我升级到Spring 3.1.1.RELEASE,现在我在以下方法上遇到异常:
@RequestMapping(method = RequestMethod.POST, params = "_finish")
public ModelAndView doPostFinish(@PathVariable("runEnvironmentName") RunEnvironment pEnvironment, @ModelAttribute("command") JobSpecNewCommand pCommand, BindingResult pErrors)
{
...
}
引发以下异常:
java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be immediately after the model attribute argument in the controller method signature: java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be immediately after the model attribute argument in the controller method signature: public org.springframework.web.servlet.ModelAndView de.wwag.infra.oocsd.projectAdmin.fe.natures.hudson.jobspecs.RunEnvJobSpecNewController.doPostFinish(de.wwag.infra.oocsd.projectAdmin.common.domain.RunEnvironment,de.wwag.infra.oocsd.projectAdmin.fe.natures.hudson.jobspecs.JobSpecNewCommand,org.springframework.validation.BindingResult) at org.springframework.web.method.annotation.ErrorsMethodArgumentResolver.resolveArgument(ErrorsMethodArgumentResolver.java:62) ...
如您所见,方法签名符合预期。 BindingResult参数在model属性之后声明。
在同一个类中声明了以下方法:
@ModelAttribute("otherJobSpecs")
public List<JobReference> modelOtherJobSpecs(@PathVariable("runEnvironmentName") RunEnvironment pEnvironment, @ModelAttribute("command") JobSpecNewCommand pCommand)
{
...
}
当我从课程中删除该方法时,一切都按预期工作。
有什么想法吗?
答案 0 :(得分:1)
这是Spring的一个错误,我报告了它:SPR-9378。
答案 1 :(得分:0)
阅读Spring错误SPR-9378,您必须从@ModelAttribute方法中删除模型变量:
@ModelAttribute
public void populateModel(Model model) { //this method haven't Libro Object
model.addAttribute(Genero.values());
model.addAttribute(EstadoLibro.values());
}
@RequestMapping(method=RequestMethod.POST)
public String grabarLibro(@Validated @ModelAttribute Libro libro, BindingResult result) {
...
}
它对我有用。