一、pagebean的改变(增加变量)
1、url:保存上一次的地址;
2、p:保存上一次查询条件;
3、maxPage:获取最大页码;
4、previousPage:获取上一页的页码;
5、nextPage:获取下一页的页码;
6、setReq:初始化pagebean;
package com.cxy.util;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
/**
* 分页工具类
*
*/
public class PageBean {
private int page = 1;// 页码
private int rows = 10;// 页大小
private int total = 0;// 总记录数
private boolean pagination = true;// 是否分页
//新增变量
private String url;//保存上一次的地址
//保存上一次查询条件
private Map<String, String[]> p = new HashMap<String, String[]>();
//获取最大页码
public int maxPage() {
return this.total%this.rows==0?
this.total/this.rows:
this.total/this.rows+1;
}
//获取上一页的页码
public int previousPage() {
return this.page>1 ? this.page-1 : this.page;
}
//获取下一页的页码
public int nextPage() {
return this.page<this.maxPage() ? this.page+1 : this.page;
}
//初始化pagebean
public void setReq(HttpServletRequest req) {
this.setPage(req.getParameter("page"));
this.setRows(req.getParameter("rows"));
this.setPagination(req.getParameter("Pagination"));
this.setUrl(req.getRequestURL().toString());
this.setP(req.getParameterMap());
}
private void setPagination(String Pagination) {
if(StringUtils.isNotBlank(Pagination)) {
//set自动生成的方法
this.setPagination(!"false".equals(Pagination));
}
}
private void setRows(String rows) {
if(StringUtils.isNotBlank(rows)) {
//set自动生成的方法
this.setRows(Integer.valueOf(rows));
}
}
public void setPage(String page) {
if(StringUtils.isNotBlank(page)) {
//set自动生成的方法
this.setPage(Integer.valueOf(page));
}
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Map<String, String[]> getP() {
return p;
}
public void setP(Map<String, String[]> p) {
this.p = p;
}
public PageBean() {
super();
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getRows() {
return rows;
}
public void setRows(int rows) {
this.rows = rows;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public void setTotal(String total) {
this.total = Integer.parseInt(total);
}
public boolean isPagination() {
return pagination;
}
public void setPagina