public class BeanCopiers extends Object
| 构造器和说明 |
|---|
BeanCopiers() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> T |
copy(Object source,
Class<T> targetType) |
static void |
copy(Object source,
Object target)
Copy properties from source to target
1、名称相同而类型不同的属性不会被拷贝
2、注意:即使源类型是基本类型(int、short、char等),目标类型是其包装类型(Integer、Short、Character等),或反之,都不会被拷贝
3、源类和目标类有相同的属性(两者的getter都存在),但目标类的setter不存在:创建BeanCopier的时候抛异常
4、当类型不一致是需要convert进行类型转换:org.springframework.cglib.core.Converter
BeanUtils/PropertyUtils -> commons-beanutils:commons-beanutils
|
static <T> T |
copy(Object source,
Supplier<T> supplier) |
static org.springframework.cglib.beans.BeanCopier |
get(Class<?> sourceType,
Class<?> targetType) |
public static org.springframework.cglib.beans.BeanCopier get(Class<?> sourceType, Class<?> targetType)
public static void copy(Object source, Object target)
1、名称相同而类型不同的属性不会被拷贝 2、注意:即使源类型是基本类型(int、short、char等),目标类型是其包装类型(Integer、Short、Character等),或反之,都不会被拷贝 3、源类和目标类有相同的属性(两者的getter都存在),但目标类的setter不存在:创建BeanCopier的时候抛异常 4、当类型不一致是需要convert进行类型转换:org.springframework.cglib.core.Converter BeanUtils/PropertyUtils -> commons-beanutils:commons-beanutils
source - source objecttarget - target objectorg.apache.commons.beanutils.BeanUtils#copyProperties(Object, Object);,
org.apache.commons.beanutils.PropertyUtils#copyProperties(Object, Object);,
BeanUtils.copyProperties(Object, Object),
BeanCopier.create(Class, Class, boolean),
mapstructCopyright © 2023. All rights reserved.