com.github.hetianyi.common.http.Page Maven / Gradle / Ivy
package com.github.hetianyi.common.http;
import com.github.hetianyi.common.util.CollectionUtil;
import java.util.List;
/**
* 分页工具类
* @param
*
* @author Jason He
* @version 1.0.1
* @since 1.0.1
* @date 2020-01-18
*/
public class Page {
/**
* 分页页码
*/
private int page;
/**
* 分页大小
*/
private int pageSize;
/**
* 总页数
*/
private int totalPages;
/**
* 当前页面记录数
*/
private int size;
/**
* 总记录数
*/
private int totalSize;
/**
* 上一页的最后一个记录id,用于分页加速获取记录
*/
private int lastId;
/**
* 分页数据
*/
private List data;
/**
* Empty constructor
*/
public Page() {
}
/**
* This constructor can used as output parameter.
* @param page 分页
* @param pageSize 分页大小
* @param totalSize 总记录数
* @param data 分页数据
*/
public Page(int page, int pageSize, int totalSize, List data) {
this.page = page;
this.pageSize = pageSize;
this.totalSize = totalSize;
this.data = data;
this.size = CollectionUtil.isNullOrEmpty(data) ? 0 : data.size();
this.totalPages = (totalSize == 0 || totalSize <= pageSize) ? 1 :
(totalSize % pageSize == 0 ? totalSize / pageSize : totalSize / pageSize + 1);
}
/**
* This constructor can used as input parameter.
* @param page 分页
* @param pageSize 分页大小
*/
public Page(int page, int pageSize) {
this.page = page;
this.pageSize = pageSize;
}
/**
* This constructor can used as input parameter.
* @param page 分页
* @param pageSize 分页大小
* @param lastId 上一页的最后一个记录id,用于分页加速获取记录
*/
public Page(int page, int pageSize, int lastId) {
this.page = page;
this.pageSize = pageSize;
this.lastId = lastId;
}
/*************** getters and setters ********************/
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getTotalSize() {
return totalSize;
}
public void setTotalSize(int totalSize) {
this.totalSize = totalSize;
}
public int getLastId() {
return lastId;
}
public void setLastId(int lastId) {
this.lastId = lastId;
}
public List getData() {
return data;
}
public void setData(List data) {
this.data = data;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy