thymeleaf模板th:each循环
<div class="media" th:each="question:${questions}"> <div class="media-left"> <a href="#"> <img class="media-object img-rounded" th:src="${question.user.avatarUrl}"> </a> </div> <div class="media-body"> <h4 class="media-heading" th:text="${question.title}"></h4> <span th:text="${question.description}"></span><br> <span class="text-color-999"><span th:text="${question.viewCount}"></span> 次浏览 • <span th:text="${question.commentCount}"></span> 个评论 • <span th:text="${#dates.format(question.gmtCreate,'dd MMMM yyyy')}"></span></span> </div> </div>
<nav aria-label="Page navigation" style="float: right;"> <ul class="pagination"> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> <li th:each="page:${pagination.pages}" ><a th:href="@{/(page=${page})}" th:text="${page}"></a></li> <li> <a href="#" aria-label="Next"> <span aria-hidden="true">»</span> </a> </li> </ul> </nav>
【thymeleaf文档】
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html