thymeleaf实现表格中序号的自增

thymeleaf实现表格中序号的自增

序号自增部分,代码如下所示:

<tr th:each="d : ${data}">                     <!-- 循环输出data数据 -->
    <td th:text="${dStat.index+1}"></td>       <!-- 每输出一行数据,序号+1 --> 
</tr>

d就是我们所获得的数据,在d后面加上Stat,即dStat,它就变成了所谓的状态变量。

这个变量有 index,count,size,current,even,odd,first,last等属性,如果没有显式地设置状态变量,thymeleaf会默认给个“变量名+Stat"的状态变量。

itemStat称作状态变量,属性有:
index:当前迭代对象的index(从0开始计算)
count: 当前迭代对象的index(从1开始计算)
size:被迭代对象的大小
current:当前迭代变量
even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)
first:布尔值,当前循环是否是第一个
last:布尔值,当前循环是否是最后一个

猜你喜欢

转载自blog.csdn.net/qq_46036214/article/details/115291643