- import java.util.List;
- public class SplitPage {
- private List totalResult = null; //所有的数据
- private List pageResult = null; //每页的数据
- private int pageSize = 10; // 每页显示的行数
- private int totalRow; //所有数据的行数
- private int totalPage; //总共的页数
- private int thisPage; //当前页面
- public SplitPage(List list) {
- super();
- this.totalResult = list;
- this.totalRow=list.size();
- this.thisPage=1;
- int page=this.totalRow/this.pageSize;
- if(this.totalRow%this.pageSize!=0)
- this.totalPage=page+1;
- else
- this.totalPage=page;
- }
- public SplitPage(List list,int num) {
- super();
- this.pageSize = num;
- this.totalResult = list;
- this.totalRow=list.size();
- this.thisPage=1;
- int page=this.totalRow/this.pageSize;
- if(this.totalRow%this.pageSize!=0)
- this.totalPage=page+1;
- else
- this.totalPage=page;
- }
- public List getFirstPage(){
- thisPage = 1;
- if(totalRow <>
- pageResult = totalResult;
- else
- pageResult = totalResult.subList(0, pageSize);
- return pageResult;
- }
- public List getLastPage(){
- thisPage = totalPage;
- if(totalRow <>
- pageResult = totalResult;
- else
- pageResult = totalResult.subList((totalPage-1)*pageSize,totalRow);
- return pageResult;
- }
- public List gotoPage(int go){
- thisPage = go;
- if(go == 1)
- return getFirstPage();
- else if(go == totalPage)
- return getLastPage();
- else{
- pageResult = totalResult.subList((go-1)*pageSize, go*pageSize);
- return pageResult;
- }
- }
- public List goNextPage(int current){
- current++;
- return gotoPage(current);
- }
- public int getPageSize() {
- return pageSize;
- }
- public void setPageSize(int pageSize) {
- this.pageSize = pageSize;
- }
- public List goPrePage(int current){
- current--;
- return gotoPage(current);
- }
- public int getTotalPage() {
- return totalPage;
- }
- public void setTotalPage(int totalPage) {
- this.totalPage = totalPage;
- }
- public int getThisPage() {
- return thisPage;
- }
- public void setThisPage(int thisPage) {
- this.thisPage = thisPage;
- }
- }
2010年8月31日星期二
一个分页工具类
订阅:
博文 (Atom)