Java 将用户分配到会议。字符串与集合类型不匹配的问题

Java 将用户分配到会议。字符串与集合类型不匹配的问题,java,html,spring,Java,Html,Spring,我有一个应用程序,其中我正在尝试将用户分配到会议。但当提交时,它作为字符串传递,我收到一个类型不匹配的错误 我的控制器方法: @GetMapping(path = "/assign/{id}") public String showStudentAssignForm(@PathVariable(name = "id") Long id, Model model){ Optional<Conference> conference = co

我有一个应用程序,其中我正在尝试将用户分配到会议。但当提交时,它作为字符串传递,我收到一个类型不匹配的错误

我的控制器方法:

@GetMapping(path = "/assign/{id}")
public String showStudentAssignForm(@PathVariable(name = "id") Long id, Model model){
    Optional<Conference> conference = conferenceService.findById(id);
    List<User> userList = userService.findAllByRoles("ROLE_STUDENT");
    model.addAttribute("userList", userList);
    model.addAttribute("conference", conference.get());
    return "assignStudent";
}

@PostMapping(path = "/assign/save")
public String saveAssignedUsers(ConferenceDto conference){
    conferenceService.updateConference(conference);
    return "redirect:/teacher/configure";
}

有什么建议可以解决这个问题吗?我应该做一个转换器(如果是的话,我如何在我的控制器中实现它?)?任何提示都将不胜感激

因此,问题似乎是字符串与集合和/或用户不匹配。我通过改变
私人收藏学生解决了这个问题
私人收藏学生在我的conferenceDto中,然后在我的ConferenceService类中保存时,我向conference(模型对象,而不是Dto)中添加使用findByName或findById从conferenceDto中的字符串中找到的用户列表

private Collection<User> students;
            <div class="form-group row">
                <label class="col-form-label col-sm-4">Users: </label>
                <div class="col-sm-8 text-left">
                    <th:block th:each="user : ${userList}">
                        <div>
                            <input type="checkbox" th:field="*{students}" th:text="${user.name}" th:value="${user}" class="m-2" />
                        </div>
                    </th:block>
                </div>
            </div>
Field error in object 'conferenceDto' on field 'students': rejected value [Bill Gates,Test McTest]; codes [typeMismatch.conferenceDto.students,typeMismatch.students,typeMismatch.java.util.Collection,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [conferenceDto.students,students]; arguments []; default message [students]]; default message [Failed to convert property value of type 'java.lang.String[]' to required type 'java.util.Collection' for property 'students'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.lukas.ramonas.cms.Model.User' for property 'students[0]': no matching editors or conversion strategy found]]