Java分页
来源:互联网 发布:江山人才招聘21js 编辑:程序博客网 时间:2024/05/17 06:49
之前找分页不方便, 就自己写了个,代码如下:
package com.vcr.util;
import java.util.List;
import java.util.Map;
public class Pager {
int curPage = 1;// 当前页
int totoalPage = 0;// 总页数
int prePage = 0;// 上一页
int nextPage = 0;// 下一页
int totoalCnt = 0;// 总条数
int cntOfPage = 10;// 每页的条数
String sorder = "desc";//排序方式
String sindex = "";//排序字段
List<Map<String, Object>> rows;//保存实际的数据
public String getSorder() {
return sorder;
}
public void setSorder(String sorder) {
this.sorder = sorder;
}
public String getSindex() {
return sindex;
}
public void setSindex(String sindex) {
this.sindex = sindex;
}
/**
* 注意该方法的返回值:List。实际上包含了实际的数据,
* 而这些数据是放在Map<String, Object>中的。
* 因而,子类在action方法如:execute中,应该构建一个
* Map<String, Object>对象,将数据放入其中,并把该对象放入
* List中。
* @return
*/
public List<Map<String, Object>> getRows() {
return rows;
}
public void setRows(List<Map<String, Object>> rows) {
this.rows = rows;
}
public void calTotoalPage() {// 计算总页数
if (totoalCnt % cntOfPage > 0) {
this.totoalPage = totoalCnt / cntOfPage + 1;
} else {
this.totoalPage = totoalCnt / cntOfPage;
}
}
public int getTotoalCnt() {
return totoalCnt;
}
public void setTotoalCnt(int totoalCnt) {
this.totoalCnt = totoalCnt;
calTotoalPage();
setNextPage();
setPrePage();
}
public int getCurPage() {
return curPage;
}
public void setCurPage(int curPage) {
this.curPage = curPage;
setNextPage();
setPrePage();
}
public int getNextPage() {
return this.nextPage;
}
public void setNextPage() {
if (this.curPage < this.totoalPage) {
this.nextPage = this.curPage + 1;
} else {
this.nextPage = this.totoalPage;
}
if (this.nextPage == 0) {
this.nextPage = 1;
}
}
public int getPrePage() {
return this.prePage;
}
public void setPrePage() {
if (this.curPage > 1) {
this.prePage = this.curPage - 1;
} else {
this.prePage = 1;
}
}
public int getTotoalPage() {
return totoalPage == 0 ? 1 : totoalPage;
}
public void setTotoalPage(int totoalPage) {
this.totoalPage = totoalPage;
}
public int getCntOfPage() {
return cntOfPage;
}
public void setCntOfPage(int cntOfPage) {
this.cntOfPage = cntOfPage;
calTotoalPage();
}
}
- java分页
- java分页
- java 分页
- java分页
- java 分页
- java分页
- java 分页
- java 分页
- java分页
- java 分页
- java分页
- Java分页
- Java分页
- java分页
- java 分页
- java分页
- Java分页
- java 分页
- MySQL-5.6.13免安装版配置方法
- PMP在线报考流程下载
- 二分匹配求最大匹配数和最大匹配值
- Ubuntu 下安装thttpd Web服务器
- String,StringBuffer与StringBuilder的区别??
- Java分页
- PHP中的 抽象类(abstract class)和 接口(interface)
- 控制反转
- Hadoop MapReduce进阶 使用分布式缓存进行replicated join
- Java 单例模式详解
- POLL, SELECT & EPOLL 原理比较分析
- C#中HashTable的用法
- python2.7中使用mysql (windows XP)
- Hibernate 映射关系注解 属性详解