Spring3+ibatis (SQL Server)+pager-taglib.tld查询分页的实现
pager-taglib分页開始~
查了好多关于分页的技术,终于选定下面方法实现~
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中:
- 标签库:
- <%@ 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>
- </pg:index>
- </pg:pager>
- </ul>
- <!-- 分页标记结束 -->
- </div>
SQL语句:
- 例1 :select * from (
- select top pageSize * from (
- select top offset + pageSize *
- from ( select * from 表1 union all select * from 表2 union all select * from 表3) ) result
- where 条件
- order by 排序字段 desc )a order by 排序字段 asc )b order by 排序字段 desc
- 例2: select top pageSize * from 表 where 主键 not in(select top (currentPage-1)*pageSize news_id from 表)
最后插张调试结果的图片:
pager-taglib.tld文件内容:
- <?
xml version="1.0" encoding="ISO-8859-1" ?
>
- <!DOCTYPE taglib
- PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
- "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
- <taglib>
- <tlibversion>1.0</tlibversion>
- <jspversion>1.1</jspversion>
- <shortname>pg</shortname>
- <uri>http://jsptags.com/tags/navigation/pager</uri>
- <info>
- The Pager Tag Library is the easy and flexible way to implement paging of
- large data sets in JavaServer Pages (JSP). It can emulate all currently
- known paging styles with minimal effort. It also includes re-usable index
- styles that emulate the search result navigators of popular web sites
- such as Google[sm], AltaVista® and Yahoo!. The Pager Tag Library does most
- of the work for you by dynamically organizing your data set into pages and
- generating a browsable index with virtually any look desired.
- </info>
- <tag>
- <name>pager</name>
- <tagclass>com.jsptags.navigation.pager.PagerTag</tagclass>
- <teiclass>com.jsptags.navigation.pager.PagerTagExtraInfo</teiclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>url</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>items</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>offset</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>maxItems</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>maxPageItems</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>maxIndexPages</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>isOffset</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>index</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>export</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>scope</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>param</name>
- <tagclass>com.jsptags.navigation.pager.ParamTag</tagclass>
- <bodycontent>empty</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>name</name>
- <required>true</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>value</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>item</name>
- <tagclass>com.jsptags.navigation.pager.ItemTag</tagclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>index</name>
- <tagclass>com.jsptags.navigation.pager.IndexTag</tagclass>
- <teiclass>com.jsptags.navigation.pager.IndexTagExtraInfo</teiclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>export</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>first</name>
- <tagclass>com.jsptags.navigation.pager.FirstTag</tagclass>
- <teiclass>com.jsptags.navigation.pager.JumpTagExtraInfo</teiclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>export</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- </attribute>
- <attribute>
- <name>unless</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>prev</name>
- <tagclass>com.jsptags.navigation.pager.PrevTag</tagclass>
- <teiclass>com.jsptags.navigation.pager.PageTagExtraInfo</teiclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>export</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- </attribute>
- <attribute>
- <name>ifnull</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>page</name>
- <tagclass>com.jsptags.navigation.pager.PageTag</tagclass>
- <teiclass>com.jsptags.navigation.pager.JumpTagExtraInfo</teiclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>export</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>pages</name>
- <tagclass>com.jsptags.navigation.pager.PagesTag</tagclass>
- <teiclass>com.jsptags.navigation.pager.PageTagExtraInfo</teiclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>export</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>next</name>
- <tagclass>com.jsptags.navigation.pager.NextTag</tagclass>
- <teiclass>com.jsptags.navigation.pager.PageTagExtraInfo</teiclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>export</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- </attribute>
- <attribute>
- <name>ifnull</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>last</name>
- <tagclass>com.jsptags.navigation.pager.LastTag</tagclass>
- <teiclass>com.jsptags.navigation.pager.JumpTagExtraInfo</teiclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>export</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- </attribute>
- <attribute>
- <name>unless</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
- <tag>
- <name>skip</name>
- <tagclass>com.jsptags.navigation.pager.SkipTag</tagclass>
- <teiclass>com.jsptags.navigation.pager.PageTagExtraInfo</teiclass>
- <bodycontent>JSP</bodycontent>
- <attribute>
- <name>id</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>export</name>
- <required>false</required>
- <rtexprvalue>false</rtexprvalue>
- </attribute>
- <attribute>
- <name>ifnull</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>pages</name>
- <required>true</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
- </taglib>
转载于:https://www.cnblogs.com/lxjshuju/p/7152287.html
Spring3+ibatis (SQL Server)+pager-taglib.tld查询分页的实现相关推荐
- 拨开云雾见日月:SQL Server 调优之查询存储
拨开云雾见日月:SQL Server 调优之查询存储 数据库调优一直都是大家觉得比较困难的事情,SQL Server提供了很多方便的工具帮助大家进行性能分析,这边介绍下SQL Server的性能调优的 ...
- sql server的跨库查询(简单实现)
sql server怎么跨库查询? 因为程序里建立连接时已经有了服务器和数据库, 库 connGZ.Provider="SQLOLEDB.1" ...
- sql server跨服务器修改数据,SQL Server跨数据库服务器查询和跨表更新的详细操作...
SQL Server数据库跨数据库服务器查询和跨表更新的相关知识是本文我们主要要介绍的内容,接下来我们就通过一个实例来介绍这一过程.实例是这样的:想实现的功能很简单, 在我的本地一个表用来保存省的信息 ...
- Sql Server 2005跨数据查询
在进行Sql Server 2005跨数据库查询时,有时会出现排序规则不一致,且选出来的内容是乱码的问题. 临时解决方法,将一个库中的表中的数据导入到另一个库中,将跨数据库查询变成同数据库查询. 转载 ...
- SQL server 第十章------模糊查询和聚合函数上机实践
SQL server 第十章------模糊查询和聚合函数 上机练习1 –查询住址在"山东"的学生姓名.电话.住址. create table student( Name nvar ...
- SQL Server中T-SQL语句查询使用的函数
SQL Server中T-SQL语句查询使用的函数 一,字符串函数 字符串函数用于对字符串数据进行处理,并返回一个字符串或数字. 函数名 描述 举例 CHARINDEX 用来寻找一个指定的字符串在另一 ...
- delphi使用MS Sql Server数据库的分布式查询
目录 delphi使用MS Sql Server数据库的分布式查询 一.链接服务器 1.1.简单的链接服务器 1.2.含多数据库架构的全链接服务器 1.3.链接服务器的理论与总结 语法: 参数: 本系 ...
- SQL Server 2005中的Row_Number分页
早就听说了SQL Server 2005中的Row_Number分页了,但是一直就没认真理解这个Row_Number的含义.这两天实在是太忙了,但是还是坚持将这个弄明白了.在说分页之前还是来了解一下R ...
- Sql Server 2005 ROW_NUMBER 函数实现分页
过去用SQL Server 2000分页的,大多都用到了临时表.SQL Server 2005 ROW_NUMBER 函数支持分页,性能据说也非常不错. Paging Records Using SQ ...
最新文章
- matplotlib色彩填充之fill、fill_between
- 最新版动手学习深度学习和GAN电子书免费下载!
- 斯坦福大学CS229数学基础(线性代数、概率论)中文翻译版.pdf
- centos dovecot mysql_Centos6.4 配置postfix+dovecot+mysql
- solidworks的小金球插件_SOLIDWORKS旋转流体仿真
- quartz java 线程 不释放_java Quartz 内存泄漏
- python扫描端口脚本_python写的端口扫描脚本
- react学习(61)--js contact
- Unity5和WebGL移植指南的一些总结
- 【AI面试题】分类问题常用的性能度量指标(评价指标)
- Oracle脚本(三)
- python人脸照片分类_Python系列之三——人脸检测、人脸识别
- 工厂模式UML类图(Pizza为例)
- 天思经理人ERP日化行业应用方案
- 《韩立刚计算机网络》第二章
- .html页面缓存问题
- linux开机启动grub rescue,开机出现 grub rescue的解决方法探索
- Java常量池[乐乐独记]
- anaconda安装包
- paperswithcode使用方法
热门文章
- 先读懂CapsNet架构然后用TensorFlow实现,这应该是最详细的教程了
- android permission权限与安全机制解析(上)
- Android实现点击通知栏后,先启动应用再打开目标Activity
- java同名类_java两个不同名类 在里面建立两个同名的类 怎么破
- 互斥锁 QMutex Class 的翻译
- 网页按钮跳转位置_RPA工具BizRobo!之运用网页数据处理
- python程序设计丁亚涛课后答案_python程序设计丁亚涛版课后答案
- python增量爬虫_python爬虫Scrapy框架之增量式爬虫
- 论文参考文献的组织(latex)
- 【学习笔记】Dilworth 定理的构造性证明