Spring MVC的3.1例外:一个错误/ BindingResult参数预期模型属性参数后,立即

2019-09-17 01:08发布

我升级到春天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参数模型属性后声明。

在同一类中的以下方法声明:

@ModelAttribute("otherJobSpecs")
public List<JobReference> modelOtherJobSpecs(@PathVariable("runEnvironmentName") RunEnvironment pEnvironment, @ModelAttribute("command") JobSpecNewCommand pCommand) 
{
...
}

当我从类中删除的方法,一切正常。

有任何想法吗?

Answer 1:

这是一个在春天有个错误,我报告说,它: SPR-9378 。



Answer 2:

读春错误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) {
   ...
}

它为我工作。



文章来源: Spring MVC 3.1 exception : An Errors/BindingResult argument is expected to be immediately after the model attribute argument