All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.hmtools.model.PageModel Maven / Gradle / Ivy

There is a newer version: 0.0.4-beta
Show newest version
package top.hmtools.model;

import java.io.Serializable;

/**
 * 分页模型实体类
 * @author HyboJ
 * 创建日期:2017-1-12下午1:32:16
 */
public class PageModel implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 805872895554443997L;

	/**
	 * 总条目数,初始化需要
	 */
	private int totalItem=0;
	
	/**
	 * 总页数
	 */
	private int totalPages;
	
	/**
	 * 每页的总条目数
	 */
	private int pageSize = 20;
	
	/**
	 * 当前页码,初始化需要
	 */
	private int currPageNo = 1;
	
	/**
	 * 上一页的 页码
	 */
	private int prePageNo;
	
	/**
	 * 下一页的 页码
	 */
	private int nextPageNo;
	
	/**
	 * 首页页码
	 */
	private int firstPageNo = 1;
	
	/**
	 * 末页页码
	 */
	private int endPageNo;
	
	/**
	 * 当前页码中条目的起始条目排序号
	 */
	private int startItemNo;
	
	/**
	 * 当前页码中条目的结束条目排序号
	 */
	private int endItemNo;
	
	/**
	 * 当前页是否是首页
	 */
	private boolean isFirstPageNo;
	
	/**
	 * 当前页是否是末页
	 */
	private boolean isEndPageNo;
	
	/**
	 * 是否有上一页
	 */
	private boolean isHasPrePageNo;
	
	/**
	 * 是否有下一页
	 */
	private boolean isHasNextPageNo;
	
	public PageModel(int totalItem,int currPageNo,int pageSieze){
		this.init(totalItem, currPageNo, pageSieze);
	}
	
	public PageModel(int totalItem,int currPageNo){
		this.init(totalItem, currPageNo);
	}
	
	public PageModel(int totalItem){
		this.init(totalItem);
	}
	
	public PageModel(){
		this.init();
	}
	
	/**
	 * 初始化 分页模型对象实例
	 * @param totalItem
	 * @param currPageNo
	 * @param pageSize
	 */
	public void init(int totalItem,int currPageNo,int pageSize){
		this.pageSize = pageSize;
		this.init(totalItem, currPageNo);
	}
	
	/**
	 * 初始化 分页模型对象实例
	 * @param totalItem
	 * @param currPageNo
	 */
	public void init(int totalItem,int currPageNo){
		this.currPageNo = currPageNo;
		this.init(totalItem);
	}
	
	/**
	 * 初始化 分页模型对象实例
	 * @param totalItem
	 */
	public void init(int totalItem){
		this.totalItem = totalItem;
		this.init();
	}
	
	/**
	 * 初始化 分页模型对象实例
	 */
	public void init(){
		//计算总页数
		if(this.totalItem<=0){
			this.totalPages=1;
		}else{
			int pageNoTmp = this.totalItem/this.pageSize;
			int moTmp = this.totalItem%this.pageSize;
			if(moTmp>0){
				pageNoTmp++;
			}
			
			this.totalPages = pageNoTmp;
		}
		
		//计算上一页页码
		if(this.totalPages >= 1){
			if(this.currPageNo > 1){
				this.prePageNo = this.currPageNo-1;
			}else{
				this.prePageNo = 1;
			}
		}else{
			this.prePageNo = 1;
		}
		
		//计算下一页页码
		if(this.totalPages >= 1){
			if(this.currPageNo < this.totalPages){
				this.nextPageNo = this.currPageNo +1;
			}else{
				this.nextPageNo = this.totalPages;
			}
		}else{
			this.nextPageNo = 1;
		}
		
		//计算第一页页码
		this.firstPageNo = 1;
		
		//计算末页页码
		this.endPageNo = this.totalPages;
		
		//计算当前页起始条目序号
		if(this.currPageNo <= 1){
			this.startItemNo = 0;
		}else{
			this.startItemNo = this.currPageNo * this.pageSize-1;
		}
		
		//计算当前页结束条目序号
		if(this.currPageNo == this.totalPages){
			int moTmp = this.totalItem%this.pageSize;
			this.endItemNo = this.startItemNo + moTmp;
		}else{
			this.endItemNo = this.startItemNo+this.pageSize;
		}
		
		//计算当前页是否是首页
		if(this.currPageNo == 1){
			this.isFirstPageNo = true;
		}else{
			this.isFirstPageNo = false;
		}
		
		//计算当前页是否是末页
		if(this.currPageNo == this.totalPages){
			this.isEndPageNo = true;
		}else{
			this.isEndPageNo = false;
		}
		
		//计算是否有上一页
		if(this.totalPages>1){
			if(this.currPageNo == 1){
				this.isHasPrePageNo = false;
			}else{
				this.isHasPrePageNo = true;
			}
		}else{
			this.isHasPrePageNo = false;
		}
		
		//计算是否有下一页
		if(this.totalPages>1){
			if(this.currPageNo == this.totalPages){
				this.isHasNextPageNo = false;
			}else{
				this.isHasNextPageNo = true;
			}
		}else{
			this.isHasNextPageNo = false;
		}
		
	}

	public int getTotalItem() {
		return totalItem;
	}

	public void setTotalItem(int totalItem) {
		this.totalItem = totalItem;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrPageNo() {
		return currPageNo;
	}

	public void setCurrPageNo(int currPageNo) {
		this.currPageNo = currPageNo;
	}

	public int getPrePageNo() {
		return prePageNo;
	}

	public void setPrePageNo(int prePageNo) {
		this.prePageNo = prePageNo;
	}

	public int getNextPageNo() {
		return nextPageNo;
	}

	public void setNextPageNo(int nextPageNo) {
		this.nextPageNo = nextPageNo;
	}

	public int getFirstPageNo() {
		return firstPageNo;
	}

	public void setFirstPageNo(int firstPageNo) {
		this.firstPageNo = firstPageNo;
	}

	public int getEndPageNo() {
		return endPageNo;
	}

	public void setEndPageNo(int endPageNo) {
		this.endPageNo = endPageNo;
	}

	public int getStartItemNo() {
		return startItemNo;
	}

	public void setStartItemNo(int startItemNo) {
		this.startItemNo = startItemNo;
	}

	public int getEndItemNo() {
		return endItemNo;
	}

	public void setEndItemNo(int endItemNo) {
		this.endItemNo = endItemNo;
	}

	public boolean isFirstPageNo() {
		return isFirstPageNo;
	}

	public void setFirstPageNo(boolean isFirstPageNo) {
		this.isFirstPageNo = isFirstPageNo;
	}

	public boolean isEndPageNo() {
		return isEndPageNo;
	}

	public void setEndPageNo(boolean isEndPageNo) {
		this.isEndPageNo = isEndPageNo;
	}

	public boolean isHasPrePageNo() {
		return isHasPrePageNo;
	}

	public void setHasPrePageNo(boolean isHasPrePageNo) {
		this.isHasPrePageNo = isHasPrePageNo;
	}

	public boolean isHasNextPageNo() {
		return isHasNextPageNo;
	}

	public void setHasNextPageNo(boolean isHasNextPageNo) {
		this.isHasNextPageNo = isHasNextPageNo;
	}
	
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy