0
私はオブジェクトのコントローラ上でPOSTフォームデータを取得しようとしていますが、1対多の関係を持っています。コードJavaスプリングポストフォームと1対多の関係
マイ通知モデル
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>
以下のように私はいつも、コントローラにフィールドnotification.listNotificationUserをPOSTフォームを送信するとnullです(他のフィールドは正常です)。
私は検索して解決策を試しましたが、機能しません。
ようにする必要があり、私はちょうど問題に気づいありがとう、それが動作していないように見える、notification.listNotificationUserが空のArrayListです:( –
、ユーザーリストストアは、タイプのユーザーが、属性listNotificationUser店NotificationUserオブジェクトそのように動作しないので、同じ種類のオブジェクトを使用する必要があります – cralfaro