`
yangjia312
  • 浏览: 8779 次
  • 性别: Icon_minigender_2
  • 来自: 武汉
社区版块
存档分类
最新评论

分页显示

    博客分类:
  • JAVA
 
阅读更多
package com.yangjia.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CutList {
private int pagesize=10; //页面显示记录个数
private int pagecount;//统计页面总数
private int page=1; //当前页数
private int count; //统计记录集长度
private List listObject;//存储记录集
private int m;
private String strs;
private String url;
//设置统计页面总数
public void setPageCount(){
if((this.count%this.pagesize)==0 ){
this.pagecount=this.count / this.pagesize;
}
else{
this.pagecount=(this.count / this.pagesize)+1;
}
}
public void setMM(){
this.m=this.pagesize;
}
//设置记录集
public void setListObjct(List listObjct,int curPage) {

this.listObject = listObjct;
setCount();
setPageCount();
setMM();
setPage(curPage);
}
//获得记录集长度
public void setCount(){
this.count=listObject.size();
}
//设置页显示的个数
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
//获得当前页
public int getPage() {
return this.page;
}
//设置当前页面
public void setPage(int page) {
if(page<1){
this.page =1;
return;
}
if(page>this.pagecount){
this.page=this.pagecount;
return;
}
this.page=page;
}

public int getCount() {
return count;
}

public int getM() {
return m;
}

public int getPagecount() {
return pagecount;
}

public void setUrl(String url) {
this.url = url;
}
public String getTail() {
setDecTail();
return strs;
}

//获得分页列表
public List getFengYe(){
int i=0;
List fengYeList=new ArrayList();
List curList=null;
i=(this.page-1)*this.m+1;
//分页显示
curList=absoluteList(i);//移动到当前页的第一个节点

Iterator it=curList.iterator();
while(it.hasNext()&&i<=this.m+(this.page-1)*this.m){
fengYeList.add(it.next());
i++;
}

return fengYeList;
}

//定位分页列表
private List absoluteList(int abs ){
int cur=1;
List absolute=new ArrayList();
Iterator it=this.listObject.iterator();
while(it.hasNext()){
//String book=(Books)it.next();
//System.out.print("s"+it.next());
Object object = it.next();
if(abs<=cur){
absolute.add( object );
}
cur++;
}
return absolute;
}

//获得分页尾部
public void setDecTail(){
String str=null;
String str_selected=null;

int prepage;
int nextpage;
int gotopage=page;
if(page-1<1){
prepage=1;
}else{
prepage=page-1;
}

if(page+1>pagecount){
nextpage=pagecount;
}else{
nextpage=page+1;
}

str="<table width='95%' border='0' bordercolor='000000'><tr>";
str=str+"<td width='15%' align='center'><font color= >"+gotopage+"页/共"+pagecount+"页</font> </td>";
str=str+"<td width='8%' height='37' align='center'><a href="+url+"&gotopage=1><font color= >首页</font></a></td>";
str=str+"<td width='10%' align='center'><a href="+url+"&gotopage="+prepage+"><font color= >上一页</font></a></td>";
str=str+"<td width='10%' align='center'><a href="+url+"&gotopage="+nextpage+"><font color= >下一页</font></a></td>";
str=str+"<td width='8%' align='center'><a href="+url+"&gotopage="+pagecount+"><font color= >末页</font></a></td>";

str=str+"<td width='25%' align='center'><font color= >转到:</font><select name='yy' onChange='location.href=this.value;'>";

for( int ti=1 ;ti<=pagecount;ti++ ){
if (gotopage==ti){
str_selected="selected";
}else{
str_selected="";
}
str=str+"<option value='"+url+"&gotopage="+ti+"' "+str_selected+">"+ti+"</option>";
}
str=str+"</select><font color= >页</font></td>";
    str=str+"<td width='6%' align='center'></td><td><font  color=>共<"+count+">条记录</font></td></tr></table>";
this.strs=str;
}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics