【问题标题】:Exception when i send my form Spring MVC当我发送表单 Spring MVC 时出现异常
【发布时间】:2013-05-24 10:42:33
【问题描述】:

我想在数据库中插入一条记录,所以这是我的控制器:

@RequestMapping(value="/ajouter_activite",method = RequestMethod.POST)
    public String AddActivity(@ModelAttribute Movement movement, ModelMap model,BindingResult result){
        AddActivityValidator actvalidator = new AddActivityValidator();
        actvalidator.validate(movement, result);
        if(!result.hasErrors()){
        boolean n;
        n=actservice.addMovement(movement);
        if(n==true){model.addAttribute("success","true");}
        else {model.addAttribute("echec","true");}
        return "/FicheService";}
        else{return "/FicheService";
        }

    }

当我发送表单时,我得到了这个异常:

Etat HTTP 500 - Request processing failed; nested exception is org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public java.lang.String gestion.delegation.controller.FicheServiceController.AddActivity(gestion.delegation.domaine.Movement,org.springframework.ui.ModelMap,org.springframework.validation.BindingResult)]; nested exception is java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!

这哪里错了?

【问题讨论】:

    标签: spring model-view-controller controller


    【解决方案1】:

    试试

    public String AddActivity(@ModelAttribute Movement movement, BindingResult result, ModelMap model)
    

    方法签名。

    有关详细信息,请参阅 http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-methods 中的示例 17.1。

    【讨论】:

    • 我明白了!谢谢!我必须始终将模型属性放在首位,然后是 BindingResult,最后是模型。顺序很重要。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多