本文整理匯總了Java中org.apache.commons.beanutils.PropertyUtils.getNestedProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java PropertyUtils.getNestedProperty方法的具體用法?Java PropertyUtils.getNestedProperty怎麽用?Java PropertyUtils.getNestedProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.beanutils.PropertyUtils
的用法示例。
在下文中一共展示了PropertyUtils.getNestedProperty方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: filterByDate
import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
/**
* Default String contains filter processing.
*
* @param item Photo to consider for inclusion.
* @param filterProperty Filter property name used to determine which photo field to compare with.
* @param filterValue Value of the filter.
* @return True if photo should be included in the resultant list to display.
*/
protected boolean filterByDate(T item, String filterProperty, Object filterValue) {
FastDateFormat dateInstance = FastDateFormat.getInstance(MM_DD_YY_PATTERN);
try {
Object fieldValue = PropertyUtils.getNestedProperty(item, filterProperty);
Date theDate = (Date) fieldValue;
String dateStr = dateInstance.format((Date) fieldValue);
if (filterValue == null || (dateInstance.format((Date) fieldValue).contains(filterValue.toString()))) {
return true;
}
} catch (Exception e) {
log.error("Failed to filter. ", e);
}
return false;
}
示例2: compare
import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
@Override
public int compare(T item1, T item2) {
try {
Comparable fieldValue1 = (Comparable) PropertyUtils.getNestedProperty(item1, sortField);
Comparable fieldValue2 = (Comparable)PropertyUtils.getNestedProperty(item2, sortField);
int retVal = ObjectUtils.compare(fieldValue1, fieldValue2);
if (SortOrder.DESCENDING.equals(sortOrder)) {
retVal = -retVal;
}
return retVal;
}
catch (Exception e) {
log.error("Failed to sort with sortField " + sortField, e);
}
return 0;
}
示例3: getNestedProperty
import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
public static Object getNestedProperty(Object data, String name) {
try {
if (!name.contains(".")) {
return PropertyUtils.getProperty(data, name);
}
if (name.contains("[")) {
String[] names = name.split("\\.", 2);
Object obj = null;
try {
obj = PropertyUtils.getIndexedProperty(data, names[0]);
} catch (NullPointerException npe) {
// アクセスする配列オブジェクトがnullの場合
obj = null;
}
if (obj == null) {
return null;
}
return getNestedProperty(obj, names[1]);
}
try {
return PropertyUtils.getNestedProperty(data, name);
} catch (NestedNullException nne) {
// ネストしたプロパティの途中がnullの場合はエラーとせず
// nullを返す
return null;
}
} catch (Exception e) {
throw new ApplicationFatalRuntimeException("invalid property : " + name, e);
}
}
示例4: filterByStringType
import org.apache.commons.beanutils.PropertyUtils; //導入方法依賴的package包/類
/**
* Default String contains filter processing.
*
* @param item Photo to consider for inclusion.
* @param filterProperty Filter property name used to determine which photo field to compare with.
* @param filterValue Value of the filter.
* @return True if photo should be included in the resultant list to display.
*/
protected boolean filterByStringType(T item, String filterProperty, Object filterValue) {
try {
Object fieldValue = PropertyUtils.getNestedProperty(item, filterProperty);
if (filterValue == null || (fieldValue != null && fieldValue.toString().toLowerCase().contains(filterValue.toString().toLowerCase()))) {
return true;
}
} catch (Exception e) {
log.error("Failed to filter. ", e);
}
return false;
}