From c3e17b9bbeab77395f6eff9c26fb44415af58eee Mon Sep 17 00:00:00 2001 From: Parker Date: Wed, 28 Dec 2022 19:55:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4cglib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/opsli/common/utils/WrapperUtil.java | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/WrapperUtil.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/WrapperUtil.java index 13a7ed23..6f913da1 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/WrapperUtil.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/WrapperUtil.java @@ -15,9 +15,9 @@ */ package org.opsli.common.utils; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.extra.cglib.CglibUtil; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; @@ -35,54 +35,60 @@ import java.util.stream.Collectors; @Slf4j public final class WrapperUtil { - /** 私有化构造函数 */ - private WrapperUtil(){} + /** + * 私有化构造函数 + */ + private WrapperUtil() { + } /** * 转化对象 + * * @param source 源数据 * @param target 目标 - * @param 泛型 + * @param 泛型 * @return M */ - public static M transformInstance(Object source, Class target){ + public static M transformInstance(Object source, Class target) { return transformInstance(source, target, false); } /** * 转化集合对象 + * * @param source 源数据 * @param target 目标 - * @param 泛型 + * @param 泛型 * @return List */ - public static List transformInstance(Collection source, Class target){ + public static List transformInstance(Collection source, Class target) { return transformInstance(source, target, false); } /** * 克隆并且转化对象 - * @param source 源数据 - * @param target 目标 + * + * @param source 源数据 + * @param target 目标 * @param isClone 是否克隆 * @return M */ - public static M transformInstance(Object source, Class target, boolean isClone){ - if(source == null){ + public static M transformInstance(Object source, Class target, boolean isClone) { + if (source == null) { return null; } - if(isClone){ + if (isClone) { source = ObjectUtil.cloneIfPossible(source); } M m = null; try { - m = CglibUtil.copy(source, target); - }catch (Exception e){ - log.error(e.getMessage(),e); + m = BeanUtil.copyProperties(source, target); + } catch (Exception e) { + log.error(e.getMessage(), e); } return m; } @@ -90,14 +96,15 @@ public final class WrapperUtil { /** * 克隆并且转化集合对象 - * @param source 源数据 - * @param target 目标 + * + * @param source 源数据 + * @param target 目标 * @param isClone 是否克隆 - * @param M + * @param M * @return List */ - public static List transformInstance(Collection source, Class target, boolean isClone){ - if(CollUtil.isEmpty(source)){ + public static List transformInstance(Collection source, Class target, boolean isClone) { + if (CollUtil.isEmpty(source)) { return Lists.newArrayList(); } @@ -106,8 +113,8 @@ public final class WrapperUtil { toInstanceList = source.stream() .map((s) -> transformInstance(s, target, isClone)) .collect(Collectors.toList()); - }catch (Exception e){ - log.error(e.getMessage(),e); + } catch (Exception e) { + log.error(e.getMessage(), e); } return toInstanceList; } -- Gitee