• Bean拷贝


    相当于C#的AutoMapper

    public class CloneUtils {
        /**
         * 拷贝对象
         * @param source
         * @param classType
         * @return
         */
        public static <T, E> E clone(T source, Class<E> classType) {
    
            if (source == null) {
                return null;
            }
            E targetInstance;
            try {
                targetInstance = classType.newInstance();
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            BeanUtils.copyProperties(source, targetInstance);
            return targetInstance;
        }
    
        /**
         * 拷贝数组对象
         * @param sourceList
         * @param classType
         * @return
         */
        public static <T, E> List<E> batchClone(List<T> sourceList, Class<E> classType) {
            if (sourceList == null) {
                return null;
            }
            List<E> result = new ArrayList<>();
            int size = sourceList.size();
            for (int i = 0; i < size; i++) {
                result.add(clone(sourceList.get(i), classType));
            }
            return result;
        }
    }
  • 相关阅读:
    一分钟学会 ConstraintLayout 之从属性角度理解布局
    halcon采集一幅图像
    halcon连续采集图像
    LinearLayout布局
    Html input 标签
    Html 标签种类
    Html div 标签
    Html span 标签
    Html h1-h6 标签
    Html br 标签
  • 原文地址:https://www.cnblogs.com/fqybzhangji/p/10518237.html
Copyright © 2020-2023  润新知