rk
2025-12-15 12d724c247e4f7dcb77b3a94891ccf4d86b53cfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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());
    }
 
}