实体类复制的工具 spring-beans-5.2.4.RELEASE.jar
BeanUtils.copyProperties(原实体, 目标实体);
BeanUtils是org.apache.commons.beanutils下的
BeanUtils.describe和PropertyUtils.describe都是将对象转换成Map,如果对象的字段存在数组或者集合类型的,使用PropertyUtils.describe。
PropertyUtils是调用的PropertyUtilsBean的这个方法,该方法读取属性值(调用getXxx方法)之后,value不做转化
而BeanUtils调用的是BeanUtilsBean的这个getNestedProperty方法,该方法在读取值之后,会再调用一次(getConvertUtils().convert(value));,进行类型转化成String。
因此BeanUtils.describe转化出来的Map的value都是String
Spring-Beans中的BeanUtils与PropertyUtils对象属性描述差异
本文讨论了Spring-Beans库中BeanUtils.copyProperties方法与PropertyUtils.describe的差异,重点在于处理对象字段包含数组或集合时,BeanUtils会进行类型转化,而PropertyUtils则不。
2203

被折叠的 条评论
为什么被折叠?



