/**
* 获取Bean的属性
* @param bean bean
* @param propertyName 属性名
* @return 属性值
*/
public static Object getProperty(Object bean, String propertyName) {
PropertyDescriptor pd = getPropertyDescriptor(bean.getClass(), propertyName);
if (pd == null) {
throw new RuntimeException("Could not read property '" + propertyName + "' from bean PropertyDescriptor is null");
}
Method readMethod = pd.getReadMethod();
if (readMethod == null) {
throw new RuntimeException("Could not read property '" + propertyName + "' from bean readMethod is null");
}
if (!readMethod.isAccessible()) {
readMethod.setAccessible(true);
}
try {
return readMethod.invoke(bean);
} catch (Throwable ex) {
throw new RuntimeException("Could not read property '" + propertyName + "' from bean", ex);
}
}
BeanUtils.java 文件源码
java
阅读 30
收藏 0
点赞 0
评论 0
项目:xmanager
作者:
评论列表
文章目录