JAVA分页机制
来源:互联网 发布:股东会网络投票 编辑:程序博客网 时间:2024/06/07 18:14
package netctoss.util;
import java.util.Collection;
public class PageController {
//总行数
private int totalRowsAmount;
//每页行数
private int pageSize = 10;
//总页数
private int totalPages;
//当前页码
private int currentPage = 1;
//下一页
private int nextPage;
//上一页
private int previousPage;
//是否有下一页
private boolean hasNext;
//是否有上一页
private boolean hasPrevious;
//当前页开始行
private int pageStartRow;
//当前页结束行
private int pageEndRow;
//数据存储
@SuppressWarnings("unchecked")
private Collection data;
/**
* 构造函数。
* @param totalRows 总行数
*/
public PageController(int totalRows,int currentPage) {
setPageController(totalRows,currentPage);
}
public PageController(int totalRows,int currentPage,int pageSize){
this.pageSize = pageSize;
this.setPageController(totalRows,currentPage);
}
public void setPageController(int totalRows,int currentPage){
setTotalRowsAmount(totalRows);
setCurrentPage(currentPage);
}
/**
* 设置总行数。
* i 总行数。
*/
private void setTotalRowsAmount(int rows) {
if(rows <0 ){
totalRowsAmount = 0;
}else{
totalRowsAmount = rows;
}
if(totalRowsAmount%pageSize==0){
totalPages = totalRowsAmount / pageSize;
}else{
totalPages = totalRowsAmount / pageSize + 1;
}
}
/**
* 设置当前页数。
* @param i
*/
private void setCurrentPage( int curPage) {
if(curPage <= 0){
currentPage = 1;
}else if(curPage > totalPages){
currentPage = totalPages;
}else{
currentPage = curPage;
}
if(currentPage == 1){
hasPrevious = false;
}else{
hasPrevious = true;
}
if(currentPage == totalPages){
hasNext = false;
}else{
hasNext = true;
}
nextPage = currentPage + 1;
previousPage = currentPage - 1;
//计算当前页开始行和结束行
if(currentPage != totalPages){
pageStartRow = (currentPage-1)*pageSize +1;
}else{
pageStartRow = (currentPage - 1)*pageSize+1;
}
//记录索引从0开始
pageStartRow -= 1;
pageEndRow = pageStartRow + pageSize;
}
public int getCurrentPage() {
return currentPage;
}
public boolean isHasNext() {
return hasNext;
}
public boolean isHasPrevious() {
return hasPrevious;
}
public int getNextPage() {
return nextPage;
}
public int getPageSize() {
return pageSize;
}
public int getPreviousPage() {
return previousPage;
}
public int getTotalPages() {
return totalPages;
}
public int getTotalRowsAmount() {
return totalRowsAmount;
}
public int getPageStartRow() {
return pageStartRow;
}
public int getPageEndRow(){
return pageEndRow;
}
// public String description() {
// String description = "Total:" + this.getTotalRowsAmount() +
// " items " + this.getTotalPages() + " pages,Current page:" +
// this.currentPage + " Previous " + this.hasPrevious +
// " Next:" + this.hasNext +
// " start row:" + this.pageStartRow +
// " end row:" + this.pageEndRow;
// return description;
// }
@SuppressWarnings("unchecked")
public void setData(Collection data) {
this.data = data;
}
@SuppressWarnings("unchecked")
public Collection getData() {
return data;
}
// public static void main(String args[]){
//
// Collection c = null;
// PageController pc = new PageController(0,2);
// System.out.println(pc.description());
// }
}
import java.util.Collection;
public class PageController {
//总行数
private int totalRowsAmount;
//每页行数
private int pageSize = 10;
//总页数
private int totalPages;
//当前页码
private int currentPage = 1;
//下一页
private int nextPage;
//上一页
private int previousPage;
//是否有下一页
private boolean hasNext;
//是否有上一页
private boolean hasPrevious;
//当前页开始行
private int pageStartRow;
//当前页结束行
private int pageEndRow;
//数据存储
@SuppressWarnings("unchecked")
private Collection data;
/**
* 构造函数。
* @param totalRows 总行数
*/
public PageController(int totalRows,int currentPage) {
setPageController(totalRows,currentPage);
}
public PageController(int totalRows,int currentPage,int pageSize){
this.pageSize = pageSize;
this.setPageController(totalRows,currentPage);
}
public void setPageController(int totalRows,int currentPage){
setTotalRowsAmount(totalRows);
setCurrentPage(currentPage);
}
/**
* 设置总行数。
* i 总行数。
*/
private void setTotalRowsAmount(int rows) {
if(rows <0 ){
totalRowsAmount = 0;
}else{
totalRowsAmount = rows;
}
if(totalRowsAmount%pageSize==0){
totalPages = totalRowsAmount / pageSize;
}else{
totalPages = totalRowsAmount / pageSize + 1;
}
}
/**
* 设置当前页数。
* @param i
*/
private void setCurrentPage( int curPage) {
if(curPage <= 0){
currentPage = 1;
}else if(curPage > totalPages){
currentPage = totalPages;
}else{
currentPage = curPage;
}
if(currentPage == 1){
hasPrevious = false;
}else{
hasPrevious = true;
}
if(currentPage == totalPages){
hasNext = false;
}else{
hasNext = true;
}
nextPage = currentPage + 1;
previousPage = currentPage - 1;
//计算当前页开始行和结束行
if(currentPage != totalPages){
pageStartRow = (currentPage-1)*pageSize +1;
}else{
pageStartRow = (currentPage - 1)*pageSize+1;
}
//记录索引从0开始
pageStartRow -= 1;
pageEndRow = pageStartRow + pageSize;
}
public int getCurrentPage() {
return currentPage;
}
public boolean isHasNext() {
return hasNext;
}
public boolean isHasPrevious() {
return hasPrevious;
}
public int getNextPage() {
return nextPage;
}
public int getPageSize() {
return pageSize;
}
public int getPreviousPage() {
return previousPage;
}
public int getTotalPages() {
return totalPages;
}
public int getTotalRowsAmount() {
return totalRowsAmount;
}
public int getPageStartRow() {
return pageStartRow;
}
public int getPageEndRow(){
return pageEndRow;
}
// public String description() {
// String description = "Total:" + this.getTotalRowsAmount() +
// " items " + this.getTotalPages() + " pages,Current page:" +
// this.currentPage + " Previous " + this.hasPrevious +
// " Next:" + this.hasNext +
// " start row:" + this.pageStartRow +
// " end row:" + this.pageEndRow;
// return description;
// }
@SuppressWarnings("unchecked")
public void setData(Collection data) {
this.data = data;
}
@SuppressWarnings("unchecked")
public Collection getData() {
return data;
}
// public static void main(String args[]){
//
// Collection c = null;
// PageController pc = new PageController(0,2);
// System.out.println(pc.description());
// }
}
- JAVA分页机制
- 分页机制
- 分页机制
- 分页机制
- 分页机制
- 分页机制
- 分页机制
- 分页机制
- 分页机制
- 分页机制
- 分页机制
- taglib分页机制
- Oracle的分页机制
- Oracle的分页机制
- 操作系统的分页机制
- 操作系统分页机制
- 内存分页机制
- django的分页机制
- 用myeclipse自动生成hibernate配置文件
- Amazon的体系结构
- Hibernate 配置文件详解 一 (有点乱)
- Servlet实现文件的上传下载
- 有关C语言中有符号/无符号数混合运算的小问题
- JAVA分页机制
- 2011年10月28日 星期五
- javascript实现拖动效果
- HTML5 WebSocket之HelloWorld
- JAVA基础
- JAVA内存模型
- Hibernate缓存机制以及一级缓存和二级缓存的作用
- JVM的垃圾回收机制详解和性能调优
- DirectFB架构等基本知识 - DirectFB - larrupingpig