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;