java 对象集合复制

此工具类相当于Spring里BeanUtils.copyProperties,此工具类比其速度要快,功能要强大(不接受反驳)

import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.impl.DefaultMapperFactory;

import java.util.List;

public class BeanCopyUtil {
    
    
    public static final MapperFacade MAPPER_FACADE;

    static {
    
    
        MAPPER_FACADE = new DefaultMapperFactory.Builder().build().getMapperFacade();
    }

    public static <S, D> D map(S source, Class<D> destinationClass) {
    
    
        return MAPPER_FACADE.map(source, destinationClass);
    }

    public static <S, D> void map(S source, D destination) {
    
    
        MAPPER_FACADE.map(source, destination);
    }

    public static  <S, D> List<D> mapAsList(Iterable<S> source, Class<D> destinationClass){
    
    
        return MAPPER_FACADE.mapAsList(source,destinationClass);
    }
}


List<QueryHistoryBadgeResBO> queryHistoryBadgeResBOList = collectDataList.stream().collect(Collectors.collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(QueryHistoryBadgeResBO::getDeviceMacAddr))), ArrayList::new));

需要导入依赖

        <dependency>
            <groupId>ma.glasnost.orika</groupId>
            <artifactId>orika-core</artifactId>
        </dependency>

帮助到您请点赞关注收藏谢谢!!

猜你喜欢

转载自blog.csdn.net/qq_42496238/article/details/109850500
今日推荐