定義兩個Vector,一個為儲存查詢所有記錄的totalV,另一個儲存當(dāng)前頁的記錄currentPageV;
總的記錄數(shù):int totalSize = totalV.getSize();
每頁顯示的記錄數(shù):int countPerPage;
總頁數(shù):int totalPageNum = totalSize/countPerPage;
//如果總的記錄數(shù)和每頁記錄數(shù)的余數(shù)大于零,
//那么總的頁數(shù)為他們的整除結(jié)果加一
if (totalSize%countPerPage > 0 ){
totalPageNum = totalSize/countPerPage + 1;
}
當(dāng)前的頁數(shù):pageNum;
for (int j = 0;j
//分頁,根據(jù)當(dāng)前的頁數(shù)和每頁顯示的記錄數(shù)從totalV中取出記錄
//往currentPageV中添加記錄;
//如果當(dāng)前記錄在(當(dāng)前頁碼-1)*每頁顯示記錄數(shù)(包括等于)
//和 當(dāng)前頁碼*每頁顯示記錄數(shù)(不包括等于)之間的時候;
//就屬于該頁的數(shù)據(jù)
if ( (j >= (pageNum - 1) * countPerPage) && (j < pageNum * countPerPage)) {
currentPageV.addElement(totalV.get(j));
}
//當(dāng)currentPageV記錄數(shù)等于每頁顯示記錄數(shù),
//停止往currentPageV中添加記錄
if (currentPageV.size() == countPerPage) {
break;
}
}
那么,當(dāng)前頁中顯示的記錄,就是currentPageV中的記錄。
posted on 2006-05-29 17:06
javaPlayer 閱讀(613)
評論(0) 編輯 收藏