Spring Boot Thymeleaf 循环遍历
Spring Boot Thymeleaf About 452 wordsth:each
${posts}是从Controller中的Model对象中添加进来的,使用th:each进行遍历,post是临时变量。
<ul th:each="post : ${posts}">
<li>
<a th:text="${post.title}" th:href="|/p/${post.id}.html|"></a>
</li>
</ul>
for 循环
使用#numbers.sequence生成Integer[]数组,然后对数组进行th:each遍历。count是传入的变量。
场景:遍历1..10,取数字1到10。
<th:block th:each="index: ${#numbers.sequence(1, count)}">
<div th:text="${index}"></div>
</th:block>
Views: 1,906 · Posted: 2023-08-18
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...