核心代码之分页

public class PageResult {

 //总记录数
 private long totalCount;
 //当前页号
 private int pageNo;
 //总页数
 private int totalPageCount;
 //页大小
 private int pageSize;
 //列表记录
 private List items;
 
 //计算总页数
 public PageResult(long totalCount, int pageNo, int pageSize, List items) {
  this.items = items==null?new ArrayList():items; //如果items是空的话 就new一个否者直接给他值,防止空指针异常
  this.totalCount = totalCount;
  this.pageSize = pageSize;
  if(totalCount != 0){ // 总记录数 非 0 时
   //计算总页数 
   int tem = (int)totalCount/pageSize;  //总页数 = 总记录数  除以  页大小
   this.totalPageCount = (totalCount%pageSize==0)?tem:(tem+1); //如果总记录数  % 页大小 == 0则 赋值页数 , 否则+1,因为有多余的记录
   this.pageNo = pageNo;
  } else {
   this.pageNo = 0;
  }
 }
 
 public long getTotalCount() {
  return totalCount;
 }
 public void setTotalCount(long totalCount) {
  this.totalCount = totalCount;
 }
 public int getPageNo() {
  return pageNo;
 }
 public void setPageNo(int pageNo) {
  this.pageNo = pageNo;
 }
 public int getTotalPageCount() {
  return totalPageCount;
 }
 public void setTotalPageCount(int totalPageCount) {
  this.totalPageCount = totalPageCount;
 }
 public int getPageSize() {
  return pageSize;
 }
 public void setPageSize(int pageSize) {
  this.pageSize = pageSize;
 }
 public List getItems() {
  return items;
 }
 public void setItems(List items) {
  this.items = items;
 }
 
}

转载于:https://www.cnblogs.com/zzzz97/p/6748721.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值