【发布时间】:2017-04-26 09:39:45
【问题描述】:
我正在尝试获取对象控制器上的 POST 表单数据具有一对多关系。就像下面的代码
我的通知模型
private long id;
@NotBlank(message = ERROR.NOT_EMPTY)
private String title;
@NotBlank(message = ERROR.NOT_EMPTY)
private String content;
// One Notification has many User
private List<NotificationUser> listNotificationUser;;
// Getter and setter method
我的控制器
@RequestMapping(value = "notification/add", method = RequestMethod.GET)
public String create(ModelMap model) {
ArrayList<User> listUser = userService.getAllUsername();
model.put("user", listUser);
model.addAttribute("notification", new Notification());
return "notification/add";
}
@RequestMapping(value = "notification/add", method = RequestMethod.POST)
public String create(ModelMap model, HttpServletRequest request,
@Valid @ModelAttribute(value = "notification") Notification notification, BindingResult bindingResult) {
....
}
我的.jsp
<form:form method="POST" action="add" name="addForm" commandName="notification">
<!-- Other input -->
<form:select path="listNotificationUser" multiple="multiple" id="name" name="itemValue">
<form:options />
<form:options items="${user}" itemValue="id" itemLabel="name" />
</form:select>
<!-- Other input -->
</form:form>
当我向控制器提交 POST 表单时,字段 notification.listNotificationUser 始终为空(其他字段很好)。
我正在搜索并尝试一些解决方案,但它不起作用。
【问题讨论】:
标签: spring-mvc post one-to-many