如何检索多个选择选项?

时间:2019-01-10 08:03:29

标签: spring thymeleaf

我有一个可以具有多个角色的用户。 我使用以下代码创建了表单:

dp1[i][j] = min(dp1[i-1][j], dp1[i][j-1],dp[i-1][j-1]+1)+1 if A[i][j]=1 else 0
dp2,dp3,dp4 are similar

res[i][j] = min(dp1[i][j], dp2[i][j], dp3[i][j], dp4[i][j])
here are my code, I cannot guarantee correctness

这是它的RequestMapping:

<form action="#" th:action="@{/add}" th:object="${user}" method="post">
        <div class="form-group">
            <label for="select1">Roles</label> <select
                multiple="multiple" class="form-control"
                id="select1" th:field="*{roles}">
                <option th:each="role : ${roles}" th:field="*{roles}"
                    th:value="${role.id}" th:text="${role.role}">Part name</option>
            </select>
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
    </form>

我有班级的用户

@GetMapping(value="/add")
    public String addUserForm(Model model) {
        Set<Role> roles = new HashSet<>();
        Role admin = new Role("1","ADMIN");
        Role user = new Role("2","USER");
        roles.add(admin);
        roles.add(user);
        model.addAttribute("user", new User());
        model.addAttribute("roles", roles);
        return "form";

    }
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String saveUser(@ModelAttribute User user) {
        userService.save(user);
        return "success";
    }

我总是在角色中得到[null]并且其他表单字段都在起作用,为了简洁起见,我没有将它们包括在内。

0 个答案:

没有答案