分頁的pageUtil類
阿新 • • 發佈:2018-12-12
package com.shili.util; public class PageUtil { //總條數 private int count; //總導航數 private int navCount; //起始行 當前也頁碼顯示的資料開始的條數 為了在資料庫裡用limit查詢資料使用 private int startRow; //每頁顯示條數 private int pageRow=16; //當前頁 private int curPage; //首頁 private int firstPage=1; //尾頁 private int lastPage; //前一頁 private int prePage; //後一頁 private int nextPage; //起始導航 private int startNav; //結束導航 private int endNav; //建立物件的時候 該物件的所有屬性自動初始化好 /** * * @param count 資料的總條數 由資料庫中查出 * @param curPage 當前頁 由頁面傳入 */ public PageUtil(int count, int curPage){ this.count=count;//總條數 this.curPage=curPage;//當前頁 this.navCount=this.count%this.pageRow>0?this.count/this.pageRow+1:this.count/this.pageRow;//總導航數 this.startRow=(this.curPage-1)*this.pageRow;//起始行 當前也頁碼顯示的資料開始的條數 this.lastPage=this.navCount;//尾頁 this.prePage=this.curPage<=this.firstPage?this.firstPage:this.curPage-1;//前一頁 this.nextPage=this.curPage>=this.lastPage?this.lastPage:this.curPage+1;//後一頁 if(this.navCount<10){ //不足十頁的情況 this.startNav=this.firstPage;//起始導航 this.endNav=this.lastPage;//結束導航 }else{ if(this.curPage<=6){ //靠近首頁的情況 this.startNav=this.firstPage; this.endNav=10; }else if(this.curPage>=this.lastPage-4){ //靠近尾頁的情況 this.startNav=this.lastPage-9; this.endNav=this.lastPage; }else{ this.startNav=this.curPage-5; this.endNav=this.curPage+4; } } } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public int getNavCount() { return navCount; } public void setNavCount(int navCount) { this.navCount = navCount; } public int getStartRow() { return startRow; } public void setStartRow(int startRow) { this.startRow = startRow; } public int getPageRow() { return pageRow; } public void setPageRow(int pageRow) { this.pageRow = pageRow; } public int getCurPage() { return curPage; } public void setCurPage(int curPage) { this.curPage = curPage; } public int getFirstPage() { return firstPage; } public void setFirstPage(int firstPage) { this.firstPage = firstPage; } public int getLastPage() { return lastPage; } public void setLastPage(int lastPage) { this.lastPage = lastPage; } public int getPrePage() { return prePage; } public void setPrePage(int prePage) { this.prePage = prePage; } public int getNextPage() { return nextPage; } public void setNextPage(int nextPage) { this.nextPage = nextPage; } public int getStartNav() { return startNav; } public void setStartNav(int startNav) { this.startNav = startNav; } public int getEndNav() { return endNav; } public void setEndNav(int endNav) { this.endNav = endNav; } }