package com.tradingplatform.dto;
import java.util.List;
/**
* 分页原理页面传送数据的Dto
* @param <T>:传送的数据的类型
*/
public class PageJumpDataDto<T> {
private int currentPage=1; //当前页
private int totalPage=0; //总共页
private int totalRecord=0; //总记录数
private List<T> listData; //数据
private int pageSize=6; //每页记录数
public PageJumpDataDto() {}
public PageJumpDataDto(int currentPage, int totalPage, int totalRecord, List<T> listData, int pageSize) {
super();
this.currentPage = currentPage;
this.totalPage = totalPage;
this.totalRecord = totalRecord;
this.listData = listData;
this.pageSize = pageSize;
}
public PageJumpDataDto(int currentPage, List<T> listData) {
if(listData==null) return;
this.totalRecord = listData.size();
//得到总页数
this.totalPage = this.totalRecord/this.pageSize;
if(this.totalRecord%this.pageSize!=0) this.totalPage+=1;
//得到当前页数
if(this.totalPage<currentPage){
this.currentPage=this.totalPage;
}else{
this.currentPage=currentPage;
}
if(this.currentPage<1) this.currentPage=1;
//得到截取的展示数据
int begin=this.pageSize*(this.currentPage-1);
int end= (this.pageSize*this.currentPage)>this.totalRecord?this.totalRecord:(this.pageSize*this.currentPage);
this.listData=listData.subList(begin, end);
}
public PageJumpDataDto(int currentPage, List<T> listData,int pageSize) {
if(listData==null) return;
this.pageSize=pageSize;
this.totalRecord = listData.size();
//得到总页数
this.totalPage = this.totalRecord/this.pageSize;
if(this.totalRecord%this.pageSize!=0) this.totalPage+=1;
//得到当前页数
if(this.totalPage<currentPage){
this.currentPage=this.totalPage;
}else{
this.currentPage=currentPage;
}
if(this.currentPage<1) this.currentPage=1;
//得到截取的展示数据
int begin=this.pageSize*(this.currentPage-1);
int end= (this.pageSize*this.currentPage)>this.totalRecord?this.totalRecord:(this.pageSize*this.currentPage);
this.listData=listData.subList(begin, end);
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}
public List<T> getListData() {
return listData;
}
public void setListData(List<T> listData) {
this.listData = listData;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
}
java分页实现
猜你喜欢
转载自blog.csdn.net/qq_28851503/article/details/73245302
今日推荐
周排行