备注:本文为自己测试通过的原创代码,若转载请出示转载路径,谢谢!
一、创建PageBean实体类,用于存放分页所需变量及计算分页数量
package com.dss.utils;
import java.util.List;
/**
* 页面实体类
* @author Administrator
*
*/
public class PageBean{
@SuppressWarnings("rawtypes")
private List list; //要返回的某一页的记录列表
private int allRow; //总记录数
private int totalPage; //总页数
private int currentPage; //当前页
private int pageSize; //每页的记录数
@SuppressWarnings("rawtypes")
public List getList() {
return list;
}
public void setList(@SuppressWarnings("rawtypes") List list) {
this.list = list;
}
public int getAllRow() {
return allRow;
}
public void setAllRow(int allRow) {
this.allRow = allRow;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
/**
* 计算总页数 静态方法
* @param pageSize 每页的记录数
* @param allRow 总记录数
* @return 总页数
*/
public static int countTatalPage(final int pageSize,final int allRow){
int toalPage = allRow % pageSize == 0 ? allRow/pageSize : allRow/pageSize + 1;
return toalPage;
}
/**