From 5e3f504c8029929f29df25d8654dc02bd49ad7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Thu, 2 Mar 2023 23:37:21 +0800 Subject: [PATCH] =?UTF-8?q?remove=20=E7=A7=BB=E9=99=A4=20BeanCopyUtils=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=20=E4=B8=8E=20JDK17=20=E4=B8=8D?= =?UTF-8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .run/RuoYiApplication.run.xml | 10 - pom.xml | 5 - ruoyi-admin/pom.xml | 12 -- .../common/core/utils/BeanCopyUtils.java | 204 ------------------ 4 files changed, 231 deletions(-) delete mode 100644 .run/RuoYiApplication.run.xml delete mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/BeanCopyUtils.java diff --git a/.run/RuoYiApplication.run.xml b/.run/RuoYiApplication.run.xml deleted file mode 100644 index 12dacba2f..000000000 --- a/.run/RuoYiApplication.run.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/pom.xml b/pom.xml index b22fd6abf..64a5f253c 100644 --- a/pom.xml +++ b/pom.xml @@ -385,11 +385,6 @@ maven-surefire-plugin ${maven-surefire-plugin.version} - - -Dfile.encoding=UTF-8 - --add-opens java.base/java.lang=ALL-UNNAMED - --add-opens java.base/java.lang.invoke=ALL-UNNAMED - ${profiles.active} diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 8c7d365e2..3ef0a5880 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -120,13 +120,6 @@ org.apache.maven.plugins maven-jar-plugin ${maven-jar-plugin.version} - - - - java.base/java.lang java.base/java.lang.invoke - - - org.apache.maven.plugins @@ -135,11 +128,6 @@ false ${project.artifactId} - - - java.base/java.lang java.base/java.lang.invoke - - diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/BeanCopyUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/BeanCopyUtils.java deleted file mode 100644 index 0661d9e38..000000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/BeanCopyUtils.java +++ /dev/null @@ -1,204 +0,0 @@ -package com.ruoyi.common.core.utils; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.lang.SimpleCache; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.cglib.beans.BeanCopier; -import org.springframework.cglib.beans.BeanMap; -import org.springframework.cglib.core.Converter; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * bean深拷贝工具(基于 cglib 性能优异) - *

- * 重点 cglib 不支持 拷贝到链式对象 - * 例如: 源对象 拷贝到 目标(链式对象) - * 请区分好`浅拷贝`和`深拷贝`再做使用 - * - * @author Lion Li - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class BeanCopyUtils { - - /** - * 单对象基于class创建拷贝 - * - * @param source 数据来源实体 - * @param desc 描述对象 转换后的对象 - * @return desc - */ - public static V copy(T source, Class desc) { - if (ObjectUtil.isNull(source)) { - return null; - } - if (ObjectUtil.isNull(desc)) { - return null; - } - final V target = ReflectUtil.newInstanceIfPossible(desc); - return copy(source, target); - } - - /** - * 单对象基于对象创建拷贝 - * - * @param source 数据来源实体 - * @param desc 转换后的对象 - * @return desc - */ - public static V copy(T source, V desc) { - if (ObjectUtil.isNull(source)) { - return null; - } - if (ObjectUtil.isNull(desc)) { - return null; - } - BeanCopier beanCopier = BeanCopierCache.INSTANCE.get(source.getClass(), desc.getClass(), null); - beanCopier.copy(source, desc, null); - return desc; - } - - /** - * 列表对象基于class创建拷贝 - * - * @param sourceList 数据来源实体列表 - * @param desc 描述对象 转换后的对象 - * @return desc - */ - public static List copyList(List sourceList, Class desc) { - if (ObjectUtil.isNull(sourceList)) { - return null; - } - if (CollUtil.isEmpty(sourceList)) { - return CollUtil.newArrayList(); - } - return StreamUtils.toList(sourceList, source -> { - V target = ReflectUtil.newInstanceIfPossible(desc); - copy(source, target); - return target; - }); - } - - /** - * bean拷贝到map - * - * @param bean 数据来源实体 - * @return map对象 - */ - @SuppressWarnings("unchecked") - public static Map copyToMap(T bean) { - if (ObjectUtil.isNull(bean)) { - return null; - } - return BeanMap.create(bean); - } - - /** - * map拷贝到bean - * - * @param map 数据来源 - * @param beanClass bean类 - * @return bean对象 - */ - public static T mapToBean(Map map, Class beanClass) { - if (MapUtil.isEmpty(map)) { - return null; - } - if (ObjectUtil.isNull(beanClass)) { - return null; - } - T bean = ReflectUtil.newInstanceIfPossible(beanClass); - return mapToBean(map, bean); - } - - /** - * map拷贝到bean - * - * @param map 数据来源 - * @param bean bean对象 - * @return bean对象 - */ - public static T mapToBean(Map map, T bean) { - if (MapUtil.isEmpty(map)) { - return null; - } - if (ObjectUtil.isNull(bean)) { - return null; - } - BeanMap.create(bean).putAll(map); - return bean; - } - - /** - * map拷贝到map - * - * @param map 数据来源 - * @param clazz 返回的对象类型 - * @return map对象 - */ - public static Map mapToMap(Map map, Class clazz) { - if (MapUtil.isEmpty(map)) { - return null; - } - if (ObjectUtil.isNull(clazz)) { - return null; - } - Map copyMap = new LinkedHashMap<>(map.size()); - map.forEach((k, v) -> copyMap.put(k, copy(v, clazz))); - return copyMap; - } - - /** - * BeanCopier属性缓存
- * 缓存用于防止多次反射造成的性能问题 - * - * @author Looly - * @since 5.4.1 - */ - public enum BeanCopierCache { - /** - * BeanCopier属性缓存单例 - */ - INSTANCE; - - private final SimpleCache cache = new SimpleCache<>(); - - /** - * 获得类与转换器生成的key在{@link BeanCopier}的Map中对应的元素 - * - * @param srcClass 源Bean的类 - * @param targetClass 目标Bean的类 - * @param converter 转换器 - * @return Map中对应的BeanCopier - */ - public BeanCopier get(Class srcClass, Class targetClass, Converter converter) { - final String key = genKey(srcClass, targetClass, converter); - return cache.get(key, () -> BeanCopier.create(srcClass, targetClass, converter != null)); - } - - /** - * 获得类与转换器生成的key - * - * @param srcClass 源Bean的类 - * @param targetClass 目标Bean的类 - * @param converter 转换器 - * @return 属性名和Map映射的key - */ - private String genKey(Class srcClass, Class targetClass, Converter converter) { - final StringBuilder key = StrUtil.builder() - .append(srcClass.getName()).append('#').append(targetClass.getName()); - if (null != converter) { - key.append('#').append(converter.getClass().getName()); - } - return key.toString(); - } - } - -}