thymeleaf 之 th:each

非 Y 不嫁゛ 提交于 2020-12-09 16:50:17
<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>

 

 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!