浏览 2544 次
锁定老帖子 主题:忍不住了,凑凑热闹,我也来秀一下我的分页类
精华帖 (0) :: 良好帖 (0) :: 新手帖 (4) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-12-18
最后修改:2008-12-18
这是下载地址 http://code.google.com/p/javaman/downloads/list 简单说明 为了保险起见,绝对标准的OO设计 Page 接口 定义分页接口 AbstractPage Page接口的默认实现,实现了大多数操作 defaultPageIMpl 实体类 【如果不满意我的实现,自己可以实现】 用法 实例话一个DefaultPageImpl 默认构造, DefaultPageImpl(); 默认每页显示10条记录 带参数构造 DefaultPageImpl(int rowInPage) 传入每页的显示数目 用法, setRowCount(int c) 需要传入 记录总行数 setPageIndex(int index) 页码索引 getStartIndex() 返回抓取记录的起始索引 getOffset() 返回抓取的行数 ============================================================== 就这么简单,至于mysql 实际上就是 想办法取得 limit x,y 的xy值 其他数据库没研究过,怎么分页,欢迎大家拍砖 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-12-19
楼主,你的源码呢?
|
|
返回顶楼 | |
发表时间:2008-12-19
Page
package net.myweb.tool; public abstract interface Page { //设置当前页索引 public abstract void setPageIndex(int paramInt); //得到当前页索引 public abstract int getPageIndex(); //设置总记录数 public abstract void setRowCount(int paramInt); public abstract int getRowCount(); //设着每页显示的行数 public abstract void setRowInPage(int paramInt); public abstract int getRowInPage(); public abstract int getStartIndex(int paramInt); //得到本页开始索引 public abstract int getStartIndex(); //得到总页数 public abstract int getPageCount(); //判断是否有前页 public abstract boolean hasPrevious(); //判断是否有后页 public abstract boolean hasNext(); } package net.myweb.tool; import org.apache.log4j.Logger; public class AbstractPage implements Page { protected final Logger logger; private int _rowCount; private int _rowsInPage; private int _pageIndex; private int _pageCount; public AbstractPage(int rowCount) { this.logger = Logger.getLogger(super.getClass()); this._rowsInPage = 10; this._pageIndex = 0; int base = this._rowCount / this._rowsInPage; if (this._rowCount % this._rowsInPage == 0) this._pageCount = base; else this._pageCount = (base + 1); } public AbstractPage() { this(10); } public int getPageIndex() { if (getPageCount() == 0) this._pageIndex = 1; if ((this._pageIndex > getPageCount()) && (getPageCount() != 0)) this._pageIndex %= getPageCount(); if ((this._pageIndex > getPageCount()) && (getPageCount() == 0)) this._pageIndex = 1; if (this._pageIndex <= 0) this._pageIndex = 1; return this._pageIndex; } public int getRowCount() { return this._rowCount; } public int getRowInPage() { return this._rowsInPage; } public int getStartIndex(int pageIndex) { if ((pageIndex <= 0) || (pageIndex >= getRowCount())) return 0; return ((pageIndex - 1) * this._rowsInPage); } public void setPageIndex(int curent) { this._pageIndex = curent; } public void setRowCount(int rowCount) { this._rowCount = rowCount; } public void setRowInPage(int rows) { if (rows > 0) this._rowsInPage = rows; } public int getPageCount() { int base = this._rowCount / this._rowsInPage; if (this._rowCount % this._rowsInPage == 0) this._pageCount = base; else this._pageCount = (base + 1); return this._pageCount; } public boolean hasNext() { return (getPageIndex() != getPageCount()); } public boolean hasPrevious() { return (getPageIndex() != 1); } public int getStartIndex() { return getStartIndex(getPageIndex()); } } package net.myweb.tool; public class DefaultPageImp extends AbstractPage { public DefaultPageImp(int rowperpage) { super(rowperpage); } } 对应的三个类,都很简单,功能一看就懂 |
|
返回顶楼 | |