?? pagingutils.java
字號:
package com.ctic.core.pub.common;
import java.util.Map;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import com.ctic.core.prod.common.extproperty.DynamicBean;
/**
* 處理分頁信息的工具類
*
* @author Tu_Minglei
*/
public class PagingUtils {
private static final boolean debug = true;
/**
* 是否能支持分頁信息的存取
* @param obj
* @return
*/
public static boolean canSupportPaging(Object obj){
if((obj instanceof DynamicBean) || (obj instanceof Map)) return true;
if(PropertyUtils.isReadable(obj, "skipResults") && PropertyUtils.isWriteable(obj, "skipResults")
&& PropertyUtils.isReadable(obj, "maxResults") && PropertyUtils.isWriteable(obj, "maxResults"))
return true;
if(debug)
System.out.println("in PagingUtils.canSupportPaging() -- >> Cannot support paging: "+obj);
return false;
}
/**
* 重置分頁相關(guān)的參數(shù)值
* @param obj
*/
public static void resetPagingParams(Object obj){
if(canSupportPaging(obj)){
setSkipResults(obj, IBATIS_NO_SKIPPED_RESULTS);
setMaxResults(obj, IBATIS_NO_MAXIMUM_RESULTS);
}
}
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
* 存取分頁參數(shù)信息
**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/**
* 填入需忽略的記錄數(shù)
* @param paramObject
* @param skipResults
*/
public static void setSkipResults(Object paramObject, int skipResults){
if(paramObject instanceof DynamicBean){
((DynamicBean)paramObject).set("skipResults", skipResults);
return;
}
if(paramObject instanceof Map){
((Map)paramObject).put("skipResults", skipResults);
return;
}
try {
BeanUtils.setProperty(paramObject, "skipResults", skipResults);
} catch (Exception e) {
if(debug)
System.out.println("in PagingUtils.setSkipResults() -- >> Cannot set value for property skipResults");
}
}
/**
* 填入欲獲取的最大記錄數(shù)
* @param paramObject
* @param maxResults
*/
public static void setMaxResults(Object paramObject, int maxResults){
if(paramObject instanceof DynamicBean){
((DynamicBean)paramObject).set("maxResults", maxResults);
return;
}
if(paramObject instanceof Map){
((Map)paramObject).put("maxResults", maxResults);
return;
}
try {
BeanUtils.setProperty(paramObject, "maxResults", maxResults);
} catch (Exception e) {
if(debug)
System.out.println("in PagingUtils.setMaxResults() -- >> Cannot set value for property maxResults");
}
}
/**
* 獲得需忽略的記錄數(shù)
* @param paramObject
* @return
*/
public static int getSkipResults(Object paramObject){
if(paramObject instanceof DynamicBean){
Object temp = ((DynamicBean)paramObject).get("skipResults");
return (temp == null) ? IBATIS_NO_SKIPPED_RESULTS : (Integer)temp;
}
if(paramObject instanceof Map){
Object temp = ((Map)paramObject).get("skipResults");
return (temp == null) ? IBATIS_NO_SKIPPED_RESULTS : (Integer)temp;
}
try {
return Integer.valueOf(BeanUtils.getProperty(paramObject, "skipResults"));
} catch (Exception e) {
if(debug)
System.out.println("in PagingUtils.getSkipResults() -- >> Cannot find value for property skipResults");
}
return IBATIS_NO_SKIPPED_RESULTS;
}
/**
* 獲得欲獲取的最大記錄數(shù)
* @param paramObject
* @return
*/
public static int getMaxResults(Object paramObject){
if(paramObject instanceof DynamicBean){
Object temp = ((DynamicBean)paramObject).get("maxResults");
return (temp == null) ? IBATIS_NO_MAXIMUM_RESULTS : (Integer)temp;
}
if(paramObject instanceof Map){
Object temp = ((Map)paramObject).get("maxResults");
return (temp == null) ? IBATIS_NO_MAXIMUM_RESULTS : (Integer)temp;
}
try {
return Integer.valueOf(BeanUtils.getProperty(paramObject, "maxResults"));
} catch (Exception e) {
if(debug)
System.out.println("in PagingUtils.getMaxResults() -- >> Cannot find value for property maxResults");
}
return IBATIS_NO_MAXIMUM_RESULTS;
}
private static final int IBATIS_NO_SKIPPED_RESULTS = 0; //== SqlExecutor.NO_SKIPPED_RESULTS
private static final int IBATIS_NO_MAXIMUM_RESULTS = -999999; //== SqlExecutor.NO_MAXIMUM_RESULTS
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -