配置分页

为了方便以后的复用,可以将分页写成一个工具类。
工具类中需要以下几个属性:

	private int nowPage=1; //起始页数,默认为1
	private int zongPage; //总条数%size==0?总条数/size:总条数/size+1
	private int size = 5; //每页条数 提前规定好 5
	private int zongCount; //总条数 select count(*) from 表名
	private int beginNumber; //起始条数 (当前页-1)*size
	private int number[]  = new int[5];   //显示页数  1 2 3  4 5 

public int[] getNumber() {
		// 开始分析
		zongPage=this.getZongPage();// 获取总共多少页
		if(zongPage<=5){
			for (int i = 0; i < zongPage; i++) {
				number[i]=i+1;
			}
		}else{
			// nowPage+2< zongPage  nowPage-2>=1
			if(this.getNowPage()+2<=this.getZongPage() && this.getNowPage()-2>=0){
				number[0]=this.getNowPage()-2;
				number[1]=this.getNowPage()-1;
				number[2]=this.getNowPage();
				number[3]=this.getNowPage()+1;
				number[4]=this.getNowPage()+2;
			}else{
				if(this.getNowPage()+2>this.getZongPage()){
					number[0]=this.getZongPage()-4;
					number[1]=this.getZongPage()-3;
					number[2]=this.getZongPage()-2;
					number[3]=this.getZongPage()-1;
					number[4]=this.getZongPage();
				}
				
				if(this.getNowPage()-2<0){
					for (int i = 0; i < 5; i++) {
						number[i]=i+1;
					}
				}
			}
		}
		return number;
	}

	
	public int getBeginNumber() {
		return (this.getNowPage()-1)*size;
	}
	
	public int getNowPage() {
		return nowPage;
	}
	public void setNowPage(int nowPage) {
		this.nowPage = nowPage;
	}
	public int getZongPage() {
		return this.zongCount%size==0?this.zongCount/size:this.zongCount/size+1;
	}
	public void setZongPage(int zongPage) {
		this.zongPage = zongPage;
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public int getZongCount() {
		return zongCount;
	}
	public void setZongCount(int zongCount) {
		this.zongCount = zongCount;
	}
	

SQL语句:select * from 表名 limit page.getBeginNumber() , page.getSize()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lemon20120331

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值