BeanCopy { public static void copyByMethod(Object src, Object dest) { if (ObjectUtil.isAnyNull(src, dest)) { return; } BeanInfo beanInfo = beanInfoCache.getBeanInfo(dest.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor destPd : propertyDescriptors) { PropertyDescriptor srcPd = beanInfoCache.getPropertyDescriptor(src.getClass(), destPd.getName()); if (srcPd == null) { continue; } Method readMethod = srcPd.getReadMethod(); Object value = ReflectionUtil.invokeMethod(readMethod, src); Method writeMethod = destPd.getWriteMethod(); ReflectionUtil.invokeMethod(writeMethod, dest, value); } }  static void copy(Object src, Object dest, boolean useAnnotation); static void copyProperties(Object src, Object dest); static void copyByAnnotation(Object src, Object dest); static void copyByMethod(Object src, Object dest);  }
@Test public void copyByMethod() { Abean bean = new Abean(); bean.setFooProp("ggg"); Abean acopied = new Abean(); BeanCopy.copyByMethod(bean, acopied); Assert.assertEquals("ggg", acopied.getFooProp()); Cbean src = new Cbean(); src.setS2("11111"); src.setS3("aaaaa"); Cbean dest = new Cbean(); BeanCopy.copyByMethod(src, dest); Assert.assertEquals("aaaaa", dest.getS3()); logger.info(dest); }