在百里香中执行迭代时添加序列号

Dee*_*ass 2 html java spring web thymeleaf

我有一个问题,我必须在列表上执行迭代并将结果显示为网格。还包括序列号。现在我对序列号所做的操作如下

<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>
Run Code Online (Sandbox Code Playgroud)

但序列号中只有1个。有人可以帮助我吗?

Tom*_*lst 5

您可以使用迭代状态的索引:

<tr th:each="item,iterator : ${items}">
    <td th:text="${iterator.index}"></td>
</tr>
Run Code Online (Sandbox Code Playgroud)