public class DataTransformUtil<T1, T2> {
public static <T1, T2> void transform(T1 source, T2 target) {
try {
PropertyUtils.copyProperties(target, source);
} catch (Exception e) {
logger.error(e);
}
}
public static <T1, T2> List<T2> transformList(List<T1> sources, Class<T2> classObj) {
List<T2> targets = new ArrayList<>();
try {
for (T1 source : sources) {
T2 target = classObj.newInstance();
transform(source, target);
targets.add(target);
}
} catch (Exception e) {
logger.error(e);
}
return targets;
}
}