| | |
| | | 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; |
| | | |
| | | /** |
| | | * 通用情况拷贝 |
| | |
| | | } |
| | | |
| | | /** |
| | | * <p>对数组进行拷贝 </p> |
| | | * <p> |
| | | * 对数组进行拷贝 |
| | | * </p> |
| | | * |
| | | * @author tkq |
| | | * @date 2018年12月19日 |
| | |
| | | if (desc.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | //创建返回对象 |
| | | // 创建返回对象 |
| | | List<T> targetList = new ArrayList<>(desc.size()); |
| | | for (Object des : desc) { |
| | | if (null != des) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * <p>对数组进行拷贝 </p> |
| | | * <p> |
| | | * 对数组进行拷贝 |
| | | * </p> |
| | | * |
| | | * @author manailin |
| | | * @date 2018年12月19日 |
| | |
| | | if (desc.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | //创建返回对象 |
| | | // 创建返回对象 |
| | | List<T> targetList = new ArrayList<>(desc.size()); |
| | | for (Object des : desc) { |
| | | if (null != des) { |
| | |
| | | /** |
| | | * 进行复制方法 |
| | | * |
| | | * @param dataSource 源目标对象 |
| | | * @param target 目标对象 |
| | | * @param dataSource |
| | | * 源目标对象 |
| | | * @param target |
| | | * 目标对象 |
| | | * @author tkq |
| | | * @date 14:37 2019-11-13 |
| | | */ |
| | |
| | | /** |
| | | * 单例模式 |
| | | * |
| | | * @param object 实体对象 |
| | | * @param object |
| | | * 实体对象 |
| | | * @return MethodAccess |
| | | * @author tkq |
| | | * @date 14:36 2019/4/10 |
| | |
| | | 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()); |
| | |
| | | |
| | | /** |
| | | * @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; |
| | |
| | | |
| | | /** |
| | | * @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); |
| | | } |
| | | } |