一、根据方法名及类对象进行操作
public <T> Object grabData(T proxyObject, String methodName, Map<String, Object> paramMap) {
Object o = null;
try {
Class cls = Class.forName(proxyObject.getClass().getName());
Method mth = cls.getMethod(methodName, Map.class);
o = mth.invoke(proxyObject, paramMap);
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
二、获取对象的属性并遍历
public <T> void getFields(T t){
try {
Field[] fields = t.getClass().getDeclaredFields();
for (Field field : fields) {
FieldConvert annotation = field.getAnnotation(FieldConvert.class);
field.setAccessible(true);
System.out.println("属性名" + field.getName() + ",属性值" + field.get(t));
}
} catch (Exception e) {
e.printStackTrace();
}
}