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分页语句,大佬勿喷,仅供参考。