JSP-帮助在分页中生成固定数量的链接 [英] JSP - Help in generating fixed number of link in pagination

查看:71
本文介绍了JSP-帮助在分页中生成固定数量的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的分页效果很好,但是我无法理解如何生成固定数量的页面链接. 例如,我需要以这种方式具有5个固定链接:1-2-3-4-5> 如果单击第三页,将始终看到5个链接:< 3-4-5-6 -7>

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 - 4 - 5 > if I click on the third page I will see always 5 links: < 3 - 4 - 5 - 6 -7 >

现在,使用我的算法,我只能生成所有链接,但是我不知道如何创建我上面解释的内容. 这是我的代码(仅用于href生成):

Now with my algorithm I'm only able to generate all the links, but I have no idea how create what I have explained above. This is my code(only for href generation):

<div class="pageBoxRight">
 <c:if test="${param.pageNumber > 1}">
 <a href="javascript: previousRecords();" class="previous"><em>previous</em></a>
 </c:if>
 <c:forEach var="i" begin="1" end="${tot + 1}" step="1" varStatus ="status">
 <a href="javascript: goToPage(${i});" id="paginator${i}" class="pageNumber"><span class="pageNumberRight">${i}</span></a>
 </c:forEach>
 <c:if test="${param.pageNumber < tot}">
 <a href="javascript: nextRecords();" class="next"><em>next</em></a>
 </c:if>
</div>

有人可以帮助我吗?非常感谢.

Can someone help me? Thanks a lot.

推荐答案

变得复杂.

<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>

这篇关于JSP-帮助在分页中生成固定数量的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆