?? pagecontrol.java
字號:
/*
* @(#)PageControl.java 1.00 2004-9-22
*
* Copyright 2004 2004 . All rights reserved.
* PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package beansoft.jsp;
/**
* PageControl, 分頁控制, 可以判斷總頁數和是否有上下頁.
*
* @author beansoft
* @version 1.00 2004-9-22
*/
public class PageControl {
/** 每頁顯示記錄數 */
private int pageCount;
/** 是否有上一頁 */
private boolean hasPrevPage;
/** 記錄總數 */
private int recordCount;
/** 是否有下一頁 */
private boolean hasNextPage;
/** 最大頁面數 */
private int maxPage;
/** 當前頁碼數 */
private int currentPage;
/**
*
*/
public PageControl() {
}
/**
* 進行分頁計算.
*/
private void calculate() {
if (getPageCount() == 0) {
setPageCount(1);
}
maxPage = (int) Math.ceil(1.0 * getRecordCount() / getPageCount()); // 總頁面數
if (maxPage == 0)
maxPage = 1;
// System.out.println("currentPage=" + currentPage);
// System.out.println("maxPage=" + maxPage);
// // Fixed logic error at 2004-09-25
hasNextPage = currentPage < maxPage;
hasPrevPage = currentPage > 1;
return;
}
/**
* @return Returns the 最大頁面數.
*/
public int getMaxPage() {
calculate();
return maxPage;
}
/**
* @param currentPage
* The 最大頁面數 to set.
*/
private void setMaxPage(int maxPage) {
this.maxPage = maxPage;
}
/**
* 是否有上一頁數據
*/
public boolean hasPrevPage() {
calculate();
return hasPrevPage;
}
/**
* 是否有下一頁數據
*/
public boolean hasNextPage() {
calculate();
return hasNextPage;
}
// Test
public static void main(String[] args) {
PageControl pc = new PageControl();
pc.setCurrentPage(0);
pc.setPageCount(5);
pc.setRecordCount(7);
System.out.println("當前頁 " + pc.getCurrentPage());
System.out.println("有上一頁 " + pc.hasPrevPage());
System.out.println("有下一頁 " + pc.hasNextPage());
System.out.println("最大頁面數 " + pc.getMaxPage());
}
/**
* @return Returns the 當前頁碼數.
*/
public int getCurrentPage() {
return currentPage;
}
/**
* 設置當前頁碼, 從 1 開始.
* @param currentPage
* The 當前頁碼數 to set.
*/
public void setCurrentPage(int currentPage) {
if (currentPage <= 0) {
currentPage = 1;
}
this.currentPage = currentPage;
}
/**
* @return Returns the recordCount.
*/
public int getRecordCount() {
return recordCount;
}
/**
* @param recordCount
* The recordCount to set.
*/
public void setRecordCount(int property1) {
this.recordCount = property1;
}
/**
* @return Returns the 每頁顯示記錄數.
*/
public int getPageCount() {
return pageCount;
}
/**
* @param pageCount
* The 每頁顯示記錄數 to set.
*/
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -