【问题标题】:add a serial number while performing iteration in thymeleaf在thymeleaf中执行迭代时添加序列号
【发布时间】:2014-04-11 14:02:40
【问题描述】:
我有一个场景,我必须在列表上执行迭代并将结果显示为网格。还包括其中的序列号。现在我为序列号所做的如下所示
<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 个出现。谁能帮我解决这个问题?
【问题讨论】:
标签:
java
html
spring
web
thymeleaf
【解决方案1】:
您可以使用 iterationStatus 以 1 而不是 0 开头。
<tr th:each="item,iterationStatus : ${items}">
<td th:text=${iterationStatus.count}></td>
</tr>
这给出了表 Sno。从 1 开始。
【解决方案2】:
可以使用迭代状态的索引:
<tr th:each="item,iterator : ${items}">
<td th:text="${iterator.index}"></td>
</tr>