java中简单的翻页功能的实现(PageManager)
2007-07-17 22:40
931 查看
package util;
import java.util.List;
public class PageManager
{
private List allRecords = null;//collection储存同一类型的对象的集合
private int currentPage = 0;//当前页码
private int totalPage = 0;//总页数
private int recordPerPage = -1;//每页的对象数
private int totalCount=0;//总的对象数
//初始化
public PageManager(List allRecords, int recordPerPage)
{
if (allRecords == null || recordPerPage < 1) return;
this.allRecords = allRecords;
this.recordPerPage = recordPerPage;
this.totalCount=allRecords.size();
if (allRecords.size() % recordPerPage == 0)
this.totalPage = allRecords.size() / recordPerPage;
else
this.totalPage = allRecords.size() / recordPerPage + 1;
this.currentPage = 0;
}
//获取所有对象集合
public List getAllRecords()
{
return this.allRecords;
}
//获取当前页的的对象集合
public List getCurrentPage()
{
return getPage(currentPage);
}
//根据序号获取该对象所在的页的对象集合
public List getThePage(int recordno)
{
if (this.allRecords == null || this.allRecords.size() == 0)
{
this.currentPage = 0;
return null;
}
int pageNo=1;
if (recordno < 1) pageNo = 1;
else if (recordno > this.allRecords.size())
pageNo = this.totalPage;
else
{
pageNo=recordno/this.recordPerPage+1;
}
this.currentPage = pageNo;
int pageStart = (pageNo - 1) * this.recordPerPage;
int pageEnd = pageStart + this.recordPerPage - 1;
if (pageEnd > this.allRecords.size() - 1) pageEnd = this.allRecords.size() - 1;
List result =this.allRecords.subList(pageStart, pageEnd+1);
return result;
}
//根据页码获取改页的对象集合
public List getPage(int pageNo)
{
if (this.allRecords == null || this.allRecords.size() == 0)
{
this.currentPage = 0;
return null;
}
if (pageNo < 1) pageNo = 1;
if (pageNo > this.totalPage) pageNo = this.totalPage;
this.currentPage = pageNo;
int pageStart = (pageNo - 1) * this.recordPerPage;
int pageEnd = pageStart + this.recordPerPage - 1;
if (pageEnd > this.allRecords.size() - 1) pageEnd = this.allRecords.size() - 1;
List result =this.allRecords.subList(pageStart, pageEnd+1);
return result;
}
//获取下一页的对象集合
public List getNextPage()
{
return getPage(this.currentPage + 1);
}
//获取上一页的对象集合
public List getPreviousPage()
{
return getPage(this.currentPage - 1);
}
//获取第一页的对象集合
public List getFirstPage()
{
return getPage(1);
}
//获取最后一页的对象集合
public List getLastPage()
{
return getPage(this.totalPage);
}
//获取总页数
public int getTotalPage() {
return totalPage;
}
//获取当前页码
public int getCurrentPageCount()
{
return this.currentPage;
}
//获取对象总数
public int getTotalCount() {
return totalCount;
}
}
import java.util.List;
public class PageManager
{
private List allRecords = null;//collection储存同一类型的对象的集合
private int currentPage = 0;//当前页码
private int totalPage = 0;//总页数
private int recordPerPage = -1;//每页的对象数
private int totalCount=0;//总的对象数
//初始化
public PageManager(List allRecords, int recordPerPage)
{
if (allRecords == null || recordPerPage < 1) return;
this.allRecords = allRecords;
this.recordPerPage = recordPerPage;
this.totalCount=allRecords.size();
if (allRecords.size() % recordPerPage == 0)
this.totalPage = allRecords.size() / recordPerPage;
else
this.totalPage = allRecords.size() / recordPerPage + 1;
this.currentPage = 0;
}
//获取所有对象集合
public List getAllRecords()
{
return this.allRecords;
}
//获取当前页的的对象集合
public List getCurrentPage()
{
return getPage(currentPage);
}
//根据序号获取该对象所在的页的对象集合
public List getThePage(int recordno)
{
if (this.allRecords == null || this.allRecords.size() == 0)
{
this.currentPage = 0;
return null;
}
int pageNo=1;
if (recordno < 1) pageNo = 1;
else if (recordno > this.allRecords.size())
pageNo = this.totalPage;
else
{
pageNo=recordno/this.recordPerPage+1;
}
this.currentPage = pageNo;
int pageStart = (pageNo - 1) * this.recordPerPage;
int pageEnd = pageStart + this.recordPerPage - 1;
if (pageEnd > this.allRecords.size() - 1) pageEnd = this.allRecords.size() - 1;
List result =this.allRecords.subList(pageStart, pageEnd+1);
return result;
}
//根据页码获取改页的对象集合
public List getPage(int pageNo)
{
if (this.allRecords == null || this.allRecords.size() == 0)
{
this.currentPage = 0;
return null;
}
if (pageNo < 1) pageNo = 1;
if (pageNo > this.totalPage) pageNo = this.totalPage;
this.currentPage = pageNo;
int pageStart = (pageNo - 1) * this.recordPerPage;
int pageEnd = pageStart + this.recordPerPage - 1;
if (pageEnd > this.allRecords.size() - 1) pageEnd = this.allRecords.size() - 1;
List result =this.allRecords.subList(pageStart, pageEnd+1);
return result;
}
//获取下一页的对象集合
public List getNextPage()
{
return getPage(this.currentPage + 1);
}
//获取上一页的对象集合
public List getPreviousPage()
{
return getPage(this.currentPage - 1);
}
//获取第一页的对象集合
public List getFirstPage()
{
return getPage(1);
}
//获取最后一页的对象集合
public List getLastPage()
{
return getPage(this.totalPage);
}
//获取总页数
public int getTotalPage() {
return totalPage;
}
//获取当前页码
public int getCurrentPageCount()
{
return this.currentPage;
}
//获取对象总数
public int getTotalCount() {
return totalCount;
}
}
相关文章推荐
- 简单实现java上传图片文件功能
- FFmpeg在Linux下的简单安装并与Java结合获取视频缩略图功能实现
- jQuery实现简单的图片轮播(二)-增加左右(或上下)翻页功能
- java反射的作用------hibernate插入功能的j简单实现
- Java实现简单的分页功能
- Java使用cookie实现简单的单点登录功能
- java TCP/IP实现简单的多人聊天功能
- Java语言实现简单FTP软件------>FTP软件效果图预览之下载功能(二)
- java由servlet实现登录的简单功能,并把用户名用cookie保存起来,读取cookie
- Java简单实现文件剪切的功能
- Java语言实现简单FTP软件------>辅助功能模块FTP站点管理的实现(十二)
- java简单实现复制 粘贴 剪切功能代码分享
- 用radix tree简单实现java.util.Map的功能
- Java简单实现视频录制播放功能
- Java_GUI创建单机版QQ聊天小程序并实现简单的小功能(附所有源码)
- java实现一个简单的HTTP服务器,带打开网页和计算功能
- Github Page+Bmob实现简单动态功能
- 【Java基础】用LinkedList实现一个简单栈的功能
- 简单实现Java验证码功能
- 实现简单的一页展示多条数据左右翻页功能