Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringBoot:如何在SpringLeaf中绑定POST上的对象列表_Java_Spring Mvc_Spring Boot_Thymeleaf - Fatal编程技术网

Java SpringBoot:如何在SpringLeaf中绑定POST上的对象列表

Java SpringBoot:如何在SpringLeaf中绑定POST上的对象列表,java,spring-mvc,spring-boot,thymeleaf,Java,Spring Mvc,Spring Boot,Thymeleaf,我有一个关于GET请求的记录列表,该列表显示在UI上,带有一个复选框。 这是我的记录POJO: 课堂记录{ 选择私有布尔值; 私有整数id; 私有字符串名称; 私人电话; //.... 我在UI中显示如下: 我很难从UI获取POST上所选记录的列表。我只从POST获取了一个对象 我希望在POSTmapping中有类似的内容: @PostMapping(“/list”) 公共字符串选择(@modeldattribute ArrayList记录){ //…至少包含选定记录的ID //…或使

我有一个关于
GET
请求的记录列表,该列表显示在UI上,带有一个复选框。

这是我的
记录
POJO

课堂记录{
选择私有布尔值;
私有整数id;
私有字符串名称;
私人电话;
//....
我在UI中显示如下:


我很难从
UI
获取
POST
上所选记录的
列表
。我只从
POST
获取了一个对象

我希望在
POST
mapping中有类似的内容:

@PostMapping(“/list”)
公共字符串选择(@modeldattribute ArrayList记录){
//…至少包含选定记录的ID
//…或使用所选的

请提供帮助。

您的问题有许多潜在的原因。下面列出的三项将帮助您正确映射表单:

  • 您应该正确构建表单,包括使用
    *
    符号来减少重复,例如:

    <th:block th:each = "record : ${records}">
      <tr>
        <td><input type="checkbox" th:field="*{selected}"/></td>
        <td><input type="text" th:field="*{id}"/></td>
        <td><input type="text" th:field="*{name}"/></td>
        <td><input type="text" th:field="*{phone}"/></td>
      </tr>
    </th:block>
    
    
    
    如图所示

  • 当在
    ${records}
    上循环时,您可能需要使用双下划线符号,以便在表单中正确填写每个
    记录。根据:

    ..
    {…}{code>语法是一个预处理表达式,它是一个内部表达式,在实际计算整个表达式之前进行计算

    例如,见

  • 通过接受带有
    @modeldattribute
    @RequestParam
    注释的
    列表,再次检查您是否在Spring
    @Controller
    中正确处理生成的列表(看起来您已经这样做了。

    例如,见


  • 这可能是@ben3000的副本。我的限制是使用同一个对象,而不是使用包含主对象列表的包装器对象。
    <th:block th:each = "record : ${records}">
      <tr>
        <td><input type="checkbox" th:field="*{selected}"/></td>
        <td><input type="text" th:field="*{id}"/></td>
        <td><input type="text" th:field="*{name}"/></td>
        <td><input type="text" th:field="*{phone}"/></td>
      </tr>
    </th:block>