码迷,mamicode.com
首页 > 其他好文 > 详细

分页---总结

时间:2015-03-10 21:10:56      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

分页总结:

1. 分页简单版: 

  实现效果如:   首页 - 上一页 - 下一页 - 尾页

  能够按相应的链接,实现跳转到相应的页面。

  分析与梳理:

    a. 只要知道当前页(PageCode--pc) 和总页数(TotalPage--tp);

    b. 所以,首页为: <a href="CustomerServlet?method=findAll&pc=1">首页</a>

      上一页:<a href="CustomerServlet?method=findAll&pc=${pc - 1}">上一页</a>

      下一页:<a href="CustomerServlet?method=findAll&pc=${pc + 1}">下一页</a>

      尾   页:<a href="CustomerServlet?method=findAll&pc=${tp}">尾页</a>

2. 分页完善版:

  实现效果如: 首页 - 上一页 - 1 - 2 - 3 - 4 - 5 - .... - 10 - 下一页 - 尾页

  能够按相应的页码,实现跳转到相应的页面。

  分析与梳理:

    a. 要求: 最多显示10个页码;

          如果当前页码超过本次显示的10个页码的 6/10 那么就向左移动。如:当前页码为6,

              那么当用户按下一页的时候就应该把6往左移动一位,之前首位的“1”就要被它后面的“2”代替掉。

          结果也就是为: 2 - 3 - 4 - 5 - 6 - 【7】 - 8 - 9 -10 -11 。

    b. 如何确定首位的数字跟末尾的数字?什么时候数字应该被移动,什么时候保持不变?

         设置页码从 begin变量开始,到end变量结束。pc为当前页码;ps为每页显示数据的最大数量(设置为“10”大小);tp为总页数;tr为数据的总条数。

         * 首先,先判断总页数(tp) 是否大于 “10”。  //如果大于10,那么begin = 1, end = 10 ;

         * 然后,判断 begin = pc - 5 < 1 ?        //如果begin小于1那么当前页在1-5之间,所以,页码不需要移动。begin = 1,end = 10;

         * 最后,判断  end = pc + 4 > tp ?        //如果end大于tp那么当前页在倒数的四页中,所以,页码还是不需要移动。begin = tp - 9 ,end = tp ;

     代码:

<a href="<c:url value="/CustomerServlet?method=findAll&pc=1"/>">首页</a>
    <c:if test="${pb.pc > 1}">
        <a href="<c:url value="/CustomerServlet?method=findAll&pc=${pb.pc-1 }"/>">上一页</a>
    </c:if>
    <c:choose>
        <c:when test="${pb.tp<=10}">
            <c:set var="begin" value="1"/>
            <c:set var="end" value="${pb.tp}"/>
        </c:when>
        <c:otherwise>
            <c:set var="begin" value="${pb.pc-5}"></c:set>
            <c:set var="end" value="${pb.pc+4}"></c:set>
            <c:if test="${begin<=1}">
                <c:set var="begin" value="1"></c:set>
                <c:set var="end" value="10"></c:set>
            </c:if>
            <c:if test="${end>=pb.tp}">
                <c:set var="begin" value="${pb.tp-9}"> </c:set>
                <c:set var="end" value="${pb.tp}"></c:set>
            </c:if>
        </c:otherwise>
    </c:choose>
    <c:forEach begin="${begin}" end="${end}" var="i">
        <a href="<c:url value="CustomerServlet?method=findAll&pc=${i }"/>">${i }</a>
    </c:forEach>
    <c:if test="${pb.pc < pb.tp}">
        <a href="<c:url value="/CustomerServlet?method=findAll&pc=${pb.pc+1 }"/>">下一页</a>
    </c:if>
    <a href="<c:url value="/CustomerServlet?method=findAll&pc=${pb.tp }"/>">尾页</a>

 

3. 最终版分页:

    (还未写)

    

 

分页---总结

标签:

原文地址:http://www.cnblogs.com/JamKong/p/4328281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!