Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


Spring Boot Thymeleaf 循环遍历

Spring Boot Thymeleaf 大约 452 字

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>
阅读 104 · 发布于 2023-08-18

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

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

扫描二维码关注我
昵称:
随便看看 换一批