import cn.hutool.core.collection.CollectionUtil;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @author lijj
* @date 2020-05-12
*/
public class CopyUtil {
public static <T> T copy(Object source,Class<T> clazz){
if (source==null){
return null;
}
T obj=null;
try {
obj=clazz.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
BeanUtils.copyProperties(source,obj);
return obj;
}
public static <T> List<T> copyList(List source,Class<T> clazz){
List<T> target=new ArrayList<>();
if (!CollectionUtil.isEmpty(source)){
for (Object c:source){
T obj=copy(c,clazz);
target.add(obj);
}
}
return target;
}
}