無(wú)線&移動(dòng)互聯(lián)網(wǎng)技術(shù)研發(fā)
換位思考·····
posts - 19, comments - 53, trackbacks - 0, articles - 283
BlogJava
::
首頁(yè)
::
新隨筆
::
聯(lián)系
::
聚合
::
管理
java List 分頁(yè)應(yīng)用(二)
Posted on 2010-01-10 02:22
Gavin.lee
閱讀(613)
評(píng)論(0)
編輯
收藏
所屬分類(lèi):
java SE & EE
應(yīng)用類(lèi):
package
com.Gavin.tools.util;
import
java.util.
*
;
/** */
/**
* 為L(zhǎng)ist分頁(yè)
* 樣式比較簡(jiǎn)單,適合WAP使用,直接輸出頁(yè)碼到頁(yè)面
*/
public
class
PagerUtil
{
private
int
pageSize
=
10
;
//
每頁(yè)大小
private
int
nextPage;
//
下一頁(yè)
private
int
prePage;
//
前一頁(yè)
private
int
pageCount;
//
總頁(yè)數(shù)
private
int
currentPage;
//
當(dāng)前頁(yè)
private
int
listSize
=
0
;
//
記錄總數(shù)
private
ArrayList alist
=
new
ArrayList();
private
String url;
/** */
/**
* 初始化記錄列表
*
@param
it Iterator
*
@return
ArrayList
*/
public
ArrayList getAlist(Iterator it)
{
ArrayList al
=
new
ArrayList();
while
(it.hasNext())
{
al.add(it.next());
}
return
al;
}
/** */
/**
* 構(gòu)造方法
*
@param
list Collection
*/
public
PagerUtil(Collection list)
{
alist
=
this
.getAlist(list.iterator());
listSize
=
alist.size();
nextPage
=
1
;
prePage
=
0
;
pageCount
=
listSize
/
pageSize
+
1
;
currentPage
=
1
;
}
/** */
/**
* 構(gòu)造方法
*
@param
list Collection
*
@param
pageSize int
*/
public
PagerUtil(Collection list,
int
pageSize)
{
alist
=
(ArrayList) list;
this
.pageSize
=
pageSize;
listSize
=
alist.size();
nextPage
=
1
;
prePage
=
0
;
pageCount
=
listSize
/
pageSize;
if
(listSize
%
pageSize
>
0
)
{
pageCount
=
pageCount
+
1
;
}
currentPage
=
1
;
}
public
PagerUtil(Vector v,
int
pageSize)
{
for
(
int
i
=
0
; i
<
v.size(); i
++
)
{
alist.add(v.get(i));
}
this
.pageSize
=
pageSize;
listSize
=
alist.size();
nextPage
=
1
;
prePage
=
0
;
pageCount
=
listSize
/
pageSize;
if
(listSize
%
pageSize
>
0
)
{
pageCount
=
pageCount
+
1
;
}
currentPage
=
1
;
}
/** */
/**
* 下一頁(yè)
*
@return
ArrayList
*/
public
int
nextPage()
{
int
tempInt
=
1
;
if
(currentPage
<
this
.getPageCount()
&&
currentPage
>=
1
)
{
tempInt
=
currentPage
+
1
;
}
else
tempInt
=
1
;
return
tempInt;
}
/** */
/**
* 前一頁(yè)
*
@return
ArrayList
*/
public
int
prePage()
{
int
tempInt
=
1
;
if
(currentPage
>
1
)
{
tempInt
=
currentPage
-
1
;
}
else
tempInt
=
this
.getPageCount();
return
tempInt;
}
/** */
/**
* 第一頁(yè)
*
@return
ArrayList
*/
public
int
firstPage()
{
nextPage
=
1
;
prePage
=
this
.getPageCount();
currentPage
=
nextPage;
return
currentPage;
}
/** */
/**
* 最后一頁(yè)
*
@return
ArrayList
*/
public
int
endPage()
{
nextPage
=
this
.getPageCount();
prePage
=
nextPage
-
1
;
currentPage
=
nextPage;
return
currentPage;
}
/** */
/**
* 根據(jù)當(dāng)前頁(yè)得到記錄列表
*
@param
currentPage int
*
@return
ArrayList
*/
public
ArrayList getPageList()
{
ArrayList tempList
=
new
ArrayList();
for
(
int
i
=
(currentPage
-
1
)
*
pageSize; i
<
(currentPage
-
1
)
*
pageSize
+
pageSize; i
++
)
{
if
(i
>=
0
&&
i
<
this
.alist.size())
{
tempList.add(alist.get(i));
}
else
break
;
}
return
tempList;
}
public
String getPageCtrlString()
{
String strCtrl
=
""
;
if
(
this
.currentPage
==
1
)
{
//
strCtrl = "首頁(yè) ";
}
else
{
strCtrl
=
"
<a href='
"
+
url
+
"
?page=1'>首頁(yè)</a>
"
;
}
if
(
this
.currentPage
==
1
)
{
//
strCtrl = strCtrl + "上一頁(yè) ";
}
else
{
strCtrl
=
strCtrl
+
"
<a href='
"
+
url
+
"
?page=
"
+
this
.prePage()
+
"
'>上頁(yè)</a>
"
;
}
if
(
this
.currentPage
==
this
.pageCount)
{
//
strCtrl = strCtrl + "下一頁(yè) ";
}
else
{
strCtrl
=
strCtrl
+
"
<a href='
"
+
url
+
"
?page=
"
+
this
.nextPage()
+
"
'>下頁(yè)</a>
"
;
}
if
(
this
.currentPage
==
this
.pageCount)
{
//
strCtrl = strCtrl + "末頁(yè) ";
}
else
{
strCtrl
=
strCtrl
+
"
<a href='
"
+
url
+
"
?page=
"
+
this
.getPageCount()
+
"
'>末頁(yè)</a>
"
;
}
strCtrl
=
strCtrl
+
"
\n\r
"
;
//
換行
//
strCtrl = strCtrl
//
+ "跳到 <select name='toPage' onChange=\"window.location='" + url
//
+ "?page='+this.options[this.selectedIndex].value;\">";
if
(
this
.getPageCount()
<=
1
)
{
}
else
if
(
this
.getPageCount()
<=
7
)
{
for
(
int
i
=
1
; i
<=
this
.getCurrentPage(); i
++
)
{
if
(i
==
this
.getCurrentPage())
{
strCtrl
=
strCtrl
+
"
<b>
"
+
i
+
"
</b>
"
;
}
else
{
strCtrl
=
strCtrl
+
"
<a href='
"
+
url
+
"
?page=
"
+
i
+
"
'>
"
+
i
+
"
</a>
"
;
}
}
}
else
if
(
4
<
this
.getCurrentPage()
&&
this
.getCurrentPage()
<
(
this
.getPageCount()
-
3
))
{
for
(
int
i
=
this
.getCurrentPage()
-
3
; i
<=
this
.getCurrentPage()
+
3
; i
++
)
{
if
(i
==
this
.getCurrentPage())
{
strCtrl
=
strCtrl
+
"
<b>
"
+
i
+
"
</b>
"
;
}
else
{
strCtrl
=
strCtrl
+
"
<a href='
"
+
url
+
"
?page=
"
+
i
+
"
'>
"
+
i
+
"
</a>
"
;
}
}
}
else
if
(
this
.getCurrentPage()
<=
4
)
{
for
(
int
i
=
1
; i
<=
7
; i
++
)
{
if
(i
==
this
.getCurrentPage())
{
strCtrl
=
strCtrl
+
"
<b>
"
+
i
+
"
</b>
"
;
}
else
{
strCtrl
=
strCtrl
+
"
<a href='
"
+
url
+
"
?page=
"
+
i
+
"
'>
"
+
i
+
"
</a>
"
;
}
}
}
else
if
((
this
.getPageCount()
-
6
)
<=
this
.getCurrentPage())
{
for
(
int
i
=
this
.getPageCount()
-
6
; i
<=
this
.getPageCount(); i
++
)
{
if
(i
==
this
.getCurrentPage())
{
strCtrl
=
strCtrl
+
"
<b>
"
+
i
+
"
</b>
"
;
}
else
{
strCtrl
=
strCtrl
+
"
<a href='
"
+
url
+
"
?page=
"
+
i
+
"
'>
"
+
i
+
"
</a>
"
;
}
}
}
else
{
for
(
int
i
=
this
.getCurrentPage()
-
3
; i
<=
this
.getCurrentPage()
+
3
; i
++
)
{
if
(i
==
this
.getCurrentPage())
{
strCtrl
=
strCtrl
+
"
<b>
"
+
i
+
"
</b>
"
;
}
else
{
strCtrl
=
strCtrl
+
"
<a href='
"
+
url
+
"
?page=
"
+
i
+
"
'>
"
+
i
+
"
</a>
"
;
}
}
}
strCtrl
=
strCtrl
+
"
\n\r
"
;
//
換行
strCtrl
=
strCtrl
+
"
當(dāng)前
"
+
this
.getCurrentPage()
+
"
/
"
+
this
.getPageCount()
+
"
頁(yè) 每頁(yè)
"
+
this
.getPageSize()
+
"
條 共
"
+
this
.listSize
+
"
條
"
;
return
strCtrl;
}
public
int
getCurrentPage()
{
return
currentPage;
}
public
int
getNextPage()
{
return
nextPage;
}
public
int
getPageCount()
{
return
pageCount;
}
public
int
getPageSize()
{
return
pageSize;
}
public
int
getPrePage()
{
return
prePage;
}
public
String getUrl()
{
return
url;
}
public
void
setPrePage(
int
prePage)
{
this
.prePage
=
prePage;
}
public
void
setPageSize(
int
pageSize)
{
this
.pageSize
=
pageSize;
}
public
void
setPageCount(
int
pageCount)
{
this
.pageCount
=
pageCount;
}
public
void
setNextPage(
int
nextPage)
{
this
.nextPage
=
nextPage;
}
public
void
setCurrentPage(
int
currentPage)
{
if
(currentPage
>
this
.getPageCount())
{
this
.currentPage
=
this
.getPageCount();
}
else
if
(currentPage
<
0
)
{
this
.currentPage
=
1
;
}
else
{
this
.currentPage
=
currentPage;
}
}
public
void
setUrl(String url)
{
this
.url
=
url;
}
}
測(cè)試類(lèi):
package
com.Gavin.tools.util;
import
java.util.ArrayList;
public
class
TestPagrUtil
{
public
static
void
main(String args[])
{
ArrayList al
=
new
ArrayList();
al.add(
"
a
"
);
al.add(
"
b
"
);
al.add(
"
c
"
);
al.add(
"
d
"
);
al.add(
"
e
"
);
al.add(
"
f
"
);
al.add(
"
g
"
);
al.add(
"
h
"
);
al.add(
"
i
"
);
al.add(
"
j
"
);
al.add(
"
k
"
);
al.add(
"
l
"
);
al.add(
"
m
"
);
al.add(
"
n
"
);
PagerUtil autopage
=
new
PagerUtil(al,
1
);
autopage.setCurrentPage(
5
);
autopage.setUrl(
"
/page/user/account/isprize.jsp
"
);
ArrayList currentPageList
=
autopage.getPageList();
String ctrlStr
=
autopage.getPageCtrlString();
for
(Object o: currentPageList)
{
System.out.println(o.toString());
}
System.out.println(ctrlStr);
}
}
//
//
e
//
<a href='/page/user/account/isprize.jsp?page=1'>首頁(yè)</a> <a href='/page/user/account/isprize.jsp?page=4'>上頁(yè)</a> <a href='/page/user/account/isprize.jsp?page=6'>下頁(yè)</a> <a href='/page/user/account/isprize.jsp?page=14'>末頁(yè)</a>
//
//
<a href='/page/user/account/isprize.jsp?page=2'>2</a> <a href='/page/user/account/isprize.jsp?page=3'>3</a> <a href='/page/user/account/isprize.jsp?page=4'>4</a> <b>5</b> <a href='/page/user/account/isprize.jsp?page=6'>6</a> <a href='/page/user/account/isprize.jsp?page=7'>7</a> <a href='/page/user/account/isprize.jsp?page=8'>8</a>
//
//
當(dāng)前5/14頁(yè) 每頁(yè)1條 共14條
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
相關(guān)文章:
commons-lang-2.4.jar 包常用方法集錦
String&InputStream的相互轉(zhuǎn)化
java 堆與棧的詳細(xì)介紹
HttpClient 一文通 (摘)
java List 分頁(yè)應(yīng)用(二)
java List 分頁(yè)應(yīng)用(一)
java 有效的防止SQL注入
java clone
Java 序列化與反序列化
Junit 單元測(cè)試
Powered by:
BlogJava
Copyright © Gavin.lee
日歷
<
2025年5月
>
日
一
二
三
四
五
六
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
常用鏈接
我的隨筆
我的文章
我的評(píng)論
我的參與
最新評(píng)論
留言簿
(13)
給我留言
查看公開(kāi)留言
查看私人留言
我參與的團(tuán)隊(duì)
深圳Java俱樂(lè)部(0/0)
隨筆檔案
(19)
2011年6月 (1)
2011年5月 (1)
2010年12月 (1)
2010年5月 (1)
2010年1月 (1)
2009年8月 (2)
2009年6月 (6)
2009年5月 (6)
文章分類(lèi)
(277)
Date tools(4)
FreeMarker (7)
java design pattern(3)
java SE & EE(60)
JDBC(14)
jsp 【勿忘】(5)
Linux command(7)
Linux shell 入門(mén)(11)
Linux 日常應(yīng)用(5)
Log && File Operate(8)
MemCache (5)
SiteMesh 頁(yè)面裝飾組件(2)
SSH2 --Hibernate(6)
SSH2 --Spring(9)
SSH2 --Struts2(21)
Subversion(Svn)(5)
wap 積累(8)
web 積累(前端 + 后臺(tái))(33)
xml doc 操作(12)
多線程(6)
性能分析(7)
類(lèi)的設(shè)計(jì)(4)
經(jīng)典語(yǔ)錄(3)
經(jīng)驗(yàn)&常識(shí)(32)
文章檔案
(282)
2011年7月 (1)
2011年6月 (1)
2011年5月 (1)
2011年4月 (1)
2011年3月 (1)
2011年2月 (1)
2010年12月 (6)
2010年11月 (8)
2010年10月 (1)
2010年9月 (6)
2010年6月 (7)
2010年5月 (22)
2010年4月 (1)
2010年3月 (14)
2010年2月 (2)
2010年1月 (10)
2009年12月 (32)
2009年11月 (30)
2009年10月 (2)
2009年9月 (5)
2009年8月 (13)
2009年7月 (41)
2009年6月 (43)
2009年5月 (33)
收藏夾
(7)
java 基礎(chǔ)類(lèi)(1)
JSP(1)
server(2)
WEB(1)
數(shù)據(jù)庫(kù)
設(shè)計(jì)模式(2)
友情鏈接
blogjava中的強(qiáng)人
chinaunix 社區(qū)
java 世紀(jì)網(wǎng)
java 基礎(chǔ)輔導(dǎo)文章
javaeye 藍(lán)色的風(fēng)
SQL語(yǔ)句教程
與java共舞
中國(guó)協(xié)議分析網(wǎng)
中文java技術(shù)網(wǎng)
多線程
待看的文章
感興趣的 csdn
我的漫漫程序之旅
新起點(diǎn),新開(kāi)始
夢(mèng)幻之旅
趙學(xué)慶 的博客
超級(jí)多文章的牛人
隔葉黃鶯 The Blog of Unmi
高手論壇
最新隨筆
1.?Mysql:1292 truncated incorrect double value -- concat 函數(shù)用法
2.?Mysql 插入當(dāng)前時(shí)間【摘】
3.?學(xué)計(jì)算機(jī)的你傷不起啊【雷人】
4.?ucweb和opera工作原理的差別【摘】
5.?清朝皇帝列表
6.?設(shè)置IE查看源文件時(shí)默認(rèn)打開(kāi)的編輯器【轉(zhuǎn)】
7.?subclipse svn修改用戶名密碼問(wèn)題【摘】
8.?hibernate.dialect (Hibernate SQL方言)-備用
9.?Tomcat JspFactory的異常的原因及解決辦法
10.?關(guān)于MyEclipse中的Tomcat啟動(dòng)的問(wèn)題 【Tomcat JDK name error】
11.?win-xp 自動(dòng)關(guān)機(jī)腳本 【古老的記憶】
12.?Office 2007 Word 打開(kāi)故障 - "The setup controller has encountered a problem during instll"
13.?木匠家的門(mén)
14.?MyEclipse 后臺(tái)進(jìn)程一直運(yùn)行"computing additional info"的解決辦法
15.?MyEclipse 一直 initializing java tooling······
16.?MyEclipse 代碼提示(“@”自動(dòng)提示)
17.?org.hibernate.hql.ast.QuerySyntaxException(我的流水賬)
18.?org.hibernate.hql.antlr.HqlBaseParser.recover(NoSuchMethodError)
19.?SVN:cannot map the project with svn provider解決辦法
20.?WAP1.0 前端開(kāi)發(fā)經(jīng)驗(yàn)(原創(chuàng)-JSP)
21.?Notepad++提示"Load langs.xml failed!"的解決方法
22.?讓你的PC也能訪問(wèn)手機(jī)騰訊網(wǎng)
23.?【轉(zhuǎn)】Proxool 連接池的配置-hibernate篇
24.?Hibernate 主鍵生成策略
25.?Quartz cron 表達(dá)式格式的含義
26.?OGNL功用?。?!
27.?使用Appfuse快速構(gòu)建J2EE應(yīng)用
28.?大型門(mén)戶網(wǎng)站的十四大技術(shù)?。。?/a>
29.?Urlrewrite與Struts2.x結(jié)合使用
30.?HttpWatch的檢測(cè)指示說(shuō)明:Blocked、Connect、Send、Wait、Receive
31.?解讀JAR,SIS,SISX格式區(qū)別?。?!
32.?commons-lang-2.4.jar 包常用方法集錦
33.?Struts2中解決一個(gè)表單多種提交
34.?JSTL(Java Standard Tag Library) 標(biāo)記庫(kù)的使用
35.?Struts2驗(yàn)證錯(cuò)誤信息的兩個(gè)經(jīng)典方法-addFieldError&addActionError
36.?Hibernate常見(jiàn)異常-無(wú)法轉(zhuǎn)換為內(nèi)部表示
37.?Spring AOP詳細(xì)導(dǎo)讀-用多手段實(shí)例對(duì)比呈現(xiàn)AOP
38.?Struts2 Result-type(封裝Action層到View層的跳轉(zhuǎn)邏輯)
39.?在Struts2中以IOC和非IOC方式獲取session&request
40.?采用url鏈接形式提交action(非s:from方式提交)
搜索
積分與排名
積分 - 356314
排名 - 156
最新評(píng)論
1.?re: Struts2驗(yàn)證錯(cuò)誤信息的兩個(gè)經(jīng)典方法-addFieldError&addActionError
S2C4
--asdad
2.?re: Struts2驗(yàn)證錯(cuò)誤信息的兩個(gè)經(jīng)典方法-addFieldError&addActionError[未登錄](méi)
asd
--as
3.?21232.2323
323432432
--馮海波
4.?re: SVN:cannot map the project with svn provider解決辦法[未登錄](méi)
多謝!已經(jīng)解決。
--will
5.?re: Struts2驗(yàn)證錯(cuò)誤信息的兩個(gè)經(jīng)典方法-addFieldError&addActionError
44
--2
閱讀排行榜
1.?學(xué)計(jì)算機(jī)的你傷不起啊【雷人】(1020)
2.?看看這個(gè)笑話,你就知道干IT的不容易了?。?623)
3.?清朝皇帝列表(617)
4.? 每天讀一遍,不久你就會(huì)變! ---- 很好很強(qiáng)大(469)
5.?木匠家的門(mén)(423)
評(píng)論排行榜
1.?學(xué)計(jì)算機(jī)的你傷不起啊【雷人】(0)
2.?清朝皇帝列表(0)
3.?木匠家的門(mén)(0)
4.? 每天讀一遍,不久你就會(huì)變! ---- 很好很強(qiáng)大(0)
5.?我喜歡的語(yǔ)錄(0)
主站蜘蛛池模板:
欧洲精品99毛片免费高清观看
|
国产v亚洲v天堂无码网站
|
亚洲成av人片在线天堂无
|
无码国产精品一区二区免费I6
|
亚洲网站免费观看
|
1区2区3区产品乱码免费
|
久久久久亚洲AV无码网站
|
午夜影院免费观看
|
亚洲伊人tv综合网色
|
91久久青青草原线免费
|
亚洲视频精品在线
|
1000部啪啪未满十八勿入免费
|
亚洲AV成人一区二区三区AV
|
免费精品一区二区三区第35
|
激情五月亚洲色图
|
日韩一区二区a片免费观看
|
波多野结衣亚洲一级
|
毛片免费全部免费观看
|
亚洲精品亚洲人成在线
|
日韩中文无码有码免费视频
|
美国毛片亚洲社区在线观看
|
xvideos亚洲永久网址
|
一区二区三区免费在线视频
|
青青草97国产精品免费观看
|
免费中文字幕在线
|
四虎国产精品成人免费久久
|
久久久久亚洲AV无码专区网站
|
三年片免费高清版
|
中文字幕免费在线
|
亚洲国产成人精品久久
|
成年女人免费视频播放77777
|
亚洲AV日韩综合一区
|
亚洲国产成人爱av在线播放
|
h片在线观看免费
|
亚洲成a人片在线观看无码
|
久久精品国产亚洲精品
|
a视频在线免费观看
|
久久久无码精品亚洲日韩蜜臀浪潮
|
亚洲一区二区三区香蕉
|
久久综合给合久久国产免费
|
亚洲五月丁香综合视频
|