thymeThymeleaf循环时带上序号
使⽤Thymeleaf循环列表时,有时候需要在前端显⽰出序号,
这时可以使⽤thymeleaf 循环的状态变量。
<tr th:each="service:${services}" >
<td th:text="${serviceStat.index+1}"></td>
<td th:text="${service.name}"></td>
<td th:text="${service.address}"></td>
<td th:text="${service.description}"></td>
</tr>
serviceStat是状态变量,有 index,count,size,current,even,odd,first,last等属性,如果没有显⽰设置状态变量,thymeleaf会默 认给个“变量名+Stat"的状态变量。