首页 > 编程语言 > 详细

javaWeb中的分页操作

时间:2014-04-19 22:03:07      阅读:658      评论:0      收藏:0      [点我收藏+]

    如下图对于这种分页,对于刚刚学习javaWeb的同学来说或许是很神秘的,网上对于此分页没有过多的代码显示,至此今天我来将其解决掉:    

bubuko.com,布布扣

       对于分页关键是要两个字段:第一:每页有几条数据pageSize    第二:数据库中对应要查询数据的总条数totalNumbers,那么为什么需要这两个字段???

  对于分页,首先要知道分几页,如何确定,很简单:totalPage = totalNumbers%pageSize==0?totalNumbers/pageSize:totalNumbers/pageSize+1;

  对于oracle数据库的分页与mysql数据库的分页是不同的;这不是我要讲的目的,关键理解分页的几个字段就ok了!

     bubuko.com,布布扣

bubuko.com,布布扣
<div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div class="pagination pagination-centered pagination-large">
                    <ul>
                        <s:if test="totalPage<6">
                            <s:iterator var="count" begin="1" end="totalPage">
                                <li><a
                                    href="<%=basePath%>admin/userList.action?currentPage=${count}">${count}</a>
                                </li>
                            </s:iterator>
                        </s:if>
                        <s:else>
                            <s:if test="currentPage>1">
                                <li><a
                                    href="<%=basePath%>admin/userList.action?currentPage=${currentPage-1}">上一页</a></li>
                            </s:if>
                            <s:if test="currentPage-1<3">
                                <s:iterator var="count" begin="1" end="4">
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${count}">${count}</a>
                                    </li>
                                </s:iterator>
                                <li><a
                                    href="<%=basePath%>admin/userList.action?currentPage=${totalPage}">...${totalPage}</a>
                                </li>
                                <s:if test="currentPage<totalPage">
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${currentPage+1}">下一页</a>
                                    </li>
                                </s:if>
                            </s:if>
                            <s:else>
                                <s:if test="totalPage-currentPage<=3">
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=1">1...</a>
                                    </li>
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${totalPage-3}">${totalPage-3}</a>
                                    </li>
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${totalPage-2}">${totalPage-2}</a>
                                    </li>
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${totalPage-1}">${totalPage-1}</a>
                                    </li>

                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${totalPage}">${totalPage}</a>
                                    </li>
                                    <s:if test="currentPage<totalPage">
                                        <li><a
                                            href="<%=basePath%>admin/userList.action?currentPage=${currentPage+1}">下一页</a>
                                        </li>
                                    </s:if>
                                </s:if>
                                <s:else>
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=1">1...</a>
                                    </li>
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${currentPage-1}">${currentPage-2}</a>
                                    </li>
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${currentPage}">${currentPage}</a>
                                    </li>
                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${currentPage+1}">${currentPage+1}</a>
                                    </li>

                                    <li><a
                                        href="<%=basePath%>admin/userList.action?currentPage=${totalPage}">...${totalPage}</a>
                                    </li>
                                    <s:if test="currentPage<totalPage">
                                        <li><a
                                            href="<%=basePath%>admin/userList.action?currentPage=${currentPage+1}">下一页</a>
                                        </li>
                                    </s:if>
                                </s:else>
                            </s:else>
                        </s:else>
                    </ul>
                </div>
            </div>
        </div>
    </div>
bubuko.com,布布扣

javaWeb中的分页操作,布布扣,bubuko.com

javaWeb中的分页操作

原文:http://www.cnblogs.com/yu0312chao/p/3675505.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!