Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧转换器不被称为_Java_Spring_Spring Mvc - Fatal编程技术网

Java 弹簧转换器不被称为

Java 弹簧转换器不被称为,java,spring,spring-mvc,Java,Spring,Spring Mvc,我有一个转换器,但它不叫。我总是有例外 public class IntegerToQueConverter implements Converter<Integer, QuestionType> { @Autowired private QuestionTypeService questionTypeService; @Override public QuestionType convert(Integer questionType) { return questio

我有一个转换器,但它不叫。我总是有例外

public class IntegerToQueConverter implements Converter<Integer, QuestionType> {

@Autowired
private QuestionTypeService questionTypeService;

@Override
public QuestionType convert(Integer questionType) {

    return questionTypeService.findOne(questionType);
}

转换器的类型参数更改为

public class IntegerToQueConverter implements Converter<String, QuestionType> {

    @Autowired
    private QuestionTypeService questionTypeService;

    @Override
    public QuestionType convert(String questionType) {
        return questionTypeService.findOne(questionType);
    }
}
公共类IntegerToQueConverter实现转换器{
@自动连线
私人问题类型服务问题类型服务;
@凌驾
公共问题类型转换(字符串问题类型){
返回questionTypeService.findOne(questionType);
}
}

随请求传入的值将是
String
类型,这要求转换器的类型为
converter

您是否在web应用程序中使用此类型?通常,您可以将字符串转换为特定的对象类型。@KevinBowersox:yes.iam在web应用程序中使用它
    @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;
}
public class IntegerToQueConverter implements Converter<String, QuestionType> {

    @Autowired
    private QuestionTypeService questionTypeService;

    @Override
    public QuestionType convert(String questionType) {
        return questionTypeService.findOne(questionType);
    }
}