注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 Pass4sure CCNA640-802 v3..
 帮助

java 实现分页的一种方式


2008-02-27 10:08:09
 标签:JAVA 实现 分页   [推送到技术圈]

利用向量实现分页的一种方式
  1. /** 当前页 */  
  2.         private int nowPage = 1;   
  3.   
  4.         /** 最大页 */  
  5.         private int maxPage = 0;   
  6.   
  7.         /** 显示数目 */  
  8.         private String showRows = new String();   
  9.   
  10.         /**全部Vector */  
  11.         private Vector allList = new Vector();   
  12.   
  13.         /** 每页Vector */  
  14.         private Vector resultList = new Vector();   
  15.   
  16.         //改变页数,更新变量   
  17.         public ChangePage(Vector pList, int pNowPage, String pShowRows) {   
  18.                 
  19.             this.allList = pList;   
  20.             //当前页   
  21.             try {   
  22.                 this.nowPage = pNowPage;   
  23.                 if (this.nowPage == 0) {   
  24.                     this.nowPage = 1;   
  25.                 }   
  26.             } catch (Exception e) {   
  27.                 this.nowPage = 1;   
  28.             }   
  29.   
  30.             //显示数目   
  31.             try {   
  32.                 if (!pShowRows.equals(Constants.SHOWALL)) {   
  33.                     if (Integer.parseInt(pShowRows)==0) {   
  34.                         this.showRows = Constants.SHOWALL;   
  35.                     } else {   
  36.                         this.showRows = pShowRows;   
  37.                     }   
  38.                 } else {   
  39.                     this.showRows = pShowRows;   
  40.                 }   
  41.             } catch (Exception e) {   
  42.                 this.showRows = Constants.SHOWALL;   
  43.             }   
  44.   
  45.             //最大页,每页   
  46.             if (this.showRows.equals(Constants.SHOWALL)) {   
  47.                 //当前页   
  48.                 this.resultList = pList;   
  49.                 //最大页   
  50.                 this.maxPage = 1;   
  51.             } else {   
  52.                 //显示数目   
  53.                 int counts = Integer.parseInt(this.showRows);   
  54.                 int tmpCount = 0;   
  55.                 Vector vAllPage = new Vector();   
  56.                 Vector vOnePage = new Vector();   
  57.                 for (int i=0; i<THIS.ALLLIST.SIZE(); (tmpCount if tmpCount++; { i++)>counts) {   
  58.                         vAllPage.add(vOnePage);   
  59.                         vOnePage = new Vector();   
  60.                         tmpCount = 1;   
  61.                     }   
  62.                     vOnePage.add(allList.get(i));   
  63.                 }   
  64.                 if (tmpCount<=counts) {   
  65.                     vAllPage.add(vOnePage);   
  66.                 }   
  67.   
  68.                 this.maxPage = vAllPage.size();   
  69.   
  70.                 if (this.nowPage>this.maxPage) {   
  71.                     this.nowPage = this.maxPage;   
  72.                 }   
  73.                 this.resultList = (Vector) vAllPage.get(this.nowPage-1);   
  74.   
  75.             }   
  76.         }  




    文章评论
 
 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: