java如何分页_java——分页

package com.bjsxt.pojo;

import java.util.List;

public class Pagination {

// 当前页数

private int page;

// 每页显示多少条数据

private int size;

// 总记录数

private int totalCount;

// 总页数

private int totalPage;

// 每次查询的起始位置

private int start;

// 是否有上一页

private boolean hasPrev;

// 上一页

private int prevPage;

// 是否有下一页

private boolean hasNext;

// 下一页

private int nextPage;

// 首页

private int firstPage;

// 尾页

private int lastPage;

// 分页导航块的个数

private int navCount;

// 导航的起始位置

private int navBegin;

// 导航的结束位置

private int navEnd;

// 查询结果对应的list集合

private List list;

public Pagination(String page, String size, int totalCount) {

// 当前页数

this.page = null != page ? Integer.parseInt(page) : 1;

// 每页显示多少条数据

this.size = null != size ? Integer.parseInt(size) : 10;

// 总记录数

this.totalCount = totalCount;

// 总页数

this.totalPage = (int) Math.ceil(this.totalCount * 1.0 / this.size);

// 当前页数不能大于总页数

if(this.page > this.totalPage && this.totalPage > 0) {

this.page = this.totalPage;

}

// 每次查询的起始位置

this.start = (this.page - 1) * this.size;

if (this.page > 1) {

// 是否有上一页

this.hasPrev = true;

// 上一页

this.prevPage = this.page - 1;

}

if (this.page < this.totalPage) {

// 是否有下一页

this.hasNext = true;

// 下一页

this.nextPage = this.page + 1;

}

// 首页

this.firstPage = 1;

// 尾页

this.lastPage = this.totalPage;

// 分页导航块的个数

this.navCount = 10;

// 导航的起始位置

// if (this.page > this.totalPage - this.navCount) {

// this.navBegin = this.totalPage - this.navCount + 1;

// } else {

this.navBegin = this.page - this.navCount / 2 < 1 ? 1 : this.page - this.navCount / 2;

// }

// 导航的结束位置

this.navEnd = this.navBegin + this.navCount - 1 > this.totalPage ? this.totalPage

: this.navBegin + this.navCount - 1;

}

// 省略getter和setter方法

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值