0

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

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

那哪里错了?

4

1 回答 1

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。

于 2013-05-24T11:06:22.863 回答