您的位置:首页 > 编程语言 > Java开发

java 实现分页的一种方式

2008-02-27 10:08 489 查看
利用向量实现分页的一种方式

view plaincopy to clipboardprint?

/** 当前页 */
private int nowPage = 1;

/** 最大页 */
private int maxPage = 0;

/** 显示数目 */
private String showRows = new String();

/**全部Vector */
private Vector allList = new Vector();

/** 每页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);

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  JAVA 职场 实现