⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page.java

📁 使用spring ,hibernate 框架的稽查管理系统
💻 JAVA
字号:
package com.je.ims.util;

import java.io.Serializable;
import java.util.*; 
import org.springframework.orm.hibernate.support.HibernateDaoSupport;

import com.je.ims.dao.*;


public class Page  implements Serializable {
	
    public static final int  DEFAULT_PAGE_SIZE =5; 
    public static final int  DEFAULT_Count=5; 

    protected int myPageSize = DEFAULT_PAGE_SIZE; 
    protected int myCount = DEFAULT_Count; 

    protected int start; 
    protected int avaCount,totalSize; 
    protected int currentPageno; 
    protected int totalPageCount; 
    int index;
   
    
   
    /* 
     * 分页数据初始方法,由子类调用 
     * @param start 本页数据在数据库中的起始位置 
     * @param avaCount 本页包含的数据条数 
     * @param totalSize 数据库中总记录条数 
     * @param pageSize 本页容量 
     * @param currentPageno  当前页数
     * @param totalPageCount 总共的页数
     * @param index  下标,如果index增一,则页数增加count页
     * 
     */ 
    public Page(){ 
        this.init(1,1,0,DEFAULT_PAGE_SIZE,DEFAULT_Count); 
    } 
    public Page(int currentPageno,int index, int totalSize){ 
    	this.init(currentPageno,index, totalSize,DEFAULT_PAGE_SIZE,DEFAULT_Count); 
    } 
    public Page(int currentPageno,int index, int totalSize,int pageSize,int count){ 
    	
        this.init(currentPageno,index, totalSize,pageSize,count); 
    }   
    protected void init(int currentPageno,int index, int totalSize,
    		int pageSize,int count){ 
     
         this.currentPageno =currentPageno; 
         this.index=index;
         this.totalSize = totalSize; 
         this.myPageSize = pageSize;
         this.myCount=count;
         //this.data=data;
      
         this.start = (currentPageno-1)* myPageSize;
         this.totalPageCount = (totalSize + myPageSize -1) / myPageSize;
         
         if(currentPageno<totalPageCount)
        	 avaCount=pageSize;
         else
        	 avaCount=totalSize-(currentPageno-1)*myPageSize;
         
    }

	public int getPageSize(){ 
         return this.myPageSize; 
       } 
      
	public int getCount(){ 
        return this.myCount; 
      } 
	
      public int getStart(){ 
          return start; 
      } 
      
      public int getEnd(){ 
          int end = this.getStart() + this.getAvaCount() -1; 
          if (end<0) { 
              end = 0; 
          } 
          return end; 
      } 
      /** 
       * 取本页包含的记录数 
       * @return 本页包含的记录数 
       */ 
      public int getAvaCount() { 
          return avaCount; 
      } 
      /** 
       * 取数据库中包含的总记录数 
       * @return 数据库中包含的总记录数 
       */ 
      public int getTotalSize() { 
          return this.totalSize; 
      } 

      /** 
       * 取当前页码 
       * @return 当前页码 
       */ 
      public int getCurrentPageNo(){ 
          return  this.currentPageno; 
      } 

      /** 
       * 取总页码 
       * @return 总页码 
       */ 
      public int getTotalPageCount(){ 
          return this.totalPageCount; 
      } 

     
    public int[] getArray(){
	   
	   int size = 0;
	   int indexCount=(totalPageCount+myCount-1)/myCount;//index的最大值
	   int pageStart=(index-1)*myCount+1;
	   
	   if(index<indexCount){
		   size=myPageSize;
	   }
	   else if(index==indexCount){
		   size=totalPageCount-pageStart+1;
	   }
	   else {
		   return null;
	   }
	   
	   int array[]=new int[size];
	   for(int i=0;i<size;i++){
		   array[i]=pageStart+i;
	   }
	   return array;
	   
  }
    public Object[] getObj(CommonDAO dao) {
    	Object[] obj;
	       if(currentPageno<totalPageCount){
	    	   avaCount=myPageSize;
	    	   obj= new Object[avaCount];
	    	   obj = dao.getCount(start,avaCount);
	    	   
	    	   return obj;
	       }
	       
	       else if(currentPageno==totalPageCount){
	    	   
		       int avaCount=totalSize-(currentPageno-1)*myPageSize;
		       obj = new Object[avaCount];
		       obj=dao.getCount(start,avaCount);
		       return obj;
	       }
	       return null;
    }
    public Object[] getObj(CommonDAO dao,List l) {
    	Object[] obj;
	       if(currentPageno<totalPageCount){
	    	   avaCount=myPageSize;
	    	   obj= new Object[avaCount];
	    	   obj = dao.getCount(start,avaCount,l);
	    	   
	    	   return obj;
	       }
	       
	       else if(currentPageno==totalPageCount){
	    	   
		       int avaCount=totalSize-(currentPageno-1)*myPageSize;
		       obj = new Object[avaCount];
		       obj=dao.getCount(start,avaCount,l);
		       return obj;
	       }
	       return null;
    }
    
    public Object[] getObj(List list) {
    	
  	   Object[] obj;
  	   
 	       if(currentPageno<totalPageCount){
 	    	   avaCount=myPageSize;
 	    	   obj = new Object[avaCount];
 	    	   for(int i=0;i<avaCount;i++){
 	    		   obj[i]=list.get(i+start);
 	    	   }
 	    	   return obj;
 	       }
 	       else if(currentPageno==totalPageCount){
 	    	   
 		       int avaCount=totalSize-(currentPageno-1)*myPageSize;
 		       obj = new Object[avaCount];
 		       for(int i=0;i<avaCount;i++){
 	    		   obj[i]=list.get(i+start);
 	    	   }
 	    	   return obj;
 	       }
 	       
 	       return null;
 	}
    public int getIndexCount(){
    	int indexCount=(totalPageCount+myCount-1)/myCount;
    	return indexCount;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -