From 1ef9cfc1bf36ece9ef8dbbb273993dfc99b84762 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, 12 Jan 2023 16:52:25 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=96=B0=E5=A2=9E=20BeanCopyUtils#mapToM?= =?UTF-8?q?ap=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/utils/BeanCopyUtils.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 index 0717f355..63bbd712 100644 --- 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 @@ -12,6 +12,7 @@ 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; @@ -131,6 +132,25 @@ public class BeanCopyUtils { 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属性缓存
* 缓存用于防止多次反射造成的性能问题