?? mypagination.java
字號:
package com.wy.tool;
import java.util.ArrayList;
import java.util.List;
public class MyPagination {
public List<Object> list=null;
private int recordCount=0;
private int pagesize=0;
private int maxPage=0;
//初始化分頁信息
public List getInitPage(List list,int Page,int pagesize){
List<Object> newList=new ArrayList<Object>();
this.list=list;
recordCount=list.size();
this.pagesize=pagesize;
this.maxPage=getMaxPage();
try{
for(int i=(Page-1)*pagesize;i<=Page*pagesize-1;i++){
try{
if(i>=recordCount){break;}
}catch(Exception e){}
newList.add((Object)list.get(i));
}
}catch(Exception e){
e.printStackTrace();
}
return newList;
}
//獲取指定頁的數據
public List<Object> getAppointPage(int Page){
List<Object> newList=new ArrayList<Object>();
try{
for(int i=(Page-1)*pagesize;i<=Page*pagesize-1;i++){
try{
if(i>=recordCount){break;}
}catch(Exception e){}
newList.add((Object)list.get(i));
}
}catch(Exception e){
e.printStackTrace();
}
return newList;
}
//獲取最大記錄數
public int getMaxPage(){
int maxPage=(recordCount%pagesize==0)?(recordCount/pagesize):(recordCount/pagesize+1);
return maxPage;
}
//獲取總記錄數
public int getRecordSize(){
return recordCount;
}
//獲取當前頁數
public int getPage(String str){
System.out.println("STR:"+str+"&&&&"+recordCount);
if(str==null){
str="0";
}
int Page=Integer.parseInt(str);
if(Page<1){
Page=1;
}else{
if(((Page-1)*pagesize+1)>recordCount){
Page=maxPage;
}
}
return Page;
}
public String printCtrl(int Page){
String strHtml="<table width='370' border='0' cellspacing='0' cellpadding='0'><tr> <td height='24' align='right'>當前頁數:["+Page+"/"+maxPage+"] ";
try{
if(Page>1){
strHtml=strHtml+"<a href='?&Page=1'>第一頁</a> ";
strHtml=strHtml+" <a href='?Page="+(Page-1)+"'>上一頁</a>";
}
if(Page<maxPage){
strHtml=strHtml+" <a href='?Page="+(Page+1)+"'>下一頁</a> <a href='?Page="+maxPage+"'>最后一頁 </a>";
}
strHtml=strHtml+"</td> </tr> </table>";
}catch(Exception e){
e.printStackTrace();
}
return strHtml;
}
public String printCtrl(int Page,String method){
method=method+"&";
String strHtml="<table width='370' border='0' cellspacing='0' cellpadding='0'><tr> <td height='24' align='right'>當前頁數:["+Page+"/"+maxPage+"] ";
try{
if(Page>1){
strHtml=strHtml+"<a href='?"+method+"&Page=1'>第一頁</a> ";
strHtml=strHtml+" <a href='?"+method+"Page="+(Page-1)+"'>上一頁</a>";
}
if(Page<maxPage){
strHtml=strHtml+" <a href='?"+method+"Page="+(Page+1)+"'>下一頁</a> <a href='?"+method+"Page="+maxPage+"'>最后一頁 </a>";
}
strHtml=strHtml+"</td> </tr> </table>";
}catch(Exception e){
e.printStackTrace();
}
return strHtml;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -