yeafee@夜飞郎

it's usually better to solve problems with simplicity and finesse rather than muscle.

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  33 随笔 :: 3 文章 :: 2 评论 :: 0 Trackbacks
 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),其中传递四个参数,分别表示页面转向eg.前一页,后一页;当前页;所有页;所有记录数;
在页面上四个页面转换方向都周用getServerList(p1,p2,p3,p4);p1值根据首页设置'first',下一页'next'等,p2,p3,p4值都相等.
取得分页所得数据的主要代码如下:
 1String 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)这个参数Map中用到两个值toPage,rcount(每页显示记录数),
可以根据toPage的不同, Limit出不同段的数据.
select * from table_name LIMIT startrecord,pagecount
posted on 2007-06-10 23:14 @yeafee 阅读(1390) 评论(1)  编辑  收藏 所属分类: 程序语言

评论

# re: 一段分页处理总结(JS数据加减) 2007-06-13 10:03 王永涛
很好  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问