Thymeleaf在循环时设置递增序号 2023-10-18 20:33 280阅读 0赞 ## 场景 ## 在使用Thymeleaf进行遍历循环时,数据前面的序号如果使用实体类的id属性,id要是不从1开始递增则不能实现计数效果。 所以需要在循环时实现一个递增的序号效果。 ![Image 1][]![20190626102532252.jpg][] 如果没有显示设置状态变量,thymeleaf会默 认给个“变量名+Stat"的状态变量。 ## 实现 ## <tr th:each="orderlist:${wmsReceiveOrderDetailsVOList}" class="text_al_r"> <td> <input type="checkbox" class="ads_Checkbox" th:text="${orderlistStat.index+1}" th:value="${orderlist.id}" name="checkedid"/> </td> <td th:text="${orderlist.salverCode}"></td> <td th:text="${orderlist.materielNumber}"></td> <td th:text="${orderlist.materielName}"></td> <td th:text="${orderlist.num}"></td> <td th:text="${orderlist.supplierBatch}"></td> <td th:text="${#dates.format(orderlist.productDate, 'yyyy-MM-dd')}"></td> <td th:text="${orderlist.statusName}"></td> </tr> 注: 使用orderlist来遍历wmsReceiveOrderDetailsVOList,所以其默认状态变量为:orderlistStat 其状态变量的属性有: index:当前迭代对象的index(从0开始计算) count: 当前迭代对象的index(从1开始计算) size:被迭代对象的大小 current:当前迭代变量 even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算) first:布尔值,当前循环是否是第一个 last:布尔值,当前循环是否是最后一个 [Image 1]: [20190626102532252.jpg]: https://img-blog.csdnimg.cn/20190626102532252.jpg
还没有评论,来说两句吧...