Java分页实例之-分页类
来源:互联网 发布:著名的中文域名有哪些 编辑:程序博客网 时间:2024/05/02 02:25
package com.dbtemplate.domain;
import org.apache.log4j.Logger;
/** *//**
* The Class PageInfo.
*/
public class PageInfo ...{
/** *//** The logger. */
static Logger logger = Logger.getLogger(PageInfo.class.getName());
/** *//** The total records. */
private int totalRecords;
/** *//** The total pages. */
private int totalPages;
/** *//** The page size. */
private int pageSize = 10;
/** *//** The current page no. */
private int currentPageNo;
/** *//** The previous page no. */
private int previousPageNo;
/** *//** The next page no. */
private int nextPageNo;
/** *//** The is first page. */
private boolean isFirstPage;
/** *//** The is last page. */
private boolean isLastPage;
/** *//** The has previous pag. */
private boolean hasPreviousPage;
/** *//** The has next page. */
private boolean hasNextPage;
/** *//**
* Instantiates a new page info.
*
* @param totalRecords the total records
*/
public PageInfo(int totalRecords, int pageSize) ...{
logger.debug("Start to initialize the page info.");
// 设置总记录数
if(totalRecords >= 0) ...{
this.totalRecords = totalRecords;
} else ...{
totalRecords = 0;
}
// 设置每页记录数
setPageSize(pageSize);
// 设置总页面数
if(totalRecords % pageSize == 0) ...{
totalPages = totalRecords/pageSize;
} else ...{
totalPages = (totalRecords/pageSize) + 1;
}
// 设置当前页
currentPageNo = 1;
}
/** *//**
* Gets the current page no.
*
* @return the current page no
*/
public int getCurrentPageNo() ...{
return currentPageNo;
}
/** *//**
* Sets the current page no.
*
* @param currentPageNo the new current page no
*/
public void setCurrentPageNo(int currentPageNo) ...{
// 设置当前页
if(currentPageNo < 1) ...{
this.currentPageNo = 1;
} else if(currentPageNo > totalPages) ...{
this.currentPageNo = totalPages;
} else ...{
this.currentPageNo = currentPageNo;
}
// 每次设置当前页时更新上一页、下一页、是否首页、是否末页、是否有上一页、是否有下一页标志
isFirstPage = (currentPageNo == 1)?true:false;
isLastPage = (currentPageNo == totalPages)?true:false;
hasPreviousPage = (currentPageNo == 1)? false:true;
hasNextPage = (currentPageNo == totalPages)? false:true;
previousPageNo = (hasPreviousPage)? (currentPageNo - 1):currentPageNo;
nextPageNo = (hasNextPage)? (currentPageNo + 1):currentPageNo;
}
/** *//**
* Gets the current page size.
*
* @return the current page size
*/
public int getCurrentPageSize() ...{
if(totalRecords == 0) ...{
return 0;
} else if(currentPageNo < totalPages) ...{
// 非末页
return pageSize;
} else ...{
// 末页
return (totalRecords - (currentPageNo -1) * pageSize);
}
}
/** *//**
* Gets the current page start record.
*
* @return the current page start record
*/
public int getCurrentPageStartRecord() ...{
return (currentPageNo - 1) * pageSize + 1;
}
/** *//**
* Gets the current page end record.
*
* @return the current page end record
*/
public int getCurrentPageEndRecord() ...{
return (currentPageNo -1) * pageSize + getCurrentPageSize();
}
/** *//**
* Checks if is has next page.
*
* @return true, if is has next page
*/
public boolean isHasNextPage() ...{
return hasNextPage;
}
/** *//**
* Checks if is has previous pag.
*
* @return true, if is has previous pag
*/
public boolean isHasPreviousPage() ...{
return hasPreviousPage;
}
/** *//**
* Checks if is first page.
*
* @return true, if is first page
*/
public boolean isFirstPage() ...{
return isFirstPage;
}
/** *//**
* Checks if is last page.
*
* @return true, if is last page
*/
public boolean isLastPage() ...{
return isLastPage;
}
/** *//**
* Gets the page size.
*
* @return the page size
*/
public int getPageSize() ...{
return pageSize;
}
/** *//**
* Sets the page size.
*
* @param pageSize the new page size
*/
public void setPageSize(int pageSize) ...{
this.pageSize = (pageSize <= 0)?10:pageSize;
}
/** *//**
* Gets the previous page no.
*
* @return the previous page no
*/
public int getPreviousPageNo() ...{
return previousPageNo;
}
/** *//**
* Gets the next page no.
*
* @return the next page no
*/
public int getNextPageNo() ...{
return nextPageNo;
}
/** *//**
* Gets the total pages.
*
* @return the total pages
*/
public int getTotalPages() ...{
return totalPages;
}
/** *//**
* Gets the total records.
*
* @return the total records
*/
public int getTotalRecords() ...{
return totalRecords;
}
}
import org.apache.log4j.Logger;
/** *//**
* The Class PageInfo.
*/
public class PageInfo ...{
/** *//** The logger. */
static Logger logger = Logger.getLogger(PageInfo.class.getName());
/** *//** The total records. */
private int totalRecords;
/** *//** The total pages. */
private int totalPages;
/** *//** The page size. */
private int pageSize = 10;
/** *//** The current page no. */
private int currentPageNo;
/** *//** The previous page no. */
private int previousPageNo;
/** *//** The next page no. */
private int nextPageNo;
/** *//** The is first page. */
private boolean isFirstPage;
/** *//** The is last page. */
private boolean isLastPage;
/** *//** The has previous pag. */
private boolean hasPreviousPage;
/** *//** The has next page. */
private boolean hasNextPage;
/** *//**
* Instantiates a new page info.
*
* @param totalRecords the total records
*/
public PageInfo(int totalRecords, int pageSize) ...{
logger.debug("Start to initialize the page info.");
// 设置总记录数
if(totalRecords >= 0) ...{
this.totalRecords = totalRecords;
} else ...{
totalRecords = 0;
}
// 设置每页记录数
setPageSize(pageSize);
// 设置总页面数
if(totalRecords % pageSize == 0) ...{
totalPages = totalRecords/pageSize;
} else ...{
totalPages = (totalRecords/pageSize) + 1;
}
// 设置当前页
currentPageNo = 1;
}
/** *//**
* Gets the current page no.
*
* @return the current page no
*/
public int getCurrentPageNo() ...{
return currentPageNo;
}
/** *//**
* Sets the current page no.
*
* @param currentPageNo the new current page no
*/
public void setCurrentPageNo(int currentPageNo) ...{
// 设置当前页
if(currentPageNo < 1) ...{
this.currentPageNo = 1;
} else if(currentPageNo > totalPages) ...{
this.currentPageNo = totalPages;
} else ...{
this.currentPageNo = currentPageNo;
}
// 每次设置当前页时更新上一页、下一页、是否首页、是否末页、是否有上一页、是否有下一页标志
isFirstPage = (currentPageNo == 1)?true:false;
isLastPage = (currentPageNo == totalPages)?true:false;
hasPreviousPage = (currentPageNo == 1)? false:true;
hasNextPage = (currentPageNo == totalPages)? false:true;
previousPageNo = (hasPreviousPage)? (currentPageNo - 1):currentPageNo;
nextPageNo = (hasNextPage)? (currentPageNo + 1):currentPageNo;
}
/** *//**
* Gets the current page size.
*
* @return the current page size
*/
public int getCurrentPageSize() ...{
if(totalRecords == 0) ...{
return 0;
} else if(currentPageNo < totalPages) ...{
// 非末页
return pageSize;
} else ...{
// 末页
return (totalRecords - (currentPageNo -1) * pageSize);
}
}
/** *//**
* Gets the current page start record.
*
* @return the current page start record
*/
public int getCurrentPageStartRecord() ...{
return (currentPageNo - 1) * pageSize + 1;
}
/** *//**
* Gets the current page end record.
*
* @return the current page end record
*/
public int getCurrentPageEndRecord() ...{
return (currentPageNo -1) * pageSize + getCurrentPageSize();
}
/** *//**
* Checks if is has next page.
*
* @return true, if is has next page
*/
public boolean isHasNextPage() ...{
return hasNextPage;
}
/** *//**
* Checks if is has previous pag.
*
* @return true, if is has previous pag
*/
public boolean isHasPreviousPage() ...{
return hasPreviousPage;
}
/** *//**
* Checks if is first page.
*
* @return true, if is first page
*/
public boolean isFirstPage() ...{
return isFirstPage;
}
/** *//**
* Checks if is last page.
*
* @return true, if is last page
*/
public boolean isLastPage() ...{
return isLastPage;
}
/** *//**
* Gets the page size.
*
* @return the page size
*/
public int getPageSize() ...{
return pageSize;
}
/** *//**
* Sets the page size.
*
* @param pageSize the new page size
*/
public void setPageSize(int pageSize) ...{
this.pageSize = (pageSize <= 0)?10:pageSize;
}
/** *//**
* Gets the previous page no.
*
* @return the previous page no
*/
public int getPreviousPageNo() ...{
return previousPageNo;
}
/** *//**
* Gets the next page no.
*
* @return the next page no
*/
public int getNextPageNo() ...{
return nextPageNo;
}
/** *//**
* Gets the total pages.
*
* @return the total pages
*/
public int getTotalPages() ...{
return totalPages;
}
/** *//**
* Gets the total records.
*
* @return the total records
*/
public int getTotalRecords() ...{
return totalRecords;
}
}
- Java分页实例之-分页类
- JAVA分页代码实例
- JAVA分页代码实例
- Java分页代码实例
- java分页查询实例
- Java分页之假分页
- java分页之假分页
- JSP分页之-分页标签类
- 分页核心技术之项目实例
- php封装分页类+分页实例
- java web 分页实例项目
- PHP分页代码 PHP分页类 PHP分页实例
- java分页之页面分页—@易小川
- 分页实例
- 分页实例
- Oracle分页原理Java三层架构分页实例
- [PHP实例] PHP分页类
- JSP+MYSQL+Java类优化分页的实例
- 今天不小心的躲班
- 一、电力知识
- 修改Struts 2.0 中URL的.action后缀
- ASP的(VBScript)类基础
- 巧妙职场面试问答
- Java分页实例之-分页类
- 童年回忆:儿时 游戏 逮鱼
- C#如何取硬件标志
- [zz]各种随机数的产生
- 关于小鸡管理系统的一些思路
- VBscript超强幻灯片效果代码
- ole db的概念与编程
- JSP分页之-分页标签类
- C#开发和使用中的23个技巧