【发布时间】:2017-09-17 06:41:08
【问题描述】:
我正在创建 Spring Boot 应用程序。我有 User 类,我正在与 Role 类映射(ManyToMany)。
我在User 类中有角色设置器:
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
从控制器我使用RoleRepository 类来获取所有角色的名称。
我在 html 中迭代它并创建复选框:
<form th:object="${userForm}">
<!-- userForm is coming from controller: -->
<!-- model.addAttribute("userForm", new User()); -->
<div class="checkbox" th:each="role: ${allroles.roleList}">
<input th:field="*{roles}" type="checkbox" th:value="${role}">
<input th:field="*{roles}" type="hidden" th:value="${role}">
<td th:text="${role}"></td>
</div>
</form>
我希望当我点击提交时,应该发送所选角色,但它返回null。
【问题讨论】: