分页的工具类
来源:互联网 发布:mac chrome收费? 编辑:程序博客网 时间:2024/05/21 01:32
package cn.util;
/**
* 分页的工具类
*
* 总共36条记录,每页10条,问:共几页?4页 当前页 起始条数 1 1 2 11 3 21 4 31 起始条数如何算出来的? (页数 - 1)*10 +
* 1
*
* ~生成读写器,做容错处理
* @author sun
*
*/
public class PageInfoUtil
{
/* 每页多少条 */
private int pageSize = 10;
/* 当前页 */
private int currentPage;
/* 总条数 */
private int totalRecord;
/* 上一页 */
private int prePage;
/* 下一页 */
private int nextPage;
/* 总页数 */
private int totalPage;
/* 当前记录数(每页的起始条数) */
private int currRecord;
public int getPageSize()
{
return pageSize;
}
public void setPageSize(int pageSize)
{
this.pageSize = pageSize;
}
public int getCurrentPage()
{
if(this.currentPage < 1)
{
this.currentPage = 1;
}
if(this.getTotalPage() > 0 && this.currentPage > this.getTotalPage())
{
this.currentPage = this.getTotalPage() ;
}
return currentPage;
}
public void setCurrentPage(int currentPage)
{
this.currentPage = currentPage;
}
public int getTotalRecord()
{
return totalRecord;
}
public void setTotalRecord(int totalRecord)
{
this.totalRecord = totalRecord;
}
public int getPrePage()
{
this.prePage = this.currentPage - 1 ;
if(this.prePage < 1 )
{
this.prePage = 1 ;
}
return prePage;
}
public int getNextPage()
{
this.nextPage = this.currentPage + 1 ;
if(this.nextPage > this.getTotalPage())
{
this.nextPage = this.getTotalPage() ;
}
return nextPage;
}
public int getTotalPage()
{
/*
* 总页数
*
* 总条数 / 10 + 1
*
* 总条数如果是30条,每页10条,问多少页?
* */
this.totalPage = this.totalRecord / this.pageSize ;
if(this.totalRecord % this.pageSize != 0 )
{
this.totalPage = this.totalRecord / this.pageSize + 1;
}
return totalPage;
}
public int getCurrRecord()
{
/* 当前页的起始条数如何算呢?
* 不能加+1,
* Mysql的limit?,?是从0开始的.
* */
this.currRecord = (this.getCurrentPage() - 1 ) * this.getPageSize() ;
return currRecord;
}
}
/**
* 分页的工具类
*
* 总共36条记录,每页10条,问:共几页?4页 当前页 起始条数 1 1 2 11 3 21 4 31 起始条数如何算出来的? (页数 - 1)*10 +
* 1
*
* ~生成读写器,做容错处理
* @author sun
*
*/
public class PageInfoUtil
{
/* 每页多少条 */
private int pageSize = 10;
/* 当前页 */
private int currentPage;
/* 总条数 */
private int totalRecord;
/* 上一页 */
private int prePage;
/* 下一页 */
private int nextPage;
/* 总页数 */
private int totalPage;
/* 当前记录数(每页的起始条数) */
private int currRecord;
public int getPageSize()
{
return pageSize;
}
public void setPageSize(int pageSize)
{
this.pageSize = pageSize;
}
public int getCurrentPage()
{
if(this.currentPage < 1)
{
this.currentPage = 1;
}
if(this.getTotalPage() > 0 && this.currentPage > this.getTotalPage())
{
this.currentPage = this.getTotalPage() ;
}
return currentPage;
}
public void setCurrentPage(int currentPage)
{
this.currentPage = currentPage;
}
public int getTotalRecord()
{
return totalRecord;
}
public void setTotalRecord(int totalRecord)
{
this.totalRecord = totalRecord;
}
public int getPrePage()
{
this.prePage = this.currentPage - 1 ;
if(this.prePage < 1 )
{
this.prePage = 1 ;
}
return prePage;
}
public int getNextPage()
{
this.nextPage = this.currentPage + 1 ;
if(this.nextPage > this.getTotalPage())
{
this.nextPage = this.getTotalPage() ;
}
return nextPage;
}
public int getTotalPage()
{
/*
* 总页数
*
* 总条数 / 10 + 1
*
* 总条数如果是30条,每页10条,问多少页?
* */
this.totalPage = this.totalRecord / this.pageSize ;
if(this.totalRecord % this.pageSize != 0 )
{
this.totalPage = this.totalRecord / this.pageSize + 1;
}
return totalPage;
}
public int getCurrRecord()
{
/* 当前页的起始条数如何算呢?
* 不能加+1,
* Mysql的limit?,?是从0开始的.
* */
this.currRecord = (this.getCurrentPage() - 1 ) * this.getPageSize() ;
return currRecord;
}
}
阅读全文
0 0
- 分页的工具类
- 通用的分页工具类
- 分页的封装工具类
- MVC的分页实体类与分页计算工具类
- Hibernate实现分页的工具类
- java的web开发分页工具类
- Android分页工具类的实现
- 封装一分页的工具类
- 分页显示数据的java工具类
- 简单的分页显示工具类
- 分页工具类
- 分页工具类
- 分页工具类
- 分页工具类
- java分页工具类
- 分页通用工具类
- hibernate分页工具类
- 分页工具类
- Python 元组(tuple)
- 对外接口如何保证安全
- 设计模式之单例模式Singleton
- iOS百思不得姐、ARKit、旋转动画、立体相册源码等
- 大前端时代来临,我们何去何从?
- 分页的工具类
- Ajax -- $.get() 方法解析 JSON 数据
- 精华【分布式、微服务、云架构dubbo+zookeeper+springmvc+mybatis+shiro+redis】分布式大型互联网企业架构!
- 欧拉函数辱骂你 2333333333
- 【poj 2104】K-th Number【整体二分+树状数组】
- c++ string char* char[]之间的转化
- Eclipse项目转移到IntelliJ IDEA
- 2017最新PHP经典面试题目汇总(上篇)
- 将excel导入sql数据库 id自增长