由上一篇文章就可能知道PageBean類,裏面需要哪些參數,有了這些參數我們就可以寫出PageBean類,這個類封裝了一些屬性。
public class PageBean { private List recordList; // 本頁的數據列表 // 指定的 傳遞參數的 private int currentPage; // 當前頁 private int pageCount; // 總頁數 // 查詢數據庫的 private int pageSize; // 每頁顯示條數 private int recordCount; // 總記錄數 private int beginPageIndex; // 頁碼列表的開始索引 private int endPageIndex; // 頁碼列表的結束索引 public PageBean(int currentPage, int pageSize, int recordCount, List recordList) { this.currentPage = currentPage; this.pageSize = pageSize; this.recordList = recordList; this.recordCount = recordCount; // 計算總頁面 pageCount = (recordCount + pageSize - 1) / pageSize; // 計算其他屬性 // 總頁數不大於5頁 if (pageCount <= 5) { beginPageIndex = 1; endPageIndex = pageCount; } // 總頁數大於5頁 else { beginPageIndex = currentPage - 4; endPageIndex = currentPage + 5; if (beginPageIndex < 1) { beginPageIndex = 1; endPageIndex = 10; } if (endPageIndex > pageCount) { beginPageIndex = pageCount - 10 + 1; endPageIndex = pageCount; } } } //其他setget方法 }