package treeroot.util;
import java.util.List;
/**
* 该接口用来实现分页功能,注意这里没有提供修改的功能。
* @author treerot
* @version 1.0
* @since 2004-9-30
*/
public interface Pageable
{
/**
* 获得数据结果
* @return
*/
public List getResult();
/**
* 获得查询总数
* @return
*/
public int getCount();
/**
* 获得每页纪录数
* @return
*/
public int getPageSize();
/**
* 获得当前页编号
* @return
*/
public int getCurrentPage();
/**
* 获得总页数
* @return
*/
public int getPages();
/**
* 每页默认显示纪录数
*/
public final static int DEFAULT_PAGESIZE=20;
}
package treeroot.util;
import java.util.List;
/**
* @author treerot
* @version 1.0
* @since 2004-9-30
*/
public abstract class AbstractPage implements Pageable
{
private int currentPage;
private int pageSize;
private int pages;
protected int count;
protected List result;
/**
* 指定当前页
* @param currentPage
* @throws PageException
*/
public AbstractPage(int currentPage){
this(currentPage,Pageable.DEFAULT_PAGESIZE);
}
/**
* 指定当前页和页大小
* @param currentPage
* @param pageSize
* @throws PageException
*/
public AbstractPage(int currentPage,int pageSize) {
this.currentPage=currentPage;
this.pageSize=pageSize;
}
protected void checkPage(int currentPage) throws PageException{
if((currentPage<1)||(currentPage>this.getPages()))
throw new PageException("页超出范围:总页数为"+this.getPages()+",当前页为"+currentPage);
}
/**
* 这个方法被子类重写用来初始化,也就是计算count值和result结果,在子类 的构造函数中调用。
*/
abstract protected void init() throws PageException;
public List getResult()
{
return result;
}
public int getCount()
{
return count;
}
public int getPageSize()
{
return pageSize;
}
public int getCurrentPage()
{
return currentPage;
}
public int getPages()
{
if(pages==0) this.pages=(count+pageSize-1)/pageSize;
return pages;
}
}
package treeroot.util
/**
* @author treeroot
* @version 1.0
* @since 2004-9-30
*/
public class PageException extends Exception
{
public PageException(){
super();
}
public PageException(String message){
super(message);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有