Java 在thymeleaf中执行迭代时添加序列号
我有一个senario,其中我必须在列表上执行迭代,并将结果显示为网格。还包括序列号。下面给出了我对序列号所做的操作Java 在thymeleaf中执行迭代时添加序列号,java,html,spring,web,thymeleaf,Java,Html,Spring,Web,Thymeleaf,我有一个senario,其中我必须在列表上执行迭代,并将结果显示为网格。还包括序列号。下面给出了我对序列号所做的操作 <div th:with="i=0"> <tr th:each="mydate:${data.Listdata}" > <div th:with="i=${i+1}"> <td th:text="${i}"> </div> //other codes </tr> </div&g
<div th:with="i=0">
<tr th:each="mydate:${data.Listdata}" >
<div th:with="i=${i+1}">
<td th:text="${i}">
</div>
//other codes
</tr>
</div>
//其他代码
但是所有序列号中只有1。有人能帮我吗?您可以使用迭代状态的索引:
<tr th:each="item,iterator : ${items}">
<td th:text="${iterator.index}"></td>
</tr>
您可以使用iterationStatus以1而不是0开头
<tr th:each="item,iterationStatus : ${items}">
<td th:text=${iterationStatus.count}></td>
</tr>
这使得表Sno。从1开始