您的位置:jsp学习站首页 >> JSP类 >> JSP高级 >> 实现jsp页面得分页显示功能方案

实现jsp页面得分页显示功能方案 (1)

[ 来源:互网络 | 更新日期:2007-09-30 19:48:46 | 浏览次数:10772]
简介:util

//接口的定义:

public interface ContactBean {

 public int getAvailableCount()throws Exception;

 public int getAvailableCount(int id)throws Exception;

 public PageBean listData(String page)throws Exception ;

 public PageBean listData(String page,int id)throws Exception ;

 public Collection getResult()throws Exception;

}

//pageBean的定义:

public class PageBean {

 public int curPage;//当前的页值。

 public int maxPage;//最大的页数。

 public int maxRowCount;//最大的行数。

 public static int rowsPerPage=10; //控制分页的行数。

 public java.util.Collection data; //所要显示的数据的集合。

 public PageBean() {

 }

 public void countMaxPage(){

  if(this.maxRowCount%this.rowsPerPage==0){

   this.maxPage=this.maxRowCount/this.rowsPerPage;

  }else{

   this.maxPage=this.maxRowCount/this.rowsPerPage+1;

  }

 }

 public Collection getResult(){

  return this.data;

 }

 public PageBean(ContactAdapter bean,int id)throws Exception{

  this.maxRowCount=bean.getAvailableCount(id);

  if(maxRowCount==0)

   maxRowCount=1;

  System.out.println(maxRowCount);

  this.data=bean.getResult();

  this.countMaxPage();

 }

 public PageBean(ContactAdapter bean)throws Exception{

  this.maxRowCount=bean.getAvailableCount();

  this.data=bean.getResult();

  this.countMaxPage();

 }

}

//对ContactBean接口进行adapter模式的封装。方便实用。

public class ContactAdapter implements ContactBean{

 public ContactAdapter() { }

 public int getAvailableCount()throws Exception{

  return 0;

 }

 public int getAvailableCount(int id)throws Exception{

  return 0;

 }

 public PageBean listData(String page)throws Exception {

  return null;

 }

 public PageBean listData(String page,int id)throws Exception {

  return null;

 }

 public Collection getResult()throws Exception{

  return null;

 }

}

在使用中你可以实现com.cn.interfaces.ContactBean 或继承 com.cn.interfaces.ContactAdapter都可以。

实现方法:

              实现一:其中不需要键入任何参数。

public int getAvailableCount()throws Exception;

               public PageBean listData(String page)throws Exception ;

               public Collection getResult()throws Exception;

              实现二:需要键入参数。

public int getAvailableCount(int id)throws Exception;

               public PageBean listData(String page,int id)throws Exception ;

public Collection getResult()throws Exception;

[1] [2]
Tags:关键字:实现jsp页面得分页显示功能方案
责任编辑:glen