package com.bdqn.zhp.util;
import java.util.ArrayList;
import java.util.List;
/**
* 分页组件 分页:内存分页和SQL分页
*
* 分页需要参数:
*
* 总记录数,每页显示条数
*
*/
public class PageBeanSQL<T> {
private int totalSize;// 总记录数
private int rowsPerPage = 5;// 每页显示条数
private int totalPages = 0;// 总页数
private int curPageNo = 1;// 当前页号
private List<T> pageList = new ArrayList<T>();// 存放当前页显示的所有记录
/**
* 分页方法
*
* @param list
* : 所有记录
* @param curPage
* : 当前页号
*/
public void page() {
// 计算页数
if (this.totalSize % this.rowsPerPage == 0) {
this.totalPages = this.totalSize / this.rowsPerPage;
} else {
this.totalPages = this.totalSize / this.rowsPerPage + 1;
}
if(curPageNo<=0){
this.curPageNo = 1;
}
if(curPageNo>=this.totalPages){
this.curPageNo = this.totalPages;
}
}
/**
* 设置页号,传入String参数,转换为int并赋值
*/
public void setPageNo(String curPage){
try {
this.curPageNo = Integer.parseInt(curPage);
} catch (Exception e) {
this.curPageNo = 1;
}
}
public int getTotalSize() {
return totalSize;
}
public void setTotalSize(int totalSize) {
this.totalSize = totalSize;
}
public int getRowsPerPage() {
return rowsPerPage;
}
public void setRowsPerPage(int rowsPerPage) {
this.rowsPerPage = rowsPerPage;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public int getCurPageNo() {
return curPageNo;
}
public void setCurPageNo(int curPageNo) {
this.curPageNo = curPageNo;
}
public List<T> getPageList() {
return pageList;
}
public void setPageList(List<T> pageList) {
this.pageList = pageList;
}
}
转载于:https://www.cnblogs.com/baobeiqi-e/p/9884839.html