从thymeleaf中的java控制器获取值后,如何为表生成此动态列?
我的表的所有值都来自控制器。在得到它们之后,我将它们显示在html表上。但是,我在生成这个动态表时遇到了一些问题。我想要的是这张桌子: 预期表格: 而信息、标题和值来自我的数据库。但这些都在循环中。我的代码在这里:从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}">
<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,这是唯一的方法(除非您想事先将数据转换为可以循环的内容,如列表)。