java - 如何从对象列表中选择一个对象

标签 java spring thymeleaf

HTML

 <form th:object="${klient}" th:action="@{/osoba}" method="post">
                        <div class="form-row">
                            <div class="form-group col-md-4">
                                <label >Imię</label>
                                <input type="text" class="form-control"  th:field="*{imie}" >
                            </div>

                            <div class="form-group col-md-4">
                                <label >Nazwisko</label>
                                <input type="text" class="form-control" th:field="*{nazwisko}" >
                            </div>
                                <div class="select-list" id="selectlist">
                                    <select th:field="*{UserId}" >
                                        <option> -- </option>
                                        <option  th:each=" users : ${user}"
                                                 th:value="${users.UserId}"
                                                 th:utext="${users.lastName}"/>
                                    </select>
                                </div>

鳕鱼

    @RequestMapping (value = "/osoba", method = RequestMethod.POST)
public String dodaj (Klient klient){
    System.out.print(klient);
    return "redirect:/osoba";
}
@RequestMapping (value = "/dodaj" , method = RequestMethod.GET)
public String tworz (Model model){
    model.addAttribute("klient" , new Klient());

    List<User> lista = userService.getAllUser();
    model.addAttribute("user" , lista);

    return "dodaj";
}

我想创建一个表单,让他填写客户的字段并为其分配一个现有用户。问题是我无法获取所选的用户 ID。

我收到一条有关第一个选择的消息

Error during execution of processor 'org.thymeleaf.spring5.processor.SpringSelectFieldTagProcessor

最佳答案

错误消息显示名为 uzytkownik 的属性存在问题,但我在模板中的任何位置都没有看到该属性。当然,您没有包含完整的模板,所以我只能说问题来自其他地方......显然来自第 178 行。

关于java - 如何从对象列表中选择一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58861646/

相关文章:

java - Spring Boot Thymeleaf 下拉列表选项不显示值

java - Spring 启动 2 : Get html output in controller

java - 如何在 Thymeleaf 3.0.x 中的自定义方言的处理器中获取标签正文

javascript - 在页面刷新时使用 jQuery 重新加载 JSON 文件

java - 双向onetomany导致 "Unable to build Hibernate SessionFactory"错误

java - 控制权是否返回到将请求转发到另一个 Web 应用程序的 Web 应用程序?

java - 如何全局配置jackson with spring?

java - 测试 WebSecurityConfigurerAdapter

java - Spring MVC Controller 中的处理模型

java - 更新使用 kubernetes 部署的 3 节点 cassandra 集群中的记录时出现问题