当前位置:Gxlcms >
数据库问题 >
Spring3+ibatis (SQL Server)+pager-taglib.tld查询分页的实现
Spring3+ibatis (SQL Server)+pager-taglib.tld查询分页的实现
时间:2021-07-01 10:21:17
帮助过:4人阅读
查了好多关于分页的技术,终于选定下面方法实现~
1.首先下载jar包:pager-taglib.jar,pager-taglib.jar放在WEB-INF/lib文件夹下;
下载地址:http://download.csdn.net/detail/jeofey/8641287
2.将pager-taglib.tld文件放在WEB-INF文件夹下,pager-taglib.tld文件的内容见文章末尾;
3.仅仅粘贴实现分页的关键部分
jsp中:
[html] view
plaincopy
-
标签库:
-
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
-
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
-
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
-
<%@taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
-
-
实现分页用的几个变量:
-
<%
-
int currentPage = Integer.parseInt((String)request.getAttribute("page"));
-
int pageSize=25;
-
int resultCount = Integer.parseInt((String)request.getAttribute("resultCount"));
-
int pageCount=((resultCount - 1)/pageSize) + 1;
-
currentPage=Math.min(currentPage, pageCount);
-
int offset=(currentPage -1) * pageSize;
-
int totalpage = (resultCount % pageSize == 0) ? resultCount / pageSize
-
: (resultCount / pageSize) + 1;
-
%>
-
-
分页标记開始(为了显示清晰。放在div里面):
-
<div>
-
-
<ul style="float:right">
-
<pg:pager
-
items="<%= resultCount %>"
-
offset="<%= offset %>"
-
index="center"
-
maxPageItems="<%=pageSize%>"
-
maxIndexPages="10"
-
isOffset="false"
-
export="currentPageNumber=pageNumber"
-
scope="request">
-
<pg:index export="totalItems=itemCount">
-
<% if(((Integer)currentPageNumber).intValue() != 1) { %>
-
<pg:first>
-
<li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html">首页</a></li>
-
</pg:first>
-
<%}%>
-
<pg:prev>
-
<li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html">上一页</a></li>
-
</pg:prev>
-
<pg:pages>
-
<% if(pageNumber == currentPageNumber) { %>
-
<li class="ifpon"><span><%= pageNumber %></span></li>
-
<% } else { %>
-
<li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html"><%= pageNumber %></a></li>
-
<% } %>
-
</pg:pages>
-
<pg:next>
-
<li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html">下一页</a></li>
-
</pg:next>
-
<% if(((Integer)currentPageNumber).intValue() != totalpage) { %>
-
<pg:last>
-
<li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html">尾页</a></li>
-
</pg:last>
-
<%}%>
-
<pg:page export="firstItem, lastItem"></pg:page