需要注意的是,参数的顺序实际上对弹簧很重要。BindingResult 需要紧跟在被验证的 Form 之后。同样,[可选] Model 参数需要在 BindingResult 之后。
例如:
有效期:
@RequestMapping(value = "/entry/updateQuantity", method = RequestMethod.POST)
public String updateEntryQuantity(@Valid final UpdateQuantityForm form,
final BindingResult bindingResult,
@RequestParam("pk") final long pk,
final Model model) {
}
无效:
RequestMapping(value = "/entry/updateQuantity", method = RequestMethod.POST)
public String updateEntryQuantity(@Valid final UpdateQuantityForm form,
@RequestParam("pk") final long pk,
final BindingResult bindingResult,
final Model model) {
}