public class PageBean<T> {
private int pageCount = 0; // 總頁數
private List<T> pageData = null; // 當前頁數據集
private int pageSize = 10; // 每頁大小
private int currentPage = 1; // 當前頁
private long totalRecord = 0; // 總記錄數
private int beginIndex = 0; // 分頁起始記錄號
private int endIndex = 1; // 分頁結束記錄號
public int getPageCount() {
pageCount = (int)(totalRecord + pageSize -1)/pageSize;
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public List<T> getPageData() {
return pageData;
}
public void setPageData(List<T> pageData) {
this.pageData = pageData;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getCurrentPage() {
if (currentPage < 1) {
currentPage = 1;
}
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public long getTotalRecord() {
if (totalRecord < 0) {
totalRecord = 0;
}
return totalRecord;
}
public void setTotalRecord(long totalRecord) {
this.totalRecord = totalRecord;
}
public int getBeginIndex() {
beginIndex = (currentPage - 1) * pageSize+1;
return beginIndex;
}
public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}
public int getEndIndex() {
endIndex = currentPage * pageSize;
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
}
頁面上,使用jQuery的Ajax發送後臺請求信息:
$.ajax({
type:"post",
url:"requestPage",
dataType:"json",
data:{這裏就是封裝數據的地方,比如妳要到第二頁的時候,在這之前要讀取當前的頁數,並進行適當的判斷,是鍵值對的形式例如:"current":1,"pageSize":10},
success:function(data){
這裏是返回json字符串
var jsonObj=$(data);
然後解析遍歷json
$.each(data.pageData,function(index,item){
這個回調函數裏面的第壹個參數是下標,第二個參數是集合裏面的單個對象
然後生成顯示…………結束
});
}
}):