Java接口分页模版
import java.io.Serializable;
import java.util.List;
public final class PageModel<T> implements Serializable {
private static final long serialVersionUID = 1L;
private int currentPage;
private int pageSize;
private int totalPage = 1;
private int totalRecord;
private List<T> dataList;
public PageModel() {
}
public PageModel(final int pageSize, final int currentPage, final int totalRecord, List<T> dataList) {
this.pageSize = pageSize;
this.totalRecord = totalRecord;
this.dataList = dataList;
this.currentPage = currentPage;
this.totalPage = this.totalRecord == 0 ? 1 : (this.totalRecord + this.pageSize - 1) / this.pageSize;
}
@SuppressWarnings("unchecked")
public static PageModel<?> newPageModel(final int pageSize, final int currentPage, final int totalRecord, List<?> dataList) {
return new PageModel(pageSize, currentPage, totalRecord, dataList);
}
private void setCurrentPage(int currentPage) {
if (currentPage < 1) {
this.currentPage = 1;
}
if (currentPage > totalPage) {
this.currentPage = totalPage;
}
}
public int getCurrentPage() {
return currentPage;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getStartRow() {
return (currentPage - 1) * pageSize;
}
public int getEndRow() {
return currentPage * pageSize;
}
public List<T> getDataList() {
return dataList;
}
public void setDataList(List<T> dataList) {
this.dataList = dataList;
}
public int getFirst() {
return 1;
}
public int getPrevious() {
return currentPage - 1;
}
public int getNext() {
return currentPage + 1;
}
public int getLast() {
return totalPage;
}
}