如下图对于这种分页,对于刚刚学习javaWeb的同学来说或许是很神秘的,网上对于此分页没有过多的代码显示,至此今天我来将其解决掉:
对于分页关键是要两个字段:第一:每页有几条数据pageSize 第二:数据库中对应要查询数据的总条数totalNumbers,那么为什么需要这两个字段???
对于分页,首先要知道分几页,如何确定,很简单:totalPage = totalNumbers%pageSize==0?totalNumbers/pageSize:totalNumbers/pageSize+1;
对于oracle数据库的分页与mysql数据库的分页是不同的;这不是我要讲的目的,关键理解分页的几个字段就ok了!
<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>