1. 自定义分页工具类
package com.jinchi.common.dto;
import java.util.List;
public class PageBean<T> {
private Integer pageNumber = 1;
private Integer pageSize = 10;
private String sortField;
private String sortType;
private Integer total;
private List<T> list;
private Integer startIndex;
public PageBean() {
}
public PageBean(Integer pageNumber, Integer pageSize, Integer total, List<T> list) {
this.pageNumber = pageNumber;
this.pageSize = pageSize;
this.total = total;
this.list = list;
}
public Integer getStartIndex() {
return (pageNumber - 1) * pageSize;
}
public void setStartIndex(Integer startIndex) {
this.startIndex = startIndex;
}
public Integer getPageNumber() {
return pageNumber;
}
public void setPageNumber(Integer pageNumber) {
this.pageNumber = pageNumber;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public String getSortField() {
return sortField;
}
public void setSortField(String sortField) {
this.sortField = sortField;
}
public String getSortType() {
return sortType;
}
public void setSortType(String sortType) {
this.sortType = sortType;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public Integer getPrePage() {
return this.pageNumber > 1 ? this.pageNumber - 1 : 0;
}
public Integer getNextPage() {
return this.pageNumber < getPages() ? this.pageNumber + 1 : 0;
}
public Integer getPages() {
return this.total % this.pageSize == 0 ? this.total / this.pageSize : this.total / this.pageSize + 1;
}
public Boolean isLastPage() {
return this.total > 0 && pageNumber == getPages();
}
public Boolean isFirstPage() {
return this.total > 0 && pageNumber == 1;
}
}
2、使用
2.1 sql端写法
2.2 调用