我遇到了一个非常奇怪的行为,Spring MVC 3.1.0.M2突然爆发:
@Controller
@RequestMapping("/admin/participants/{participantId}")
public class ParticipantEditController extends ParticipantControllerSupport {
@ModelAttribute("participant")
public Participant getParticipant(
@PathVariable("participantId") final long participantId) {
// ...
}
@RequestMapping(value = "/{tab}/edit", method = RequestMethod.PUT)
public ModelAndView save(
@ModelAttribute("participant") final Participant participant,
final BindingResult errors) {
// ...
}
}
当我提交表单时,我遇到以下异常:
java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!
at org.springframework.web.method.annotation.support.ErrorsMethodArgumentResolver.resolveArgument(ErrorsMethodArgumentResolver.java:60)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:65)
...
令我感到不安的是我的BindingResult
会立即跟随方法签名中的model属性。
我尝试使用和不使用@Valid
注释以及更多或更少的其他参数,但无济于事。
有谁知道我做错了什么?非常感谢任何帮助。
答案 0 :(得分:2)
我发现了这个问题。罪魁祸首是父类中使用“@ModelAttribute
计算另一个模型属性的另一种方法:
@ModelAttribute("foobar")
public String getFoobar(@ModelAttribute("participant") Participant participant) {
...
}
答案 1 :(得分:0)
我希望这不是正确的答案。尽量不要将参数声明为最终参数。 ex。
public ModelAndView save(
@ModelAttribute("participant") Participant participant,
BindingResult errors)