public class GetModelNameAndType {
public static <T> void testReflect(T model, T vo) throws Exception {
Field[] src = model.getClass().getDeclaredFields();
Field[] target = vo.getClass().getDeclaredFields();
Map<String, Object> temp = new HashMap<>();
for (int j = 0; j < src.length; j++) {
String srcName = src[j].getName();
srcName = srcName.substring(0, 1).toUpperCase() + srcName.substring(1);
Method m = model.getClass().getMethod("get" + srcName);
temp.put(srcName, m.invoke(model));
}
for (int i = 0; i < target.length; i++) {
String targetName = target[i].getName();
targetName = targetName.substring(0, 1).toUpperCase() + targetName.substring(1);
String type = target[i].getGenericType().toString();
if (type.equals("class java.lang.String")) {
if (temp.containsKey(targetName)) {
Method m1 = vo.getClass().getMethod("set" + targetName, String.class);
m1.invoke(vo, temp.get(targetName));
}
}
if (type.equals("class java.lang.Integer")) {
if (temp.containsKey(targetName)) {
Method m1 = vo.getClass().getMethod("set" + targetName, Integer.class);
m1.invoke(vo, temp.get(targetName));
}
}
if (type.equals("class java.util.Date")) {
if (temp.containsKey(targetName)) {
Method m1 = vo.getClass().getMethod("set" + targetName, Date.class);
m1.invoke(vo, temp.get(targetName));
}
}
if (type.equals("class java.lang.Long")) {
if (temp.containsKey(targetName)) {
Method m1 = vo.getClass().getMethod("set" + targetName, Long.class);
m1.invoke(vo, temp.get(targetName));
}
}
}
}
}