JSTL实现分页

xiaoxiao2026-05-09  13

最多显示左右三页间隔,首页和末页必显示1页 当前任意页  12页 当前任意页  1 23页 当前任意页  1 2 34页 当前任意页  1 2 3 45页 当前任意页  1 2 3 4 56页 当前第1页  1 2 3 4 ... 6当前第2-5页 1 2 3 4 5 6当前第6页  1 ... 3 4 5 67页 当前第1页  1 2 3 4 ... 7当前第2页  1 2 3 4 5 ... 7当前第3-5页 1 2 3 4 5 6 7当前第6页  1 ...  3 4 5 6 7当前第7页  1 ... 4 5 6 78页当前第1页  1 2 3 4 ... 8当前第2页  1 2 3 4 5 ... 8当前第3页  1 2 3 4 5 6 ... 8当前第4-5页 1 2 3 4 5 6 7 8当前第6页  1 ... 3 4 5 6 7 8当前第7页  1 ... 4 5 6 7 8当前第8页  1 ... 5 6 7 89页当前第1页  1 2 3 4 ... 9当前第2页  1 2 3 4 5 ... 9当前第3页  1 2 3 4 5 6 ... 9当前第4页  1 2 3 4 5 6 7 ... 9当前第5页  1 2 3 4 5 6 7 8 9当前第6页  1 ... 3 4 5 6 7 8 9当前第7页  1 ... 4 5 6 7 8 9当前第8页  1 ... 5 6 7 8 9当前第9页  1 ... 6 7 8 910页

当前第1页  1 2 3 4 ... 10当前第2页  1 2 3 4 5 ... 10当前第3页  1 2 3 4 5 6 ... 10当前第4页  1 2 3 4 5 6 7 ... 10当前第5页  1 2 3 4 5 6 7 8 ... 10当前第6页  1 ... 3 4 5 6 7 8 9 10当前第7页  1 ... 4 5 6 7 8 9 10当前第8页  1 ... 5 6 7 8 9 10当前第9页  1 ... 6 7 8 9 10当前第10页 1 ... 7 8 9 1011页当前第1页  1 2 3 4 ... 11当前第2页  1 2 3 4 5 ... 11当前第3页  1 2 3 4 5 6 ... 11当前第4页  1 2 3 4 5 6 7 ... 11当前第5页  1 2 3 4 5 6 7 8 ... 11当前第6页  1 ... 3 4 5 6 7 8 9 ... 11当前第7页  1 ... 4 5 6 7 8 9 10 11当前第8页  1 ... 5 6 7 8 9 10 11当前第9页  1 ... 6 7 8 9 10 11当前第10页 1 ... 7 8 9 10 11当前第11页 1 ... 8 9 10 1112页当前第1页  1 2 3 4 ... 12当前第2页  1 2 3 4 5 ... 12当前第3页  1 2 3 4 5 6 ... 12当前第4页  1 2 3 4 5 6 7 ... 12当前第5页  1 2 3 4 5 6 7 8 ... 12当前第6页  1 ... 3 4 5 6 7 8 9 ... 12当前第7页  1 ... 4 5 6 7 8 9 10 ... 12当前第8页  1 ... 5 6 7 8 9 10 11 12当前第9页  1 ... 6 7 8 9 10 11 12当前第10页 1 ... 7 8 9 10 11 12当前第11页 1 ... 8 9 10 11 12当前第12页 1 ... 9 10 11 12

 

实现方案:总页数pageAmount当前页码currentPage页数左间隔/右间隔interval(1)第一页和最后一页肯定显示n=pageAmount,当n=1时只显示1页(2)中间页码显示如果currentPage<=5,从2显示至currentPage如果currentPage>5,显示省略号,然后从currentPage-3显示至currentPage如果currentPage<=pageAmount-4或者pageAmount-4<=0,从currentPage+1显示至pageAmount如果currentPage>pageAmount-4,从currentPage+1显示至currentPage+3,然后显示省略号和pageAmount

 

每页显示&nbsp;${sessionScope.count}&nbsp;条记录&nbsp; 总记录数/总页数&nbsp;${sessionScope.recordAmount}/${sessionScope.pageAmount} &nbsp;当前第&nbsp; <a href="ViewServlet?currentPage=1">[1]</a>&nbsp; <c:if test="${sessionScope.pageAmount!=1}"> <c:choose> <c:when test="${requestScope.currentPage<=5}"> <c:forEach var="i" begin="2" end="${requestScope.currentPage}"> <a href="ViewServlet?currentPage=${i}">[${i }]</a>&nbsp; </c:forEach> </c:when> <c:otherwise> ...&nbsp; <c:forEach var="i" begin="${requestScope.currentPage-3}" end="${requestScope.currentPage}"> <a href="ViewServlet?currentPage=${i}">[${i }]</a>&nbsp; </c:forEach> </c:otherwise> </c:choose> <c:choose> <c:when test="${requestScope.currentPage>=sessionScope.pageAmount-4 || sessionScope.pageAmount-4<=0}"> <c:forEach var="i" begin="${requestScope.currentPage+1}" end="${sessionScope.pageAmount}"> <a href="ViewServlet?currentPage=${i}">[${i }]</a>&nbsp; </c:forEach> </c:when> <c:otherwise> <c:forEach var="i" begin="${requestScope.currentPage+1}" end="${requestScope.currentPage+3}"> <a href="ViewServlet?currentPage=${i}">[${i }]</a>&nbsp; </c:forEach> ...&nbsp; <a href="ViewServlet?currentPage=${sessionScope.pageAmount}"> [${sessionScope.pageAmount}]</a>&nbsp; </c:otherwise> </c:choose> </c:if> 页

  

 

转载请注明原文地址: https://www.6miu.com/read-5048458.html

最新回复(0)