本文整理汇总了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;
}