package com.wiki.utils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class CopyUtil {
public static <T> T copy(Object param, Class<T> target) {
if (param == null) {
return null;
}
T object = null;
try {
object = target.getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
return null;
}
BeanUtils.copyProperties(param, object);
return object;
}
public static <T> List<T> copyList(List paramList, Class<T> target) {
List<T> list = new ArrayList<>();
if (!CollectionUtils.isEmpty(paramList)) {
for (Object c : paramList) {
T obj = copy(c, target);
list.add(obj);
}
}
return list;
}
}