add
yj
2024-12-05 b9900893177c78fc559223521fe839aa21000017
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
package com.dobbinsoft.fw.support.utils;
 
import org.springframework.beans.BeanUtils;
 
import java.util.Arrays;
import java.util.stream.Collectors;
 
public class FwBeanUtils {
 
    public static void copyProperties(Object source, Object target) {
        BeanUtils.copyProperties(source, target);
    }
 
    public static void copyProperties(Object source, Object target, String ...ignore) {
        BeanUtils.copyProperties(source, target, ignore);
    }
 
    public static void copyPropertiesFields(Object source, Object target, String ...fields) {
        Object[] objects = Arrays.stream(target.getClass().getFields()).map(item -> item.getName()).filter(item -> {
            boolean exist = false;
            for (String f : fields) {
                if (f.equals(item)) {
                    exist = true;
                }
            }
            return !exist;
        }).collect(Collectors.toList()).toArray();
        BeanUtils.copyProperties(source, target, (String[]) objects);
    }
 
}