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中:

[html] view plaincopy
  1. 标签库:
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
  4. <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
  5. <%@taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
  6. 实现分页用的几个变量:
  7. <%
  8. int currentPage = Integer.parseInt((String)request.getAttribute("page"));
  9. int pageSize=25;
  10. int resultCount = Integer.parseInt((String)request.getAttribute("resultCount"));
  11. int pageCount=((resultCount - 1)/pageSize) + 1;
  12. currentPage=Math.min(currentPage, pageCount);
  13. int offset=(currentPage -1) * pageSize;
  14. int totalpage = (resultCount % pageSize  == 0) ? resultCount / pageSize
  15. : (resultCount / pageSize) + 1;
  16. %>
  17. 分页标记開始(为了显示清晰。放在div里面):
  18. <div>
  19. <!-- 分页标记開始 -->
  20. <ul style="float:right">
  21. <pg:pager
  22. items="<%= resultCount %>"
  23. offset="<%= offset %>"
  24. index="center"
  25. maxPageItems="<%=pageSize%>"
  26. maxIndexPages="10"
  27. isOffset="false"
  28. export="currentPageNumber=pageNumber"
  29. scope="request">
  30. <pg:index export="totalItems=itemCount">
  31. <% if(((Integer)currentPageNumber).intValue() != 1) { %>
  32. <pg:first>
  33. <li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html">首页</a></li>
  34. </pg:first>
  35. <%}%>
  36. <pg:prev>
  37. <li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html">上一页</a></li>
  38. </pg:prev>
  39. <pg:pages>
  40. <% if(pageNumber == currentPageNumber) { %>
  41. <li class="ifpon"><span><%= pageNumber %></span></li>
  42. <% } else { %>
  43. <li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html"><%= pageNumber %></a></li>
  44. <% } %>
  45. </pg:pages>
  46. <pg:next>
  47. <li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html">下一页</a></li>
  48. </pg:next>
  49. <% if(((Integer)currentPageNumber).intValue() != totalpage) { %>
  50. <pg:last>
  51. <li><a href="/PageProject/directcity/alllist/tj/<%= pageNumber %>.html">尾页</a></li>
  52. </pg:last>
  53. <%}%>
  54. <pg:page export="firstItem, lastItem"></pg:page>
  55. </pg:index>
  56. </pg:pager>
  57. </ul>
  58. <!-- 分页标记结束 -->
  59. </div>

SQL语句:

[sql] view plaincopy
  1. 例1 :select * from (
  2. select top pageSize * from (
  3. select top offset + pageSize  *
  4. from ( select * from 表1 union all  select * from 表2 union all  select * from 表3)   ) result
  5. where 条件
  6. order by 排序字段 desc )a  order by 排序字段 asc )b order by 排序字段 desc
  7. 例2:  select   top  pageSize   *   from   表   where   主键   not   in(select   top   (currentPage-1)*pageSize      news_id   from   表)

最后插张调试结果的图片:

pager-taglib.tld文件内容:

[plain] view plaincopy
  1. <?

    xml version="1.0" encoding="ISO-8859-1" ?

    >

  2. <!DOCTYPE taglib
  3. PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
  4. "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
  5. <taglib>
  6. <tlibversion>1.0</tlibversion>
  7. <jspversion>1.1</jspversion>
  8. <shortname>pg</shortname>
  9. <uri>http://jsptags.com/tags/navigation/pager</uri>
  10. <info>
  11. The Pager Tag Library is the easy and flexible way to implement paging of
  12. large data sets in JavaServer Pages (JSP). It can emulate all currently
  13. known paging styles with minimal effort. It also includes re-usable index
  14. styles that emulate the search result navigators of popular web sites
  15. such as Google[sm], AltaVista® and Yahoo!. The Pager Tag Library does most
  16. of the work for you by dynamically organizing your data set into pages and
  17. generating a browsable index with virtually any look desired.
  18. </info>
  19. <tag>
  20. <name>pager</name>
  21. <tagclass>com.jsptags.navigation.pager.PagerTag</tagclass>
  22. <teiclass>com.jsptags.navigation.pager.PagerTagExtraInfo</teiclass>
  23. <bodycontent>JSP</bodycontent>
  24. <attribute>
  25. <name>id</name>
  26. <required>false</required>
  27. <rtexprvalue>true</rtexprvalue>
  28. </attribute>
  29. <attribute>
  30. <name>url</name>
  31. <required>false</required>
  32. <rtexprvalue>true</rtexprvalue>
  33. </attribute>
  34. <attribute>
  35. <name>items</name>
  36. <required>false</required>
  37. <rtexprvalue>true</rtexprvalue>
  38. </attribute>
  39. <attribute>
  40. <name>offset</name>
  41. <required>false</required>
  42. <rtexprvalue>true</rtexprvalue>
  43. </attribute>
  44. <attribute>
  45. <name>maxItems</name>
  46. <required>false</required>
  47. <rtexprvalue>true</rtexprvalue>
  48. </attribute>
  49. <attribute>
  50. <name>maxPageItems</name>
  51. <required>false</required>
  52. <rtexprvalue>true</rtexprvalue>
  53. </attribute>
  54. <attribute>
  55. <name>maxIndexPages</name>
  56. <required>false</required>
  57. <rtexprvalue>true</rtexprvalue>
  58. </attribute>
  59. <attribute>
  60. <name>isOffset</name>
  61. <required>false</required>
  62. <rtexprvalue>true</rtexprvalue>
  63. </attribute>
  64. <attribute>
  65. <name>index</name>
  66. <required>false</required>
  67. <rtexprvalue>true</rtexprvalue>
  68. </attribute>
  69. <attribute>
  70. <name>export</name>
  71. <required>false</required>
  72. <rtexprvalue>true</rtexprvalue>
  73. </attribute>
  74. <attribute>
  75. <name>scope</name>
  76. <required>false</required>
  77. <rtexprvalue>true</rtexprvalue>
  78. </attribute>
  79. </tag>
  80. <tag>
  81. <name>param</name>
  82. <tagclass>com.jsptags.navigation.pager.ParamTag</tagclass>
  83. <bodycontent>empty</bodycontent>
  84. <attribute>
  85. <name>id</name>
  86. <required>false</required>
  87. <rtexprvalue>true</rtexprvalue>
  88. </attribute>
  89. <attribute>
  90. <name>name</name>
  91. <required>true</required>
  92. <rtexprvalue>true</rtexprvalue>
  93. </attribute>
  94. <attribute>
  95. <name>value</name>
  96. <required>false</required>
  97. <rtexprvalue>true</rtexprvalue>
  98. </attribute>
  99. </tag>
  100. <tag>
  101. <name>item</name>
  102. <tagclass>com.jsptags.navigation.pager.ItemTag</tagclass>
  103. <bodycontent>JSP</bodycontent>
  104. <attribute>
  105. <name>id</name>
  106. <required>false</required>
  107. <rtexprvalue>true</rtexprvalue>
  108. </attribute>
  109. </tag>
  110. <tag>
  111. <name>index</name>
  112. <tagclass>com.jsptags.navigation.pager.IndexTag</tagclass>
  113. <teiclass>com.jsptags.navigation.pager.IndexTagExtraInfo</teiclass>
  114. <bodycontent>JSP</bodycontent>
  115. <attribute>
  116. <name>id</name>
  117. <required>false</required>
  118. <rtexprvalue>true</rtexprvalue>
  119. </attribute>
  120. <attribute>
  121. <name>export</name>
  122. <required>false</required>
  123. <rtexprvalue>false</rtexprvalue>
  124. </attribute>
  125. </tag>
  126. <tag>
  127. <name>first</name>
  128. <tagclass>com.jsptags.navigation.pager.FirstTag</tagclass>
  129. <teiclass>com.jsptags.navigation.pager.JumpTagExtraInfo</teiclass>
  130. <bodycontent>JSP</bodycontent>
  131. <attribute>
  132. <name>id</name>
  133. <required>false</required>
  134. <rtexprvalue>true</rtexprvalue>
  135. </attribute>
  136. <attribute>
  137. <name>export</name>
  138. <required>false</required>
  139. <rtexprvalue>false</rtexprvalue>
  140. </attribute>
  141. <attribute>
  142. <name>unless</name>
  143. <required>false</required>
  144. <rtexprvalue>true</rtexprvalue>
  145. </attribute>
  146. </tag>
  147. <tag>
  148. <name>prev</name>
  149. <tagclass>com.jsptags.navigation.pager.PrevTag</tagclass>
  150. <teiclass>com.jsptags.navigation.pager.PageTagExtraInfo</teiclass>
  151. <bodycontent>JSP</bodycontent>
  152. <attribute>
  153. <name>id</name>
  154. <required>false</required>
  155. <rtexprvalue>true</rtexprvalue>
  156. </attribute>
  157. <attribute>
  158. <name>export</name>
  159. <required>false</required>
  160. <rtexprvalue>false</rtexprvalue>
  161. </attribute>
  162. <attribute>
  163. <name>ifnull</name>
  164. <required>false</required>
  165. <rtexprvalue>true</rtexprvalue>
  166. </attribute>
  167. </tag>
  168. <tag>
  169. <name>page</name>
  170. <tagclass>com.jsptags.navigation.pager.PageTag</tagclass>
  171. <teiclass>com.jsptags.navigation.pager.JumpTagExtraInfo</teiclass>
  172. <bodycontent>JSP</bodycontent>
  173. <attribute>
  174. <name>id</name>
  175. <required>false</required>
  176. <rtexprvalue>true</rtexprvalue>
  177. </attribute>
  178. <attribute>
  179. <name>export</name>
  180. <required>false</required>
  181. <rtexprvalue>false</rtexprvalue>
  182. </attribute>
  183. </tag>
  184. <tag>
  185. <name>pages</name>
  186. <tagclass>com.jsptags.navigation.pager.PagesTag</tagclass>
  187. <teiclass>com.jsptags.navigation.pager.PageTagExtraInfo</teiclass>
  188. <bodycontent>JSP</bodycontent>
  189. <attribute>
  190. <name>id</name>
  191. <required>false</required>
  192. <rtexprvalue>true</rtexprvalue>
  193. </attribute>
  194. <attribute>
  195. <name>export</name>
  196. <required>false</required>
  197. <rtexprvalue>false</rtexprvalue>
  198. </attribute>
  199. </tag>
  200. <tag>
  201. <name>next</name>
  202. <tagclass>com.jsptags.navigation.pager.NextTag</tagclass>
  203. <teiclass>com.jsptags.navigation.pager.PageTagExtraInfo</teiclass>
  204. <bodycontent>JSP</bodycontent>
  205. <attribute>
  206. <name>id</name>
  207. <required>false</required>
  208. <rtexprvalue>true</rtexprvalue>
  209. </attribute>
  210. <attribute>
  211. <name>export</name>
  212. <required>false</required>
  213. <rtexprvalue>false</rtexprvalue>
  214. </attribute>
  215. <attribute>
  216. <name>ifnull</name>
  217. <required>false</required>
  218. <rtexprvalue>true</rtexprvalue>
  219. </attribute>
  220. </tag>
  221. <tag>
  222. <name>last</name>
  223. <tagclass>com.jsptags.navigation.pager.LastTag</tagclass>
  224. <teiclass>com.jsptags.navigation.pager.JumpTagExtraInfo</teiclass>
  225. <bodycontent>JSP</bodycontent>
  226. <attribute>
  227. <name>id</name>
  228. <required>false</required>
  229. <rtexprvalue>true</rtexprvalue>
  230. </attribute>
  231. <attribute>
  232. <name>export</name>
  233. <required>false</required>
  234. <rtexprvalue>false</rtexprvalue>
  235. </attribute>
  236. <attribute>
  237. <name>unless</name>
  238. <required>false</required>
  239. <rtexprvalue>true</rtexprvalue>
  240. </attribute>
  241. </tag>
  242. <tag>
  243. <name>skip</name>
  244. <tagclass>com.jsptags.navigation.pager.SkipTag</tagclass>
  245. <teiclass>com.jsptags.navigation.pager.PageTagExtraInfo</teiclass>
  246. <bodycontent>JSP</bodycontent>
  247. <attribute>
  248. <name>id</name>
  249. <required>false</required>
  250. <rtexprvalue>true</rtexprvalue>
  251. </attribute>
  252. <attribute>
  253. <name>export</name>
  254. <required>false</required>
  255. <rtexprvalue>false</rtexprvalue>
  256. </attribute>
  257. <attribute>
  258. <name>ifnull</name>
  259. <required>false</required>
  260. <rtexprvalue>true</rtexprvalue>
  261. </attribute>
  262. <attribute>
  263. <name>pages</name>
  264. <required>true</required>
  265. <rtexprvalue>true</rtexprvalue>
  266. </attribute>
  267. </tag>
  268. </taglib>

转载于:https://www.cnblogs.com/lxjshuju/p/7152287.html

Spring3+ibatis (SQL Server)+pager-taglib.tld查询分页的实现相关推荐

  1. 拨开云雾见日月:SQL Server 调优之查询存储

    拨开云雾见日月:SQL Server 调优之查询存储 数据库调优一直都是大家觉得比较困难的事情,SQL Server提供了很多方便的工具帮助大家进行性能分析,这边介绍下SQL Server的性能调优的 ...

  2. sql server的跨库查询(简单实现)

    sql server怎么跨库查询? 因为程序里建立连接时已经有了服务器和数据库,   库        connGZ.Provider="SQLOLEDB.1"           ...

  3. sql server跨服务器修改数据,SQL Server跨数据库服务器查询和跨表更新的详细操作...

    SQL Server数据库跨数据库服务器查询和跨表更新的相关知识是本文我们主要要介绍的内容,接下来我们就通过一个实例来介绍这一过程.实例是这样的:想实现的功能很简单, 在我的本地一个表用来保存省的信息 ...

  4. Sql Server 2005跨数据查询

    在进行Sql Server 2005跨数据库查询时,有时会出现排序规则不一致,且选出来的内容是乱码的问题. 临时解决方法,将一个库中的表中的数据导入到另一个库中,将跨数据库查询变成同数据库查询. 转载 ...

  5. SQL server 第十章------模糊查询和聚合函数上机实践

    SQL server 第十章------模糊查询和聚合函数 上机练习1 –查询住址在"山东"的学生姓名.电话.住址. create table student( Name nvar ...

  6. SQL Server中T-SQL语句查询使用的函数

    SQL Server中T-SQL语句查询使用的函数 一,字符串函数 字符串函数用于对字符串数据进行处理,并返回一个字符串或数字. 函数名 描述 举例 CHARINDEX 用来寻找一个指定的字符串在另一 ...

  7. delphi使用MS Sql Server数据库的分布式查询

    目录 delphi使用MS Sql Server数据库的分布式查询 一.链接服务器 1.1.简单的链接服务器 1.2.含多数据库架构的全链接服务器 1.3.链接服务器的理论与总结 语法: 参数: 本系 ...

  8. SQL Server 2005中的Row_Number分页

    早就听说了SQL Server 2005中的Row_Number分页了,但是一直就没认真理解这个Row_Number的含义.这两天实在是太忙了,但是还是坚持将这个弄明白了.在说分页之前还是来了解一下R ...

  9. Sql Server 2005 ROW_NUMBER 函数实现分页

    过去用SQL Server 2000分页的,大多都用到了临时表.SQL Server 2005 ROW_NUMBER 函数支持分页,性能据说也非常不错. Paging Records Using SQ ...

最新文章

  1. matplotlib色彩填充之fill、fill_between
  2. 最新版动手学习深度学习和GAN电子书免费下载!
  3. 斯坦福大学CS229数学基础(线性代数、概率论)中文翻译版.pdf
  4. centos dovecot mysql_Centos6.4 配置postfix+dovecot+mysql
  5. solidworks的小金球插件_SOLIDWORKS旋转流体仿真
  6. quartz java 线程 不释放_java Quartz 内存泄漏
  7. python扫描端口脚本_python写的端口扫描脚本
  8. react学习(61)--js contact
  9. Unity5和WebGL移植指南的一些总结
  10. 【AI面试题】分类问题常用的性能度量指标(评价指标)
  11. Oracle脚本(三)
  12. python人脸照片分类_Python系列之三——人脸检测、人脸识别
  13. 工厂模式UML类图(Pizza为例)
  14. 天思经理人ERP日化行业应用方案
  15. 《韩立刚计算机网络》第二章
  16. .html页面缓存问题
  17. linux开机启动grub rescue,开机出现 grub rescue的解决方法探索
  18. Java常量池[乐乐独记]
  19. anaconda安装包
  20. paperswithcode使用方法

热门文章

  1. 先读懂CapsNet架构然后用TensorFlow实现,这应该是最详细的教程了
  2. android permission权限与安全机制解析(上)
  3. Android实现点击通知栏后,先启动应用再打开目标Activity
  4. java同名类_java两个不同名类 在里面建立两个同名的类 怎么破
  5. 互斥锁 QMutex Class 的翻译
  6. 网页按钮跳转位置_RPA工具BizRobo!之运用网页数据处理
  7. python程序设计丁亚涛课后答案_python程序设计丁亚涛版课后答案
  8. python增量爬虫_python爬虫Scrapy框架之增量式爬虫
  9. 论文参考文献的组织(latex)
  10. 【学习笔记】Dilworth 定理的构造性证明