java中的分页

分页类
import java.util.ArrayList;
import java.util.List;

public class Pager {

// 页面大小
protected int[] pageSizeList = { 10, 25, 50, 100, 200, 300, 500 };

// 一页显示的记录数
protected int pageSize = Constants.pageSize;

// 当前页码
protected int pageNo = Constants.pageNo;

// 记录总数
protected int rowCount = 0;

// 总页数
protected int pageCount = 1;

// 起始行数
protected int startIndex = 1;

// 结束行数
protected int endIndex = 1;

protected int firstPageNo = 1;
protected int prePageNo = 1;
protected int nextPageNo = 1;
protected int lastPageNo = 1;

// 结果集存放List
protected List resultList;

public Pager(int pageSize, int pageNo, int rowCount, List resultList) {
this.pageSize = pageSize;
this.pageNo = pageNo;
this.rowCount = rowCount;
this.resultList = resultList;

if (rowCount % pageSize == 0) {
this.pageCount = rowCount / pageSize;
} else {
this.pageCount = rowCount / pageSize + 1;
}
this.startIndex = pageSize * (pageNo - 1);
this.endIndex = this.startIndex + resultList.size();

this.lastPageNo = this.pageCount;
if (this.pageNo > 1) this.prePageNo = this.pageNo -1;
if (this.pageNo == this.lastPageNo){
this.nextPageNo = this.lastPageNo;
} else {
this.nextPageNo = this.pageNo + 1;
}
}

public Object[] getPageSizeIndexs() {
List result = new ArrayList(pageSizeList.length);
for (int i = 0; i < pageSizeList.length; i++) {
result.add(String.valueOf(pageSizeList[i]));
}
Object[] indexs = (result.toArray());
return indexs;
}

public Object[] getPageNoIndexs() {
List result = new ArrayList(pageCount);
for (int i = 0; i < pageCount; i++) {
result.add(String.valueOf(i + 1));
}
Object[] indexs = (result.toArray());
return indexs;
}}


数据库的查询

String sql ="select * from 表名 where 条 件 order by id " +
"limit " + (pageNo - 1) * pageSize + ", " + pageSize;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值