java 分页 代码
来源:互联网 发布:javascript最好的教程 编辑:程序博客网 时间:2024/05/17 05:02
package common.util;
import java.util.*;
public class PageController implements IPageModel {
private Collection model;
//数据总行数
private int totalRowCount = 0; //
//总页数
private int pageCount = 0;
//每页应显示的行数
private int maxPageRowCount = 0;
//当前页行数
private int currPageRowCount = 0;
//当前页号
private int currPageNum;
//默认构造
public PageController() {
super();
}
//传入模型
public PageController(Collection model) {
setPageController(model);
}
//设一个分页模型
public void setPageController(Collection model) {
this.model = model;
this.totalRowCount = model.size();
}
/**
* 总页数
* @return int
*/
public int getPageCount() {
return this.pageCount;
}
/**
* getPageContents
*
* @param intPageNum int
* @return Object
*/
public Object getPageContents(int intPageNum) {
//非法数据
if(intPageNum<1){
intPageNum=1;
}
if(intPageNum>pageCount){
intPageNum=pageCount;
}
//指定当前页
this.currPageNum=intPageNum;
int i = 0;
ArrayList arr = new ArrayList();
//如果是合法的范围
if (intPageNum > 0 && intPageNum <= pageCount) {
//计算该页的开始号和结束号
int lfromrow = (intPageNum - 1) * maxPageRowCount;
arr = (ArrayList) getElementsAt(model, lfromrow, lfromrow + maxPageRowCount-1);
}
currPageNum=intPageNum;
return arr;
}
public Object getLastPage() {
return this.getPageContents(pageCount);
}
public Object getFirstPage() {
return this.getPageContents(0);
}
/**
* getCurrentPageRowsCount
*
* @return int
*/
public int getCurrentPageRowsCount() {
if(currPageNum<pageCount){
return maxPageRowCount;
}
else{//最后一页
return totalRowCount-(pageCount-1)*maxPageRowCount;
}
}
public int getCurrentPageNum(){
return currPageNum;
}
/**
* setMaxPageRows
*
* @return int
*/
public void setMaxPageRows(int rowCount) {
maxPageRowCount = rowCount;
//计算总页数
if (totalRowCount % maxPageRowCount > 0) { //有余数
pageCount = totalRowCount / maxPageRowCount + 1;
}
else {
pageCount = totalRowCount / maxPageRowCount;
}
}
/**
* getMaxPageRows
*/
public int getMaxPageRows() {
return maxPageRowCount;
}
//私有方法,返回集合中指定范围的数据
private Object getElementsAt(Collection model, int fromIndex, int toIndex) {
Iterator iter = model.iterator();
ArrayList arr = new ArrayList();
if (iter != null) {
int i = 0;
while (iter.hasNext()) {
Object obj=iter.next();
if (i >= fromIndex && i <= toIndex) {
arr.add(obj);
}
if (i > toIndex) {
break;
}
i = i + 1;
}
}
return arr;
}
}
- JAVA分页代码实例
- Java分页代码(JFIS)
- java分页代码
- java 分页 代码
- JAVA通用分页代码
- java 分页代码
- Java分页代码
- Java分页代码(JFIS)
- JAVA 手动分页代码
- JAVA分页代码实例
- java中的分页代码
- JAVA分页代码
- Java分页代码实例
- java分页实现代码
- Java分页代码
- JAVA分页代码
- java通用分页代码
- java代码实现分页
- 找回删除的文件
- 转:【0811】LM4229(LCD240128)画矩形+反白显示
- Google 输入法api自定义体验
- 实践csync2+inotify实现文件实时同步
- 常用命令
- java 分页 代码
- Qt学习之路(1):前言
- SQL2005数据类型简单整理
- sed指定行范围匹配(转贴!)
- 常用命令
- Develop Domino Applications for BlackBerry Devices (via Java)
- Windows自动安装命令
- ITU标准介绍及下载索引
- tomact内存分配问题