用于实现基本的分页操作工具类

package com.fww.practice.page;
 
import java.util.List;
 
/**
  * 类功能说明 :作为分页使用
  * @Description:
  * @author FWW
  * @date 2014年7月2日 下午5:45:49
  */
public class Page {
 
     /**
      * 总的记录数
      */
     private int rowCounts;
     
     /**
      * 每一页可以显示的记录数
      */
     private int pageSize;
     
     /**
      * 当前的页面
      */
     private int currentPage;
     
     /**
      * 开始的记录数
      */
     private int startRow;
     
     /**
      * 记录数折换成导航显示的个数
      */
     private int navCounts;
     
     /**
      * 第一页
      */
     private int firstPage;
     
     /**
      * 最后一页
      */
     private int lastPage;
     
     /**
      * 页面显示的导航起始位置
      */
     private int beginNav;
     
     /**
      * 页面显示的导航结束的位置
      */
     private int endNav;
     
     /**
      * 上一页
      */
     private int prePage;
     
     /**
      * 下一页
      */
     private int nextPage;
     
     /**
      * 固定的导航数
      */
     private int navNum;
     
     /**
      * 获取的记录集合
      */
     @SuppressWarnings ( "rawtypes" )
     private List pageDatas;
 
     public int getRowCounts() {
         return rowCounts;
     }
 
     public void setRowCounts( int rowCounts) {
         this .rowCounts = rowCounts;
     }
 
     public int getPageSize() {
         return pageSize;
     }
 
     public void setPageSize( int pageSize) {
         this .pageSize = pageSize;
     }
 
     public int getCurrentPage() {
         return currentPage;
     }
 
     public void setCurrentPage( int currentPage) {
         this .currentPage = currentPage;
     }
 
     public int getStartRow() {
         return startRow;
     }
 
     public void setStartRow( int startRow) {
         this .startRow = startRow;
     }
 
     public int getNavCounts() {
         return navCounts;
     }
 
     public void setNavCounts( int navCounts) {
         this .navCounts = navCounts;
     }
 
     public int getFirstPage() {
         return firstPage;
     }
 
     public void setFirstPage( int firstPage) {
         this .firstPage = firstPage;
     }
 
     public int getLastPage() {
         return lastPage;
     }
 
     public void setLastPage( int lastPage) {
         this .lastPage = lastPage;
     }
 
     public int getBeginNav() {
         return beginNav;
     }
 
     public void setBeginNav( int beginNav) {
         this .beginNav = beginNav;
     }
 
     public int getEndNav() {
         return endNav;
     }
 
     public void setEndNav( int endNav) {
         this .endNav = endNav;
     }
 
     public int getPrePage() {
         return prePage;
     }
 
     public void setPrePage( int prePage) {
         this .prePage = prePage;
     }
 
     public int getNextPage() {
         return nextPage;
     }
 
     public void setNextPage( int nextPage) {
         this .nextPage = nextPage;
     }
 
     public int getNavNum() {
         return navNum;
     }
 
     public void setNavNum( int navNum) {
         this .navNum = navNum;
     }
 
     @SuppressWarnings ( "rawtypes" )
     public List getPageDatas() {
         return pageDatas;
     }
 
     @SuppressWarnings ( "rawtypes" )
     public void setPageDatas(List pageDatas) {
         this .pageDatas = pageDatas;
     }
 
     /**
      * @param rowCounts 总得记录实体个数
      * @param pageSize 页面可以显示的实体个数
      * @param currentPage 当前页码
      * @param navNum 固定显示的最多导航数
      */
     public Page( int rowCounts, int pageSize, int currentPage, int navNum) {
         //记录实体总数
         this .rowCounts = rowCounts;
         //一页可以显示的记录实体的个数
         this .pageSize = pageSize;
         //第一页
         this .firstPage = 1 ;
         //固定的导航数
         this .navNum = navNum;
 
         //运用总的实体数折算出来的可以显示的导航数
         this .navCounts = ( int )(rowCounts+pageSize- 1 )/pageSize;
         //当前的页面: 首页和当前页中的最大的
         this .currentPage = Math.max(currentPage, firstPage);
         //当前的页面: 折算出来的可以显示的最大页数和当前页中的最小的一个
         this .currentPage = Math.min(currentPage, this .navCounts);
         
         //起始显示的实体在数据库中的位置
         this .startRow = Math.max( 0 , ( this .currentPage- 1 )*pageSize);
         //尾页
         this .lastPage = this .navCounts;
         
         //上一页
         this .prePage  = Math.max( this .currentPage- 1 , firstPage);
         //下一页
         this .nextPage = Math.min( this .currentPage+ 1 , lastPage);
         //起始的导航数
         this .beginNav = Math.max( this .firstPage, this .currentPage- this .navNum/ 2 );
         //最后的一个导航数
         this .endNav = Math.min( this .lastPage, this .beginNav+ this .navNum- 1 );
         
         if (lastPage - beginNav<(navNum- 1 )){
             this .beginNav = Math.max( this .firstPage, this .endNav- this .navNum+ 1 );
         }
     }
 
     public Page() {
         
     }
     
     
     
     
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值