From 177249c76aeea0b4bf8d8816d4994e3b445b45ce Mon Sep 17 00:00:00 2001 From: huanghongfa <huanghongfa123456> Date: 星期四, 02 九月 2021 10:39:34 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/zzj' into zzj --- springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/CopyUtil.java | 120 ++++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 68 insertions(+), 52 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/CopyUtil.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/CopyUtil.java index dc2b8c8..a2c41ed 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/CopyUtil.java +++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/CopyUtil.java @@ -1,19 +1,20 @@ package com.panzhihua.common.utlis; -import cn.hutool.core.bean.BeanUtil; -import com.alibaba.fastjson.JSONObject; -import com.esotericsoftware.reflectasm.MethodAccess; -import lombok.extern.slf4j.Slf4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeanUtils; -import org.springframework.util.StringUtils; - import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.util.StringUtils; + +import com.alibaba.fastjson.JSONObject; +import com.esotericsoftware.reflectasm.MethodAccess; + +import cn.hutool.core.bean.BeanUtil; +import lombok.extern.slf4j.Slf4j; /** * 通用情况拷贝 @@ -38,7 +39,9 @@ } /** - * <p>对数组进行拷贝 </p> + * <p> + * 对数组进行拷贝 + * </p> * * @author tkq * @date 2018年12月19日 @@ -50,7 +53,7 @@ if (desc.isEmpty()) { return new ArrayList<>(); } - //创建返回对象 + // 创建返回对象 List<T> targetList = new ArrayList<>(desc.size()); for (Object des : desc) { if (null != des) { @@ -67,7 +70,9 @@ } /** - * <p>对数组进行拷贝 </p> + * <p> + * 对数组进行拷贝 + * </p> * * @author manailin * @date 2018年12月19日 @@ -79,7 +84,7 @@ if (desc.isEmpty()) { return new ArrayList<>(); } - //创建返回对象 + // 创建返回对象 List<T> targetList = new ArrayList<>(desc.size()); for (Object des : desc) { if (null != des) { @@ -118,8 +123,10 @@ /** * 进行复制方法 * - * @param dataSource 源目标对象 - * @param target 目标对象 + * @param dataSource + * 源目标对象 + * @param target + * 目标对象 * @author tkq * @date 14:37 2019-11-13 */ @@ -162,7 +169,8 @@ /** * 单例模式 * - * @param object 实体对象 + * @param object + * 实体对象 * @return MethodAccess * @author tkq * @date 14:36 2019/4/10 @@ -172,8 +180,8 @@ synchronized (name) { MethodAccess methodAccess = MethodAccess.get(name); Class<?> className = object.getClass(); - Set<Field> fields =new HashSet<>(); - for(;className != Object.class ; className = className.getSuperclass()) { + Set<Field> fields = new HashSet<>(); + for (; className != Object.class; className = className.getSuperclass()) { fields.addAll(Arrays.asList(className.getDeclaredFields())); } List<String> fieldList = new ArrayList<>(fields.size()); @@ -204,48 +212,52 @@ /** * @description 复制属性 - * @param source 源数据 - * @param targetClass 目标对象类型 - * @return - * @author weifei - * @date 2020/8/20 10:38 + * @param source + * 源数据 + * @param targetClass + * 目标对象类型 + * @return + * @author weifei + * @date 2020/8/20 10:38 */ - public static <T,K> K copyProperties(T source,Class<K> targetClass){ - if(source == null || targetClass == null){ + public static <T, K> K copyProperties(T source, Class<K> targetClass) { + if (source == null || targetClass == null) { return null; } - //创建对象 + // 创建对象 try { K k = targetClass.newInstance(); - //复制对象 - BeanUtils.copyProperties(source,k); + // 复制对象 + BeanUtils.copyProperties(source, k); return k; } catch (Exception e) { - throw new RuntimeException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } /** * @description 复制属性 - * @param source 源数据 - * @param targetClass 目标对象类型 - * @return - * @author weifei - * @date 2020/12/16 10:12 + * @param source + * 源数据 + * @param targetClass + * 目标对象类型 + * @return + * @author weifei + * @date 2020/12/16 10:12 */ - public static <T,K> List<K> copyProperties(List<T> source,Class<K> targetClass){ - if(source == null || targetClass == null){ + public static <T, K> List<K> copyProperties(List<T> source, Class<K> targetClass) { + if (source == null || targetClass == null) { return null; } List<K> returnValue = new ArrayList<>(); try { source.forEach(s -> { K k = copyProperties(s, targetClass); - if(k != null){ + if (k != null) { returnValue.add(k); } }); - }catch (Exception e){ + } catch (Exception e) { throw new RuntimeException(e.getMessage()); } return returnValue; @@ -253,31 +265,35 @@ /** * @description 深度复制对象 - * @param source 元数据 - * @param targetClass 目标对象类型 - * @return - * @author weifei - * @date 2021/3/1 14:21 + * @param source + * 元数据 + * @param targetClass + * 目标对象类型 + * @return + * @author weifei + * @date 2021/3/1 14:21 */ - public static <T,K> K deepCopyObject(T source,Class<K> targetClass){ - if(source == null || targetClass == null){ + public static <T, K> K deepCopyObject(T source, Class<K> targetClass) { + if (source == null || targetClass == null) { return null; } - return JSONObject.parseObject(JSONObject.toJSONBytes(source),targetClass); + return JSONObject.parseObject(JSONObject.toJSONBytes(source), targetClass); } /** * @description 深度复制list对象 - * @param source 元数据 - * @param targetClass 目标对象类型 + * @param source + * 元数据 + * @param targetClass + * 目标对象类型 * @return - * @author weifei + * @author weifei * @date 2021/3/1 14:26 */ - public static <T,K> List<K> deepCopyListObject(List<T> source,Class<K> targetClass){ - if(source == null || targetClass == null){ + public static <T, K> List<K> deepCopyListObject(List<T> source, Class<K> targetClass) { + if (source == null || targetClass == null) { return null; } - return JSONObject.parseArray(JSONObject.toJSONString(source),targetClass); + return JSONObject.parseArray(JSONObject.toJSONString(source), targetClass); } } -- Gitblit v1.7.1