我进行搜索,并从Thymeleaf获得服务器的响应。这保存了结果数:
${response.count}
我想进行这样的迭代:
for (int i = 1; i <= response.count; i++) { if (response.page == i) { <button class="active">Dummy</button> } else { <button>Dummy</button> } }
我怎样才能做到这一点?我已经尝试过类似的方法:
${#numbers.sequence(0, response.count)}
但是没有用
编辑:我已经尝试过,但是也没有用:
<button th:each="i: ${#numbers.sequence(0, response.count - 1)}" th:class="${i == response.page} ?: active">Dummy</button>
这对我有用:
<th:block th:each="i: ${#numbers.sequence(0, response.count - 1)}"> <button th:if="${response.page == i}" class="active">Dummy</button> <button th:unless="${response.page == i}">Dummy</button> </th:block>