package com.doumee.core.utils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import java.util.List;
|
import java.util.function.Supplier;
|
import java.util.stream.Collectors;
|
|
/**
|
* Created by IntelliJ IDEA.
|
*
|
* @Author : Rk
|
* @create 2025/12/12 9:31
|
*/
|
public class ListUtil {
|
|
public static <S, T> List<T> copyProperties(List<S> sources, Supplier<T> target) {
|
return sources.stream().map(source -> {
|
T t = target.get();
|
BeanUtils.copyProperties(source, t);
|
return t;
|
}).collect(Collectors.toList());
|
}
|
|
public static <S, T> List<T> copyListProperties(List<S> sources, Class<T> target) {
|
return sources.stream().map(source -> {
|
T t;
|
try {
|
t = target.newInstance();
|
} catch (Exception e) {
|
e.printStackTrace();
|
return null;
|
}
|
BeanUtils.copyProperties(source, t);
|
return t;
|
}).collect(Collectors.toList());
|
}
|
|
}
|