我有一个带有Thymeleaf循环的HTML文件,循环遍历类列表。下面是整个表:
<tr th:each="h : ${hour}">
<td><span th:text="${h.getDatetime().substring(11, 13) + ':00'}"></span></td>
<td><span th:text="${h.getTemp() + 'C'}"></span></td>
<td><span th:text="${h.getWind_spd()}"></span></td>
<td><span th:text="${h.getWeather().getDescription()}"></span></td>
</tr>
迭代列表中有23个元素。我需要它每隔4个元素进行迭代。所以我会得到一个5个元素的表,而不是23个(每4小时)。
我试过把它转换成整数,然后在thymleaf中输入if-unless,但是没有成功。
编辑:忘了说了,我的日期时间变量是字符串
1条答案
按热度按时间pxiryf3j1#
请参阅https://stackoverflow.com/a/38367572/18157,并将区块 Package 在条件div(
th:if
)中,以测试循环索引是否可被4整除。