String attr ="ss";
Field fields[] = obj.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.getName().equals(attr)) {
field.setAccessible(true);
Object attrValue = field.get(obj);
if (attrValue != null) {
} else {
attrValue ="";
}
break;
}
}
/**
* 反射获取bean属性
*/
public static Object getFiledValue(Object obj, String filed) {
Object result = null;
try {
Class<?> clazz = obj.getClass();
PropertyDescriptor pd = new PropertyDescriptor(filed, clazz);
Method getMethod = pd.getReadMethod();
if (pd != null) {
result = getMethod.invoke(obj);
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}