java 两个list之间复制(beanUtils的copyproperties)

复制代码
public static <T> List<T> copyPropertiesOfList(List<?> sourceList, Class<T> targetClass, boolean useConverter) {
    if (CollectionUtils.isEmpty(sourceList)) {
        return Collections.emptyList();
    }
    List<T> resultList = new ArrayList<>(sourceList.size());
    for (Object o : sourceList) {
        T t = null;
        try {
            t = targetClass.newInstance();
            copyPropertiesOfList(o, t, useConverter);
            resultList.add(t);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return resultList;
}

private static <T>void copyPropertiesOfList(Object soruces, T target, boolean useConverter){
    if (useConverter) copyProperties(soruces, target, useConverter);
    else copyProperties(soruces, target);
}
相关推荐
Pluchon16 小时前
硅基计划4.0 算法 二叉树深搜(DFS)
java·数据结构·算法·leetcode·深度优先·剪枝
9号达人16 小时前
if-else 优化的折中思考:不是消灭分支,而是控制风险
java·后端·面试
不知道累,只知道类17 小时前
Java 在AWS上使用SDK凭证获取顺序
java·aws
咖啡Beans17 小时前
SpringBoot2.7集成Swagger3.0
java·swagger
聪明的笨猪猪17 小时前
Java JVM “垃圾回收(GC)”面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
Moniane18 小时前
时序数据库全面重构指南
java·后端·struts
whm277718 小时前
Visual Basic 值传递与地址传递
java·开发语言·数据结构
没有bug.的程序员18 小时前
云原生与分布式架构的完美融合:从理论到生产实践
java·分布式·微服务·云原生·架构
村口张大爷18 小时前
Spring Boot 初始化钩子
java·spring boot·后端
x_feng_x18 小时前
Java从入门到精通 - 集合框架(二)
java·开发语言·windows