我正在使用 Tiles 3.0 和 Spring Validator。如何使用 .../edit/{userID} 之类的 ulr 编辑用户并出现一些验证错误,然后使用相同的 url 返回到该视图。我的问题是错误没有显示。我怎样才能做到这一点?对不起,我的英语不好!
这是我的代码:
@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
public String getEditUser(@PathVariable int id, Model model) {
User user = userService.getUserById(id);
model.addAttribute("user", user);
return "user_edit";
}
@RequestMapping(value = "/edit/{id}", method = RequestMethod.POST)
public String editUser(@PathVariable int id,
@Validated(GroupEdit.class) @ModelAttribute User user,
BindingResult result, Model model) {
if (result.hasErrors()){
return "redirect:edit/" + user.getUserId(); //how can i return here?
}
userService.updateUser(user);
return "redirect:edit/" + user.getUserId();
}