Thymeleaf List指定数量条数循环

项目使用Thymeleaf模板,页面只需要显示list里面的前3条数据,这时候应该怎么做呢,不像jsp那样,可以使用begin=“0”,end=“2” 这样,这时候可以使用 th:if="${userStat.index} lt 3 判断当前的迭代索引,从0开始。这是index属性。lt 就是 <,这样就可以获取前3 条数据了。

<tr th:each="user,userStat:${supplierVotes}" th:class="${userStat.odd}? odd" th:if="${userStat.index} lt 3" th:object="${user}">
				<td th:text="${userStat.count}">1</td>
				<a th:href="@{/user/details(customerId=${user.customerId})}" target="_blank"><td th:text="*{customerId}">1</td></a>
				<td th:text="${user.yearFlag}">1</td>
				<td th:text="|${user.yearFlag} ${user.customerId}|">1</td>
				<td><span th:if="${user.yearFlag == 2017}">特殊提供</span></td>
				<td><a th:href="@{/user/details(customerId=${user.customerId})}" target="_blank">详情</a></td>
			</tr>
经验分享 程序员 微信小程序 职场和发展