码迷,mamicode.com
首页 > 编程语言 > 详细

页码导航算法

时间:2015-03-05 16:53:15      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

int pcount = r3d.pager.getPageCount();
int curpage = r3d.pager.getPageNow();

if (pcount > 1) {//显示超链接
    //上一页
    if (curpage != 1) {
        out.println("<a href=index.jsp?pageNow=" + (curpage - 1)
                + ">上一页</a>");
        out.println("<a href=index.jsp?pageNow=1>[1]</a>");
    } else
        out.println("&nbsp;1&nbsp;");

    int stap = curpage - 2;
    int endp = curpage + 2;
    if (endp > pcount - 1)
        stap -= (endp - pcount + 1);
    if (stap < 2) {
        endp += (2 - stap);
        stap = 2;
    }

    int i = stap;

    if (i >  2) {
        out.println("...");
    }

    while (i <= endp && i <= pcount) {
        if (i == curpage)
            out.println("&nbsp;" + i + "&nbsp;");
        else
            out.println("<a href=index.jsp?pageNow=" + i + ">[" + i
                    + "]</a>");
        i++;
    }
    if (i < pcount) {
        out.println("...");

        out.println("<a href=index.jsp?pageNow=" + pcount + ">["
            + pcount + "]</a>");
    }
    //下一页
    if (curpage < pcount) {
        out.println("<a href=index.jsp?pageNow=" + (curpage + 1)
                + ">下一页</a>");
    }
}

 

页码导航算法

标签:

原文地址:http://www.cnblogs.com/dashi/p/4316027.html

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