当我发送我的表单Spring MVC时出现异常

时间:2013-05-24 10:42:34

标签: spring model-view-controller controller

我想将记录插入数据库,这是我的控制器:

@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!

错在哪里?

1 个答案:

答案 0 :(得分: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以获取更多信息。