From ba04d420faf2e92ab8b41eae5780129f8ae2471c Mon Sep 17 00:00:00 2001 From: dongsk Date: Tue, 12 Mar 2024 12:48:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7DAP=E7=89=88=E6=9C=AC5.2.0.10?= =?UTF-8?q?29=E5=88=B05.2.0.1085?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/infra/common/utils/BeanCopyUtil.java | 66 ------------------- demo-athenaopt_backend/pom.xml | 3 +- 2 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/BeanCopyUtil.java diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/BeanCopyUtil.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/BeanCopyUtil.java deleted file mode 100644 index 52ad492..0000000 --- a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/BeanCopyUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.digiwin.athena.app.infra.common.utils; - -import com.digiwin.app.container.exceptions.DWRuntimeException; -import net.sf.cglib.beans.BeanCopier; -import net.sf.cglib.beans.BeanMap; -import org.springframework.objenesis.ObjenesisStd; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -public final class BeanCopyUtil { - private BeanCopyUtil() { - } - - private static ThreadLocal objenesisStdThreadLocal = ThreadLocal.withInitial(ObjenesisStd::new); - private static ConcurrentHashMap, ConcurrentHashMap, BeanCopier>> cache = new ConcurrentHashMap<>(); - - - public static T copy(Object source, Class target) { - return copy(source, objenesisStdThreadLocal.get().newInstance(target)); - } - - public static T copy(Object source, T target) { - BeanCopier beanCopier = getCacheBeanCopier(source.getClass(), target.getClass()); - beanCopier.copy(source, target, null); - return target; - } - - public static List copyList(List sources, Class target) { - if (sources.isEmpty()) { - return Collections.emptyList(); - } - - ArrayList list = new ArrayList<>(sources.size()); - ObjenesisStd objenesisStd = objenesisStdThreadLocal.get(); - for (Object source : sources) { - if (source == null) { - throw new DWRuntimeException("转换异常"); - } - T newInstance = objenesisStd.newInstance(target); - BeanCopier beanCopier = getCacheBeanCopier(source.getClass(), target); - beanCopier.copy(source, newInstance, null); - list.add(newInstance); - } - return list; - } - - public static T mapToBean(Map source, Class target) { - T bean = objenesisStdThreadLocal.get().newInstance(target); - BeanMap beanMap = BeanMap.create(bean); - beanMap.putAll(source); - return bean; - } - - public static Map beanToMap(T source) { - return BeanMap.create(source); - } - - private static BeanCopier getCacheBeanCopier(Class source, Class target) { - ConcurrentHashMap, BeanCopier> copierConcurrentHashMap = cache.computeIfAbsent(source, aClass -> new ConcurrentHashMap<>(16)); - return copierConcurrentHashMap.computeIfAbsent(target, aClass -> BeanCopier.create(source, target, false)); - } -} diff --git a/demo-athenaopt_backend/pom.xml b/demo-athenaopt_backend/pom.xml index 256f35c..486bf64 100644 --- a/demo-athenaopt_backend/pom.xml +++ b/demo-athenaopt_backend/pom.xml @@ -32,9 +32,10 @@ https://repo.digiwincloud.com.cn/maven 1.1.0.0 5.0.5.RELEASE - 5.2.0.1029 + 5.2.0.1085 2.8.6 1.05 + 4.1.67.Final