Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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
从thymeleaf中的java控制器获取值后,如何为表生成此动态列?_Java_Html_Loops_Html Table_Thymeleaf - Fatal编程技术网

从thymeleaf中的java控制器获取值后,如何为表生成此动态列?

从thymeleaf中的java控制器获取值后,如何为表生成此动态列?,java,html,loops,html-table,thymeleaf,Java,Html,Loops,Html Table,Thymeleaf,我的表的所有值都来自控制器。在得到它们之后,我将它们显示在html表上。但是,我在生成这个动态表时遇到了一些问题。我想要的是这张桌子: 预期表格: 而信息、标题和值来自我的数据库。但这些都在循环中。我的代码在这里: <div> <table class="dataTable"> <th:block th:each="informations, iteration : ${data.listItems}">

我的表的所有值都来自控制器。在得到它们之后,我将它们显示在html表上。但是,我在生成这个动态表时遇到了一些问题。我想要的是这张桌子:

预期表格:

而信息、标题和值来自我的数据库。但这些都在循环中。我的代码在这里:

<div>
<table class="dataTable">

  <th:block th:each="informations, iteration : ${data.listItems}">

      <th>Information</th>
      <th> Info <span th:text="${iteration.index+1}"></span></th>

      <tr>
        <td>Title</td>
        <td th:text="${informations.title}"></td>
      </tr>

      <tr>
        <td>Class</td>
        <td th:text="${informations.class}"></td>
      </tr>

  </th:block>

</table>
</div>

问询处
信息
标题
等级
结果如下表所示:

输出表:


多次重复行名,我不知道;我不想要。我如何修改它,以便生成上面所示的预期的表?

我认为
<div>
<table class="dataTable">

      <th>Information</th>
      
       <th:block th:each="informations, iteration : ${data.listItems}">
       <th>Info <span th:text="${iteration.index+1}"></span></th>
       </th:block>

      <tr>
        <td>Title</td>
       <th:block th:each="informations, iteration : ${data.listItems}">
        <td th:text="${informations.title}"></td>
       </th:block>
      </tr>

      <tr>
        <td>Class</td>
       <th:block th:each="informations, iteration : ${data.listItems}">
        <td th:text="${informations.class}"></td>
       </th:block>
      </tr>

</table>
</div>

问询处
信息
标题
等级

我这样认为,但当它一次又一次地编写同一个循环时,我可能只发布了3个数据,但我几乎有10多个数据,这就是为什么我想检查是否有其他方法我知道这不是最好的决定,但即使在重读thymeleaf文档后,我也看不到beter Onep,这是唯一的方法(除非您想事先将数据转换为可以循环的内容,如列表)。