Mybatis+mysql动态分页查询数据案例——分页工具类(Page.java)

package cn.bdqn.mhouse.util;

import java.util.ArrayList;
import java.util.List;

import cn.bdqn.mhouse.entity.House;

/**
 * 
*    
* 项目名称:mhouse   
* 类名称:Page   
* 类描述:   分页的工具类
* 创建人:Mu Xiongxiong  
* 创建时间:2017-3-17 下午1:04:02   
* 修改人:Mu Xiongxiong   
* 修改时间:2017-3-17 下午1:04:02   
* 修改备注:   
* @version    
*
 */
public class Page {
	private int pageSize=3;            //页大小
	private int pageIndex=0;           //当前页号
	private int totalPageCount=0;      //总页数
	private int record=0;              //记录总数
	private Integer nextPage;          //下一页
	private Integer prePage;           //上一页
	private List<House> houseList=new ArrayList<House>();     //房屋信息的集合
	
	

	/**    
	 * @author Mu Xiongxiong       
	 * @created 2017-3-17 下午10:04:41 
	 * @return type 
	 */
	
	public List<House> getHouseList() {
		return houseList;
	}

	/**     
	 * @author Mu Xiongxiong      
	 * @created 2017-3-17 下午10:04:41         
	 * @param houseList   
	 */
	public void setHouseList(List<House> houseList) {
		this.houseList = houseList;
	}

	//得到开始记录数
	public int getSartRow(){
		return (pageIndex-1)*pageSize;
	}
	
	//得到结束记录数
	public int getEndRow(){
		return pageSize;
	}

	public int getPageSize() {
		return pageSize;
	}

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

	public int getPageIndex() {
		return pageIndex;
	}

	//得到当前页
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
		//下一页
		setNextPage();
		//上一页
		setPrePage();
	}

	public int getTotalPageCount() {
		return totalPageCount;
	}

	//总页数
	public void setTotalPageCount() {
		int totalP = record % getPageSize() == 0 ? record / getPageSize() :
			record/ getPageSize() + 1;
		this.totalPageCount = totalP;
	}

	public int getRecord() {
		return record;
	}
	
	//总记录数
	public void setRecord(int record) {
		this.record = record;
		//设置总页数
		setTotalPageCount();
	}

	public Integer getNextPage() {
		return nextPage;
	}

	//设置下一页
	public void setNextPage() {
		this.nextPage = this.pageIndex+1;
		
	}

	public Integer getPrePage() {
		return prePage;
	}

	//设置上一页
	public void setPrePage() {
		this.prePage =this.pageIndex-1;
		if(this.prePage<1){
			this.prePage=1;
		}
	}
	
	

}

posted @ 2017-03-18 22:46  穆雄雄  阅读(217)  评论(0编辑  收藏  举报