PropertyUtils.copyProperties和BeanUtils.copyProperties使用区别:
public static void copyProperties(Object dest, Object orig) {
try {
PropertyUtils.copyProperties(dest, orig);
} catch (IllegalAccessException | InvocationTargetException
| NoSuchMethodException e) {
throw new IllegalArgumentException(e);
}
public static void copyPropertiesByBean(Object dest, Object orig) {
try {
BeanUtils.copyProperties(dest, orig);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
BeanUtils提供对Java反射和自省API的包装。其主要目的是利用反射机制对JavaBean的属性进行处理。一个JavaBean通常包含了大量的属性,很多情况下,对JavaBean的处理导致大量get/set代码堆积,增加了代码长度和阅读代码的难度。
使用PropertyUtils.copyProperties()拷贝一个bean中的属性到另一个bean中,第一个参数是目标bean,第二个参数是源bean。
Maven依赖:
commons-beanutils commons-beanutils1.9.3
推荐(深入了解):
BeanUtils.copyProperties与PropertyUtils.copyProperties用法及区别
commons-beanutils使用介绍



