diff --git a/src/com/platform/utils/BeanCopy.java b/src/com/platform/utils/BeanCopy.java index f6cee9fc..d992c602 100644 --- a/src/com/platform/utils/BeanCopy.java +++ b/src/com/platform/utils/BeanCopy.java @@ -1,6 +1,7 @@ package com.platform.utils; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -25,7 +26,7 @@ public class BeanCopy { * @throws NoSuchFieldException * @throws SecurityException */ - public static void copyBean(Object source, Object dst, String... params) throws Exception{ + public static void copyBean(Object source, Object dst, String... params){ if (dst.getClass().getSuperclass() == source.getClass()) { fatherCopyChild(source, dst, params); } @@ -45,14 +46,18 @@ public class BeanCopy { if (sourceFieldName.contains(name)) { field.setAccessible(true); Object value; - Method m = source.getClass().getMethod("get"+upperHeadChar(name)); - value = m.invoke(source); -// Field fie = source.getClass().getDeclaredField(name); -// fie.setAccessible(true); -// value = fie.get(source); - if (null != value) { - field.set(dst, value); - } + Method m; + try { + m = source.getClass().getMethod("get"+upperHeadChar(name)); + value = m.invoke(source); + // Field fie = source.getClass().getDeclaredField(name); + // fie.setAccessible(true); + // value = fie.get(source); + if (null != value) + field.set(dst, value); + } catch (Exception e) { + log.error(e.getStackTrace()); + } } } @@ -87,7 +92,7 @@ public class BeanCopy { } } - private static void fatherCopyChild(Object father, Object dst, String... params) throws Exception{ + private static void fatherCopyChild(Object father, Object dst, String... params){ List filter = new ArrayList(); filter.addAll(Arrays.asList(params)); if (dst.getClass().getSuperclass() == father.getClass()) { @@ -101,9 +106,14 @@ public class BeanCopy { } f.setAccessible(true); Class type = f.getType(); - Method m = faClass.getMethod("get"+upperHeadChar(f.getName())); - Object obj = m.invoke(father); - f.set(dst, obj); + Method m; + try { + m = faClass.getMethod("get"+upperHeadChar(f.getName())); + Object obj = m.invoke(father); + f.set(dst, obj); + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + log.error(e.getStackTrace()); + } } } }