Spring Boot Thymeleaf 循环遍历

Spring Boot Thymeleaf About 452 words

th: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,取数字110

<th:block th:each="index: ${#numbers.sequence(1, count)}">
    <div th:text="${index}"></div>
</th:block>
Views: 491 · Posted: 2023-08-18

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh