html 如何在已有循环的thymelaf中设置迭代步骤

oknwwptz  于 2022-12-02  发布在  其他
关注(0)|答案(1)|浏览(112)

我有一个带有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,但是没有成功。
编辑:忘了说了,我的日期时间变量是字符串

pxiryf3j

pxiryf3j1#

请参阅https://stackoverflow.com/a/38367572/18157,并将区块 Package 在条件div(th:if)中,以测试循环索引是否可被4整除。

相关问题