1 import java.util.List;
2
3 /**
4 * 分頁工具
5 * @author Administrator
6 *
7 */
8 public class PageBean<T> { 9 10 private int pageNo = 1; //當前頁 11 private int pageSize = 4; //每頁個數 12 private int totalCount; //總記錄數 13 private int totalPages; //總頁數--只讀 14 private List<T> pageList; //每頁對應的集合泛型 15 public int getPageNo() { 16 return pageNo; 17 } 18 //當前頁碼不能小於1不能大於總頁數 19 public void setPageNo(int pageNo) { 20 if(pageNo<1) 21 this.pageNo = 1; 22 else if(pageNo > totalPages) 23 this.pageNo = totalPages; 24 else 25 this.pageNo = pageNo; 26 } 27 public int getPageSize() { 28 return pageSize; 29 } 30 public void setPageSize(int pageSize) { 31 this.pageSize = pageSize; 32 } 33 //總記錄數決定總頁數 34 public void setTotalCount(int totalCount) { 35 this.totalCount = totalCount; 36 this.totalPages = (this.totalCount%this.pageSize==0)?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1; 37 } 38 public int getTotalCount() { 39 return totalCount; 40 } 41 42 //只讀 43 public int getTotalPages() { 44 return totalPages; 45 } 46 47 48 public List<T> getPageList() { 49 return pageList; 50 } 51 public void setPageList(List<T> pageList) { 52 this.pageList = pageList; 53 } 54 public PageBean(int pageNo, int pageSize, int totalCount, int totalPages, 55 List<T> pageList) { 56 super(); 57 this.pageNo = pageNo; 58 this.pageSize = pageSize; 59 this.totalCount = totalCount; 60 this.totalPages = totalPages; 61 this.pageList = pageList; 62 } 63 public PageBean() { 64 super(); 65 // TODO Auto-generated constructor stub 66 } 67 68 }
mysql分頁:select * from 表 limit (pageNo-1)*pageSize,pageSize;
oracle分頁:select a.* (select 表.*,rowum rn from 表) a where rn>(pageNo-1)*pageSize and rn <=pageNo*pageSize;
這是一個最簡單分頁工具類,順便附上mysql以及oracle分頁語句,大佬勿噴,僅供參考。