【发布时间】:2020-12-11 00:48:15
【问题描述】:
我尝试建立简单的论坛,但我在前端遇到了分页问题。 我建立的页面有我所有的主题,例如有 50 个,所以为每个页面选择 10 个主题,所以应该得到 5 个页面,主题是 150,应该有 15 个页面。我无法解决如何隐藏显示在列表下方的这 1、2、3、4 到 15 页。我只想显示数字 1、当前页和最后一个数字页(15)。下面这段代码适用于几页,但如果你有数百页或更多,那么这段代码将显示数百页。
<div th:if = "${totalPages > 1}">
<div class = "row col-sm-10">
<div class = "col-sm-2">
Total topics: [[${totalElements}]]
</div>
<div class = "col-sm-1">
<span th:each="i: ${#numbers.sequence(1, totalPages)}">
<a th:if="${currentPage != i}" th:href="@{'/topic/page/' + ${i}}">[[${i}]]</a>
<span th:unless="${currentPage != i}">[[${i}]]</span>
</span>
</div>
<div class = "col-sm-1">
<a th:if="${currentPage < totalPages}" th:href="@{'/topic/page/' + ${currentPage + 1}}">Next</a>
<span th:unless="${currentPage < totalPages}">Next</span>
</div>
<div class = "col-sm-1">
<a th:if="${currentPage > 1}" th:href="@{'/topic/page/' + ${currentPage - 1}}">Previous</a>
</div>
<div class="col-sm-1">
<a th:if="${currentPage < totalPages}" th:href="@{'/topic/page/' + ${totalPages}}">Last</a>
<span th:unless="${currentPage < totalPages}">Last</span>
</div>
</div>
</div>
有人可以帮我解决这个问题吗?我在前端很弱,不太了解如何解决它;s
【问题讨论】: