From 667ad269714030ff856a03f0239807c6c13ef267 Mon Sep 17 00:00:00 2001 From: yexuejc007 Date: Thu, 15 Jun 2023 14:24:05 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20ObjUtil.copy=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=88=E5=8D=B3=E4=BD=BFcopy=E4=B8=8D?= =?UTF-8?q?=E6=88=90=E5=8A=9F=EF=BC=8C=E4=B9=9F=E4=B8=8D=E6=8A=A5=E9=94=99?= =?UTF-8?q?=EF=BC=8C=E5=87=BA=E8=AD=A6=E5=91=8A=E6=97=A5=E5=BF=97=EF=BC=89?= =?UTF-8?q?=E3=80=82PR=EF=BC=9Acopy=E6=BA=90=E5=92=8C=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E4=B8=AD=E7=9A=84=E5=B1=9E=E6=80=A7=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=8D=E4=B8=80=E8=87=B4=EF=BC=8Ccopy=E4=B8=8D?= =?UTF-8?q?=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yexuejc/base/util/ObjUtil.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/yexuejc/base/util/ObjUtil.java b/src/main/java/com/yexuejc/base/util/ObjUtil.java index d11c9ca..a5d96b2 100644 --- a/src/main/java/com/yexuejc/base/util/ObjUtil.java +++ b/src/main/java/com/yexuejc/base/util/ObjUtil.java @@ -8,6 +8,8 @@ import java.lang.reflect.Method; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; /** @@ -20,6 +22,8 @@ import java.util.stream.Collectors; * @date 2018/12/28 15:54 */ public class ObjUtil { + private static Logger log = Logger.getLogger(ObjUtil.class.getName()); + private ObjUtil() { } @@ -299,7 +303,9 @@ public class ObjUtil { } catch (NoSuchFieldException e) { } } catch (Exception e) { - throw new RuntimeException(e); + log.warning(lowerCaseFirstChar(f.getName()) + " field copy failed. " + e); + log.log(Level.FINER, lowerCaseFirstChar(f.getName()) + + " field copy failed. The exception information is as follows:", e); } }); return o; @@ -321,8 +327,9 @@ public class ObjUtil { List getterMethods = getAllGetterMethods(source.getClass(), "get"); O o = targetClass.getDeclaredConstructor().newInstance(); getterMethods.forEach(method -> { + + String fieldName = method.getName().replace("get", ""); try { - String fieldName = method.getName().replace("get", ""); Object v = method.invoke(source); if (invokeSetter) { try { @@ -344,7 +351,9 @@ public class ObjUtil { } } } catch (Exception e) { - throw new RuntimeException(e); + log.warning(lowerCaseFirstChar(fieldName) + " field copy failed. " + e); + log.log(Level.FINER, lowerCaseFirstChar(fieldName) + + " field copy failed. The exception information is as follows:\n", e); } }); return o;