今天自己整理了一个分页工具(刚做还有很多没完善的地方),把它放上来。
因为个人水平有限,有不对的地方,望大家见谅。也希望大家提出你们宝贵的意见或建议。
源码siyn-pager.rar下载
下面主要介绍一下其使用方法:
1.把siyn-pager.jar放到lib下,
2.把siyn-pager.tld放到/WEB-INF/下,
3.修改web.xml文件,添加tld配置
<
jsp-config
>
< taglib >
< taglib-uri > http://www.siyn.org/siyn-pager.tld </ taglib-uri >
< taglib-location > /WEB-INF/siyn-pager.tld </ taglib-location >
</ taglib >
</ jsp-config >
4.action
< taglib >
< taglib-uri > http://www.siyn.org/siyn-pager.tld </ taglib-uri >
< taglib-location > /WEB-INF/siyn-pager.tld </ taglib-location >
</ taglib >
</ jsp-config >
4.1通过PageControlUtil.getPageControl(request)得到pageControl;
PageControl pageControl
=
PageControlUtil.getPageControl(request);
4.2如果还没有获得总记录数,通过调用service的方法获得总记录数
if
(pageControl.getRowcount()
<=
0
)
pageControl.setRowcount(service.getSize());
4.3通过调用service的方法得到结果集
pageControl.setRowcount(service.getSize());
List list
=
service.getData(pageControl);
4.4将结果集&分页控制bean(pageControl)放入request
request.setAttribute(
"
list
"
, list);
request.setAttribute(
org.siyn.common.web.struts.taglib.page.Constants.PAGE_CONTROL_MODEL,
pageControl);
4.5跳转页面
request.setAttribute(
org.siyn.common.web.struts.taglib.page.Constants.PAGE_CONTROL_MODEL,
pageControl);
return
mapping.findForward(
"
success
"
);
5.jsp页面
5.1导入标签库
<%
@ taglib uri
=
"
http://www.siyn.org/siyn-page.tld
"
prefix
=
"
page
"
%>
5.2显示list数据
<
logic:iterate id
=
"
data
"
name
=
"
list
"
indexId
=
"
i
"
>
< ul >
< li >< bean:write name = " data " property = " x " /></ li >
< li >< bean:write name = " data " property = " xx " /></ li >
< li >< bean:write name = " data " property = " xxx " /></ li >
</ ul >
</ logic:iterate >
5.3显示导航控制
< ul >
< li >< bean:write name = " data " property = " x " /></ li >
< li >< bean:write name = " data " property = " xx " /></ li >
< li >< bean:write name = " data " property = " xxx " /></ li >
</ ul >
</ logic:iterate >
<
pager:navigator actionPath
=
"
xxx.do?Op=showlist
"
shownum
=
"
3
"
template
=
"
template.jsp
"
/>
这个navigator有三个属性,
actionPath为必须的,请求数据的action地址
shownum可选,导航栏除了首页,上页,下页,末页外,中间的数字页显示几个,默认显示5个
template 可选,为导航栏的模板路径(相对于classes目录),自己可以修改以显示不同风格,默认为org/siyn/common/web/struts/taglib/page/pageControlTemplate.jsp