You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.demo.common.util;
import lombok.ToString;
/**
* 分页工具类
*/
@ToString
public class Page {
private int start; //开始页数
private int count; //每页显示个数
private int total; //总个数
private static final int defaultCount = 8; //默认每页显示5条
public Page (){
count = defaultCount;
}
public Page(int start, int count) {
this();
this.start = start;
this.count = count;
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public boolean isHasPreviouse(){
if(start==0)
return false;
return true;
}
public boolean isHasNext(){
if(start==getLast())
return false;
return true;
}
public int getTotalPage(){
int totalPage;
// 假设总数是50是能够被5整除的那么就有10页
if (0 == total % count)
totalPage = total /count;
// 假设总数是51不能够被5整除的那么就有11页
else
totalPage = total / count + 1;
if(0==totalPage)
totalPage = 1;
return totalPage;
}
public int getLast(){
int last;
// 假设总数是50是能够被5整除的那么最后一页的开始就是45
if (0 == total % count)
last = total - count;
// 假设总数是51不能够被5整除的那么最后一页的开始就是50
else
last = total - total % count;
last = last<0?0:last;
return last;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
}