在spring mvc中,如果使用到@InitBinder标签,那么过滤掉的属性需要在方法中添加上去,否则会报400错误。
代码如下:
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.setDisallowedFields("positionList");
binder.setDisallowedFields("rolesList");
}
@RequestMapping(value = "updateRoles", method = RequestMethod.POST)
public String updateRoles(@RequestParam(value = "positionList") List<String> checkedPositionList, @RequestParam(value = "rolesList") List<String> checkedRoleList, RedirectAttributes redirectAttributes){
return "redirect:/account/userList";
}
但是如果这个时候加上
@ModelAttribute("user") User user
还是会报400错误,这个原因需要进一步去研究。