<span th:each="cartInfo,stat:${checkedCartList}">
<input name="orderDetailList[0].skuId'" type="hidden" value="" />
<input name="orderDetailList[0].skuNum'" type="hidden" value="" />
<input name="orderDetailList[0].orderPrice'" type="hidden" value="" />
</span>
想要在html的循环中获取角标,引入thymeleaf 之 th:each状态变量,即stat
index:当前迭代对象的index(从0开始计算)
count: 当前迭代对象的index(从1开始计算)
size:被迭代对象的大小
current:当前迭代变量
even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)
first:布尔值,当前循环是否是第一个
last:布尔值,当前循环是否是最后一个
例如:
<th th:text="${Stat.index}">状态变量:index</th>
<th th:text="${Stat.count}">状态变量:count</th>
<th th:text="${Stat.size}">状态变量:size</th>
<th th:text="${Stat.current.userName}">状态变量:current</th>
<th th:text="${Stat.even}">状态变量:even****</th>
<th th:text="${Stat.odd}">状态变量:odd</th>
<th th:text="${Stat.first}">状态变量:first</th>
<th th:text="${Stat.last}">状态变量:last</th>
所以:
<span th:each="cartInfo,stat:${checkedCartList}">
<input th:name="'orderDetailList['+${stat.index}+'].skuId'" type="hidden" value="" />
<input th:name="'orderDetailList['+${stat.index}+'].skuNum'" type="hidden" value="" />
<input th:name="'orderDetailList['+${stat.index}+'].orderPrice'" type="hidden" value="" />
</span>
来源:oschina
链接:https://my.oschina.net/u/3668429/blog/4783897