/**
* 获取(属性名,类型)数组
* */
public static Map<Object,Object> getFiledName(Object o){
Field[] fields = o.getClass().getDeclaredFields();
Map<Object,Object> map = new HashMap<>(fields.length);
for(int i=0;i<fields.length;i++){
map.put(fields[i].getName(),fields[i].getType().toString());
}
return map;
}
/* 根据属性名获取属性值
* */
public static Object getFieldValueByName(String fieldName, Object o) {
try {
String firstLetter = fieldName.substring(0, 1).toUpperCase();
String getter = "get" + firstLetter + fieldName.substring(1);
Method method = o.getClass().getMethod(getter, new Class[] {});
Object value = method.invoke(o, new Object[] {});
return value;
} catch (Exception e) {
return null;
}
}