我想在这个文件档案化管理解决方案后,在本周末,但它并不适用于BindingResult工作。
下面的代码有效,但并不完美。
@modelattribute("command")
public PlaceOrderCommand command() {
return new PlaceOrderCommand();
}
@RequestMapping(value = "/placeOrder", method = RequestMethod.GET)
public String placeOrder(
@modelattribute("command") PlaceOrderCommand command,
ModelMap modelMap) {
modelMap.put(BindingResult.MODEL_KEY_PREFIX + "command",
modelMap.get("errors"));
return "placeOrder";
}
@RequestMapping(value = "/placeOrder", method = RequestMethod.POST)
public String placeOrder(
@Valid @modelattribute("command") PlaceOrderCommand command,
final BindingResult bindingResult, Model model,
final RedirectAttributes redirectAttributes) {
if (bindingResult.hasErrors()) {
redirectAttributes.addFlashAttribute("errors", bindingResult);
//it doesn't work when passing this
//redirectAttributes.addFlashAttribute(BindingResult.MODEL_KEY_PREFIX + "command", bindingResult);
redirectAttributes.addFlashAttribute("command", command);
return "redirect:/booking/placeOrder";
}
......
}