?? pagelist.java
字號:
package com.easyjf.web.tools;
import java.util.*;
/**
* 實現通過調用IQuery實現分頁處理,其它特殊形式的分頁查詢需求只需要繼承該類即可,比如DbPageList。具體的分頁查詢算法可以根據實際應用中的記錄數、響應時間要求等選擇適合的查詢處理器IQuery,
*
* @author 蔡世友
*
*/
public class PageList implements IPageList {
private int rowCount;// 記錄數
private int pages;// 總頁數
private int currentPage;// 實際頁數
private int pageSize;
private List result;// 查詢結果集
private IQuery query;// 查詢器
public PageList() {
}
/**
* 根據查詢器q構造一個分頁處理對象
*
* @param q
*/
public PageList(IQuery q) {
this.query = q;
}
/**
* 設置查詢器
*/
public void setQuery(IQuery q) {
query = q;
}
/**
* 返回查詢結果集,只有在執行doList方法后才能取得正確的查詢結果
*/
public List getResult() {
return result;
}
/**
* 根據每頁記錄數,頁碼,統計sql及實際查詢sql執行查詢操作
*/
public void doList(int pageSize, int pageNo, String totalSQL,
String queryHQL) {
doList(pageSize,pageNo,totalSQL,queryHQL,null);
}
/**
* 根據每頁記錄數,頁碼,統計sql及實際查詢sql及參數執行查詢操作
*/
public void doList(int pageSize, int pageNo, String totalSQL,
String queryHQL, Collection paraValues) {
List rs = null;
this.pageSize=pageSize;
if(paraValues!=null)query.setParaValues(paraValues);
int total = query.getRows(totalSQL);
//System.out.println("query:"+queryHQL+";total:"+total);
if (total > 0) {
this.rowCount = total;
this.pages = (this.rowCount + pageSize - 1) / pageSize; // 記算總頁數
int intPageNo = (pageNo > this.pages ? this.pages : pageNo);
if (intPageNo < 1)
intPageNo = 1;
this.currentPage = intPageNo;
if (pageSize > 0) {
query.setFirstResult((intPageNo - 1) * pageSize);
query.setMaxResults(pageSize);
}
rs = query.getResult(queryHQL);
}
result = rs;
}
/**
* 返回總頁數
*/
public int getPages() {
return pages;
}
/**
* 返回總記錄數
*/
public int getRowCount() {
return rowCount;
}
/**
* 返回當前頁
*/
public int getCurrentPage() {
return currentPage;
}
/**
* 返回每頁大小
*/
public int getPageSize() {
return pageSize;
}
public int getNextPage()
{
int p=this.currentPage+1;
if(p>this.pages)p=this.pages;
return p;
}
public int getPreviousPage()
{
int p=this.currentPage-1;
if(p<1)p=1;
return p;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -