У меня есть конвертер, но он не называется. Я всегда получаю исключение BindException.
public class IntegerToQueConverter implements Converter<Integer, QuestionType> {
@Autowired
private QuestionTypeService questionTypeService;
@Override
public QuestionType convert(Integer questionType) {
return questionTypeService.findOne(questionType);
}
Я определил следующий компонент в контексте приложения.
<annotation-driven conversion-service="conversionService">
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean" >
<property name="converters">
<list>
<bean class="org.hr.quiz.converter.IntegerToQueConverter"/>
</list>
</property>
</bean>
Пожалуйста помоги. Заранее спасибо!
Обновить:
Я хочу, чтобы конвертер был вызван в этом коде:
@RequestMapping(value="/insertQuestion", method = RequestMethod.POST)
public ModelAndView insertQuestion(@ModelAttribute("questions") Question question)
{
ModelAndView view=new ModelAndView("addQuestion");
System.out.println(question.getQuestion());
.............................
return view;
}
Измените аргументы типа Converter
на <String,QuestionType>
:
public class IntegerToQueConverter implements Converter<String, QuestionType> {
@Autowired
private QuestionTypeService questionTypeService;
@Override
public QuestionType convert(String questionType) {
return questionTypeService.findOne(questionType);
}
}
Значения, переданные с запросом, будут иметь тип String
который требует, чтобы преобразователь имел тип Converter<String,QuestionType>
.