拷贝list的工具,解决beanutils拷贝list结果为空的问题

99 阅读1分钟
public class ListCopyUtil extends BeanUtils {

    /**
     * list集合数据的拷贝
     * @param source: 数据源类
     * @param target: 目标类::new(eg: UserVO::new)
     * @return 返回拷贝结果
     */
    public static <S, T> List<T> copyListProperties(List<S> source, Supplier<T> target) {
        List<T> list = new ArrayList<>(source.size());
        for (S s : source) {
            T t = target.get();
            copyProperties(s, t);
            list.add(t);
        }
        return list;
    }
}