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);
}
相关推荐
执笔论英雄7 分钟前
【RL】async原理
java·服务器·前端
z***94848 分钟前
Java进阶07 嵌套类
java·开发语言·python
python百炼成钢10 分钟前
43.Linux LCD驱动
java·linux·运维·驱动开发
w***H65010 分钟前
Springboot项目:使用MockMvc测试get和post接口(含单个和多个请求参数场景)
java·spring boot·后端
橘子编程10 分钟前
仓颉语言:华为新一代编程利器
java·c语言·开发语言·数据库·python·青少年编程
a***131411 分钟前
Spring Boot 条件注解:@ConditionalOnProperty 完全解析
java·spring boot·后端
axihaihai11 分钟前
maven的构建问题
java·linux·maven
tgethe12 分钟前
Java注解
java·后端
稚辉君.MCA_P8_Java15 分钟前
DeepSeek Java 多线程打印的12种实现方法
java·linux·后端·架构·maven
代码不停20 分钟前
Java栈题目练习
java·开发语言