当前位置: 编程技术>java/j2ee
一个通用的jsp分页PageBean
来源: 互联网 发布时间:2014-10-17
本文导语: package com.shaccp.web.util; import java.util.List; public class PageBean { /** * * * @author ppy 2008-10-18 14:3:56 * totalRecords 总记录数 * list 保存分页的数据 * pageNo 当前页 * pageSize 页大小 * query 保存用户查询的字符串 * pageAction 操作分页的Servlet或Action...
package com.shaccp.web.util;
import java.util.List;
public class PageBean {
/**
*
*
* @author ppy 2008-10-18 14:3:56
* totalRecords 总记录数
* list 保存分页的数据
* pageNo 当前页
* pageSize 页大小
* query 保存用户查询的字符串
* pageAction 操作分页的Servlet或Action(struts)
* method (struts中Action对应的method)
*
*
*/
private int totalRecords;
private List list;
private int pageNo;
private int pageSize;
private String query;
private String pageAction;
private String method;
public void setPageAction(String pageAction) {
this.pageAction = pageAction;
}
public void setMethod(String method) {
this.method = method;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalRecords() {
return totalRecords;
}
public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
}
public void setQuery(String query) {
this.query = query;
}
/**
* 取得总页数的方法 return
* totalRecords%pageSize==0?(totalRecords/pageSize):(totalRecords/pageSize+1)
*
* @return
*/
public int getTotalPages() {
return (totalRecords + pageSize - 1) / pageSize;
}
/**
* 得到首页
*
* @return
*/
public int getTopPage() {
return 1;
}
/**
* 得到上一页
*
* @return
*/
public int getPreviousPageNo() {
if (pageNo = getTotalPages()) {
return getTotalPages() == 0 ? 1 : getTotalPages();
} else {
return pageNo + 1;
}
}
/**
* 得到尾页
*
* @return
*/
public int getBottomPageNo() {
return getTotalRecords() == 0 ? 1 : getTotalPages();
}
//页面分页导航的链接 方式一
public String getPageToolBar1() {
String str = "";
str += "上一页 ";
str += "下一页";
return str;
}
//页面分页导航的链接 方式二
public String getPageToolBar2() {
String str = "";
int pageSplit = (pageNo / 5) * 5;
for (int i = pageSplit - 1; i < (pageSplit + 6); i++) {
if (i getTotalPages()) {
} else {
str += "" + i + "" + " ";
}
}
return str;
}
}
import java.util.List;
public class PageBean {
/**
*
*
* @author ppy 2008-10-18 14:3:56
* totalRecords 总记录数
* list 保存分页的数据
* pageNo 当前页
* pageSize 页大小
* query 保存用户查询的字符串
* pageAction 操作分页的Servlet或Action(struts)
* method (struts中Action对应的method)
*
*
*/
private int totalRecords;
private List list;
private int pageNo;
private int pageSize;
private String query;
private String pageAction;
private String method;
public void setPageAction(String pageAction) {
this.pageAction = pageAction;
}
public void setMethod(String method) {
this.method = method;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalRecords() {
return totalRecords;
}
public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
}
public void setQuery(String query) {
this.query = query;
}
/**
* 取得总页数的方法 return
* totalRecords%pageSize==0?(totalRecords/pageSize):(totalRecords/pageSize+1)
*
* @return
*/
public int getTotalPages() {
return (totalRecords + pageSize - 1) / pageSize;
}
/**
* 得到首页
*
* @return
*/
public int getTopPage() {
return 1;
}
/**
* 得到上一页
*
* @return
*/
public int getPreviousPageNo() {
if (pageNo = getTotalPages()) {
return getTotalPages() == 0 ? 1 : getTotalPages();
} else {
return pageNo + 1;
}
}
/**
* 得到尾页
*
* @return
*/
public int getBottomPageNo() {
return getTotalRecords() == 0 ? 1 : getTotalPages();
}
//页面分页导航的链接 方式一
public String getPageToolBar1() {
String str = "";
str += "上一页 ";
str += "下一页";
return str;
}
//页面分页导航的链接 方式二
public String getPageToolBar2() {
String str = "";
int pageSplit = (pageNo / 5) * 5;
for (int i = pageSplit - 1; i < (pageSplit + 6); i++) {
if (i getTotalPages()) {
} else {
str += "" + i + "" + " ";
}
}
return str;
}
}