import java.lang.reflect.Method;
public class EntityUtil {
/**
* 通过反射将src的值输出到target
* @param src
* @param target
* @return
* @throws Exception
*/
public static <T, F> F parseEntity(T src, F target) throws Exception{
Method[] srcMethods = src.getClass().getMethods();
Method[] targetMethod = target.getClass().getMethods();
for(Method m : srcMethods) {
if(m.getName().startsWith("get")) {
Object result = m.invoke(src);
for(Method mm : targetMethod) {
if(mm.getName().startsWith("set") && mm.getName().substring(3).
equals(m.getName().substring(3))) {
mm.invoke(target,result);
}
}
}
}
return target;
}
}