?1
<
script?language
=
"
JavaScript
"
?type
=
"
text/JavaScript
"
>
?2
function
?getServerList(dir,curpage,totalpage,totalrecordcount)
{
?3
???
var
?page;
?4
??
if
(dir
==
"
first
"
)
{?page
=
1
;}
?5
??
if
(dir
==
"
last
"
)
{page
=
totalpage?;}
?6
??
if
(dir
==
"
previous
"
)
{
?7
?????
if
(curpage
==
"
1
"
)
{
?8
???????page
=
1
;
?9
?????}
else
{
10
?????page
=
parseInt(curpage)
-
parseInt(
1
);
11
?????}
12
??}
13
??
if
(dir
==
"
next
"
)
{
14
?????
if
(parseInt(curpage)
<
parseInt(totalpage))
{
15
???????page
=
parseInt(curpage)
+
parseInt(
1
);
16
?????}
else
{
17
???????page
=
totalpage;
18
?????}
19
??}
20
??
//
alert(page);
21
??
var
?action
=
"
***.shtml
"
;
22
??document.location.href
=
action
+
"
?page=
"
+
page;
23
}
24
</
script
>
getServerList(p1,p2,p3,p4),其中傳遞四個(gè)參數(shù),分別表示頁(yè)面轉(zhuǎn)向eg.前一頁(yè),后一頁(yè);當(dāng)前頁(yè);所有頁(yè);所有記錄數(shù);
在頁(yè)面上四個(gè)頁(yè)面轉(zhuǎn)換方向都周用getServerList(p1,p2,p3,p4);p1值根據(jù)首頁(yè)設(shè)置'first',下一頁(yè)'next'等,p2,p3,p4值都相等.
取得分頁(yè)所得數(shù)據(jù)的主要代碼如下:
?1
String?page=?request.getParameter("page");
?2
????????String?to=request.getParameter("toPage");
?3
????????int?someCount=?getSystemManager().getAdvertisementCount();
?4
????????int?pageCount=?0;
?5
????????if(someCount<Constants.PAGENATION_RECORDS_COUNT)
{
?6
????????????pageCount=someCount==0?0:1;
?7
????????}else
{
?8
????????????if(someCount%Constants.PAGENATION_RECORDS_COUNT==0)
{
?9
????????????????pageCount=someCount/Constants.PAGENATION_RECORDS_COUNT;
10
????????????}else
{
11
????????????????pageCount=someCount/Constants.PAGENATION_RECORDS_COUNT+1;
12
????????????}
13
????????}
14
????????paramMap.put("totalRecordCount",someCount);
15
????????paramMap.put("totalPage",pageCount);
16
????????paramMap.put("rcount",Constants.PAGENATION_RECORDS_COUNT);
17
????????if(to!=null&&to.trim().length()>0)
{
18
??????????????if(Integer.parseInt(to)>pageCount)
{
19
????????????????paramMap.put("toPage",?pageCount);
20
?????????????}else
{
21
????????????????paramMap.put("toPage",to);
22
????????????}
23
????????????paramMap.put("currentPage",Integer.parseInt(to));
24
????????}
25
????????if(page!=null)
{
26
????????????paramMap.put("toPage",page);
27
????????????paramMap.put("currentPage",Integer.parseInt(page));
28
????????}
29
????????if(to==null&&page==null)
{
30
????????????paramMap.put("toPage","1");
31
????????????paramMap.put("currentPage","1");
32
????????}
33
????????if(paramMap.get("toPage")==null)
{
34
????????????paramMap.put("toPage","1");
35
????????????paramMap.put("currentPage","1");
36
????????}
37
????????List?adsList?=?getSystemManager().getLiveAdverAndServerList(paramMap); getLiveServerList(paramMap)這個(gè)參數(shù)Map中用到兩個(gè)值toPage,rcount(每頁(yè)顯示記錄數(shù)),
可以根據(jù)toPage的不同, Limit出不同段的數(shù)據(jù).
select?*?from?table_name?LIMIT?startrecord,pagecount