import java.io.Serializable;
import java.util.List;
public class PageUtil<T> implements Serializable {
private int page;//当前页
private int pre;//上一页
private int next;//下一页
private int totalpage;//尾页
private int size;//每页多少条
private Long total;//总记录数
private List<T> rows;//当前页记录
//自己实现自己
public static void main(String[] args) {
new PageUtil<>();
}
//无参构造
public PageUtil() {
}
//有参构造
public PageUtil(int page, int size, Long total, List<T> rows) {
this.page = page;
//三目运算符
//判断当前页大于1,则当前页-1,否则当前就在第一页
this.pre = page>1?page-1:1;//上一页
//判断当前页小于尾页,则当前页+1,否则当前页就在尾页
this.next = page<this.totalpage?page+1:this.totalpage;//下一页
//计算总页数(总页数),总记录数%每页条数,如果等于0,则没有余数,不需要再加一页,否则再
//加一页,放余出来的记录数
this.totalpage = (int) (total%size==0?total/size:(total/size+1));
this.size = size;
this.total = total;
this.rows = rows;
}
//get/set赋值取值
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getPre() {
return pre;
}
public void setPre(int pre) {
this.pre = pre;
}
public int getNext() {
return next;
}
public void setNext(int next) {
this.next = next;
}
public int getTotalpage() {
return totalpage;
}
public void setTotalpage(int totalpage) {
this.totalpage = totalpage;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}
|