Thymeleaf中each标签遍历list如何获取index

<tr th:each="user,userStat:${users}">
userStat是状态变量,有 index,count,size,current,even,odd,first,last等属性,如果没有显示设置状态变量,thymeleaf会默 认给个“变量名+Stat"的状态变量。

对arrayList对象users遍历,使用user作为接受参数接收,使用userStat作为users下标值,通过userStat.index得到当前所处下标值;

用处:判断下标是否未奇数,设置tr样式

   给遍历的集合加上序号

原文地址:https://www.cnblogs.com/hanxue53/p/7826792.html