Loading... **相同的:** 都是浅拷贝,都提供了copyProperties()方法,只要`属性名相同`就可以从源bean中拷贝值到目标bean中 **不同点:** BeanUtils.copyProperties`提供类型转换功能`,BeanUtils会调用默认的转换器(Converter)进行类型转换,所以在拷贝时能对八个基本类型间进行转换,不能转换时抛出错误 PropertyUtils.copyProperties`不提供类型转换功能`,即发现两个JavaBean的同名属性为不同类型时,会提示argument mistype异常。 ##### PropertyUtils.copyProperties(Object dest, Object orig); ### 实体间拷贝 ``` User user = new User(); user.setName("张三"); user.setAge(24); User user2 = new User(); PropertyUtils.copyProperties(user2, user); System.out.println(user2);//User [name=张三, age=24] ``` ### map和实体间拷贝 ``` User user3 = new User(); Map<String,Object> map = new HashMap<String, Object>(); map.put("name", "王五"); map.put("age", 25); PropertyUtils.copyProperties(user3, map); System.out.println(user3);//User [name=王五, age=25] ``` **转自:https://blog.csdn.net/u012894692/article/details/80087859** Last modification:August 10, 2021 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 感谢大佬投喂 啾咪~