JSP - Help in generating fixed number of link in pagination

后端 未结 1 1552
感动是毒
感动是毒 2021-01-03 07:20

my pagination works good but I\'m not able to understand how generate a fixed number of links to the pages. For example, I need to have 5 fixed links in this way: 1 - 2 - 3

相关标签:
1条回答
  • 2021-01-03 08:11

    It get complicated.

    <c:set var="p" value="${param.pageNumber}" /> <%-- current page (1-based) --%>
    <c:set var="l" value="5" /> <%-- amount of page links to be displayed --%>
    <c:set var="r" value="${l / 2}" /> <%-- minimum link range ahead/behind --%>
    <c:set var="t" value="${tot}" /> <%-- total amount of pages --%>
    
    <c:set var="begin" value="${((p - r) > 0 ? ((p - r) < (t - l + 1) ? (p - r) : (t - l)) : 0) + 1}" />
    <c:set var="end" value="${(p + r) < t ? ((p + r) > l ? (p + r) : l) : t}" />
    
    <c:forEach begin="${begin}" end="${end}" var="page">
        ${page}...
    </c:forEach>
    
    0 讨论(0)
提交回复
热议问题