@Test public void testCopyProperties() throws InvocationTargetException, IllegalAccessException { BusinessLog bean1 = new BusinessLog(); bean1.setOperationName("operationName test"); bean1.setOperation_type("operationName type"); bean1.setLogType("logTypevalue"); Log2 bean2 = new Log2(); System.out.println("复制前:" + bean1); System.out.println("复制前:" + bean2); BeanUtil.copyProperties(bean1, bean2, new PropertyFilter() { @Override public String Properties(String pro) { return StringUtil.remove(pro, "_").toLowerCase().replaceAll("yy", "ty"); } }); BeanUtil.copyPropertiesPeaceful(bean1, bean2, new PropertyFilter() { @Override public String Properties(String pro) { return StringUtil.remove(pro, "_").toLowerCase().replaceAll("yy", "ty"); } }); System.out.println("复制后:" + bean1); System.out.println("复制后:" + bean2); }
public static void copyProperties(Object srcBean, Object destBean) throws InvocationTargetException, IllegalAccessException { add(srcBean); add(destBean); Map<String, BeanStruct> srcMap = simpleProperties(srcBean); Map<String, BeanStruct> dstMap = simpleProperties(destBean); Map<String, BeanStruct> intersection = CollectionHelper.intersection(srcMap, dstMap); for (Map.Entry<String, BeanStruct> entry : intersection.entrySet()) { String key = entry.getKey(); Object value = readMethod(srcBean, getReadMethod(srcBean, key)); writeMethod(destBean, getWriteMethod(destBean, key), value); } }
BeanUtil { public static void copyProperties(Object srcBean, Object destBean) throws InvocationTargetException, IllegalAccessException { add(srcBean); add(destBean); Map<String, BeanStruct> srcMap = simpleProperties(srcBean); Map<String, BeanStruct> dstMap = simpleProperties(destBean); Map<String, BeanStruct> intersection = CollectionHelper.intersection(srcMap, dstMap); for (Map.Entry<String, BeanStruct> entry : intersection.entrySet()) { String key = entry.getKey(); Object value = readMethod(srcBean, getReadMethod(srcBean, key)); writeMethod(destBean, getWriteMethod(destBean, key), value); } } }
BeanUtil { public static void copyProperties(Object srcBean, Object destBean) throws InvocationTargetException, IllegalAccessException { add(srcBean); add(destBean); Map<String, BeanStruct> srcMap = simpleProperties(srcBean); Map<String, BeanStruct> dstMap = simpleProperties(destBean); Map<String, BeanStruct> intersection = CollectionHelper.intersection(srcMap, dstMap); for (Map.Entry<String, BeanStruct> entry : intersection.entrySet()) { String key = entry.getKey(); Object value = readMethod(srcBean, getReadMethod(srcBean, key)); writeMethod(destBean, getWriteMethod(destBean, key), value); } }  }
BeanUtil { public static void copyProperties(Object srcBean, Object destBean) throws InvocationTargetException, IllegalAccessException { add(srcBean); add(destBean); Map<String, BeanStruct> srcMap = simpleProperties(srcBean); Map<String, BeanStruct> dstMap = simpleProperties(destBean); Map<String, BeanStruct> intersection = CollectionHelper.intersection(srcMap, dstMap); for (Map.Entry<String, BeanStruct> entry : intersection.entrySet()) { String key = entry.getKey(); Object value = readMethod(srcBean, getReadMethod(srcBean, key)); writeMethod(destBean, getWriteMethod(destBean, key), value); } }  static void add(Object obj); static void add(Class clazz); static boolean hasProperty(Object bean, String pro); static boolean hasDeclaredProperty(Object bean, String pro); static boolean hasPropertyIgnoreCase(Object bean, String pro); static boolean hasPropertyFilter(Object bean, String pro, PropertyFilter filter); static Object getProperty(Object bean, String pro); static Object getPropertyPeaceful(Object bean, String pro); static Object getPropertyIgnoreCase(Object bean,
                                               String pro); static Object getPropertyIgnoreCasePeaceful(Object bean, String pro); static Object getPropertyFilter(Object bean, String pro,
                                           PropertyFilter filter); static Object getPropertyFilterPeaceful(Object bean, String pro, PropertyFilter filter); static void setProperty(Object bean, String pro,
                                   Object value); static void setPropertyPeaceful(Object bean, String pro, Object value); static void setPropertyIgnoreCase(Object bean, String pro,
                                             Object value); static void setPropertyIgnoreCasePeaceful(Object bean, String pro, Object value); static void setPropertyFilter(Object bean, String pro, Object value,
                                         PropertyFilter filter); static void setPropertyFilterPeaceful(Object bean, String pro, Object value, PropertyFilter filter); static void copyProperty(Object srcBean, Object destBean,
                                    String[] pros); static void copyPropertyPeaceful(Object srcBean, Object destBean, String[] pros); static void copyProperties(Object srcBean,
                                      Object destBean); static void copyPropertiesPeaceful(Object srcBean, Object destBean); static void copyPropertiesIgnoreCase(Object srcBean,
                                                Object destBean); static void copyPropertiesIgnoreCasePeaceful(Object srcBean, Object destBean); static void copyProperties(Object srcBean, Object destBean,
                                      PropertyFilter filter); static void copyPropertiesPeaceful(Object srcBean, Object destBean, PropertyFilter filter); }
BeanUtil { public static void copyProperties(Object srcBean, Object destBean) throws InvocationTargetException, IllegalAccessException { add(srcBean); add(destBean); Map<String, BeanStruct> srcMap = simpleProperties(srcBean); Map<String, BeanStruct> dstMap = simpleProperties(destBean); Map<String, BeanStruct> intersection = CollectionHelper.intersection(srcMap, dstMap); for (Map.Entry<String, BeanStruct> entry : intersection.entrySet()) { String key = entry.getKey(); Object value = readMethod(srcBean, getReadMethod(srcBean, key)); writeMethod(destBean, getWriteMethod(destBean, key), value); } }  static void add(Object obj); static void add(Class clazz); static boolean hasProperty(Object bean, String pro); static boolean hasDeclaredProperty(Object bean, String pro); static boolean hasPropertyIgnoreCase(Object bean, String pro); static boolean hasPropertyFilter(Object bean, String pro, PropertyFilter filter); static Object getProperty(Object bean, String pro); static Object getPropertyPeaceful(Object bean, String pro); static Object getPropertyIgnoreCase(Object bean,
                                               String pro); static Object getPropertyIgnoreCasePeaceful(Object bean, String pro); static Object getPropertyFilter(Object bean, String pro,
                                           PropertyFilter filter); static Object getPropertyFilterPeaceful(Object bean, String pro, PropertyFilter filter); static void setProperty(Object bean, String pro,
                                   Object value); static void setPropertyPeaceful(Object bean, String pro, Object value); static void setPropertyIgnoreCase(Object bean, String pro,
                                             Object value); static void setPropertyIgnoreCasePeaceful(Object bean, String pro, Object value); static void setPropertyFilter(Object bean, String pro, Object value,
                                         PropertyFilter filter); static void setPropertyFilterPeaceful(Object bean, String pro, Object value, PropertyFilter filter); static void copyProperty(Object srcBean, Object destBean,
                                    String[] pros); static void copyPropertyPeaceful(Object srcBean, Object destBean, String[] pros); static void copyProperties(Object srcBean,
                                      Object destBean); static void copyPropertiesPeaceful(Object srcBean, Object destBean); static void copyPropertiesIgnoreCase(Object srcBean,
                                                Object destBean); static void copyPropertiesIgnoreCasePeaceful(Object srcBean, Object destBean); static void copyProperties(Object srcBean, Object destBean,
                                      PropertyFilter filter); static void copyPropertiesPeaceful(Object srcBean, Object destBean, PropertyFilter filter);  }