利用向量实现分页的一种方式
-
- private int nowPage = 1;
-
-
- private int maxPage = 0;
-
-
- private String showRows = new String();
-
-
- private Vector allList = new Vector();
-
-
- private Vector resultList = new Vector();
-
-
- public ChangePage(Vector pList, int pNowPage, String pShowRows) {
-
- this.allList = pList;
-
- try {
- this.nowPage = pNowPage;
- if (this.nowPage == 0) {
- this.nowPage = 1;
- }
- } catch (Exception e) {
- this.nowPage = 1;
- }
-
-
- try {
- if (!pShowRows.equals(Constants.SHOWALL)) {
- if (Integer.parseInt(pShowRows)==0) {
- this.showRows = Constants.SHOWALL;
- } else {
- this.showRows = pShowRows;
- }
- } else {
- this.showRows = pShowRows;
- }
- } catch (Exception e) {
- this.showRows = Constants.SHOWALL;
- }
-
-
- if (this.showRows.equals(Constants.SHOWALL)) {
-
- this.resultList = pList;
-
- this.maxPage = 1;
- } else {
-
- int counts = Integer.parseInt(this.showRows);
- int tmpCount = 0;
- Vector vAllPage = new Vector();
- Vector vOnePage = new Vector();
- for (int i=0; i<THIS.ALLLIST.SIZE(); (tmpCount if tmpCount++; { i++)>counts) {
- vAllPage.add(vOnePage);
- vOnePage = new Vector();
- tmpCount = 1;
- }
- vOnePage.add(allList.get(i));
- }
- if (tmpCount<=counts) {
- vAllPage.add(vOnePage);
- }
-
- this.maxPage = vAllPage.size();
-
- if (this.nowPage>this.maxPage) {
- this.nowPage = this.maxPage;
- }
- this.resultList = (Vector) vAllPage.get(this.nowPage-1);
-
- }
- }
本文出自 51CTO.COM技术博客 |