public class BeanUtil
extends org.springframework.beans.BeanUtils
| Constructor and Description |
|---|
BeanUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
clone(T source)
浅拷贝
支持 map bean
|
static <T> List<T> |
copy(Collection<?> sourceList,
Class<T> targetClazz)
copy 列表对象,默认不使用Convert
支持 map bean copy
|
static <T> List<T> |
copy(Collection<?> sourceList,
List<T> targetList,
Class<T> targetClazz)
copy 列表对象,默认不使用Convert
支持 map bean copy
|
static <T> T |
copy(Object source,
Class<T> clazz)
copy 对象属性,默认不使用Convert
支持 map bean copy
|
static <T> T |
copy(Object source,
Class sourceClazz,
Class<T> targetClazz)
copy 对象属性,默认不使用Convert
支持 map bean copy
|
static void |
copy(Object source,
Object targetBean)
拷贝对象
支持 map bean copy
|
static void |
copyNonNull(Object source,
Object targetBean)
拷贝对象,source 属性做 null 判断,Map 不支持,map 会做 instanceof 判断,不会
支持 bean copy
|
static <T> List<T> |
copyProperties(Collection<?> sourceList,
Class<T> targetClazz)
Copy the property values of the given source bean into the target class.
|
static <T> T |
copyProperties(Object source,
Class<T> targetClazz)
Copy the property values of the given source bean into the target class.
|
static <T> List<T> |
copyWithConvert(Collection<?> sourceList,
Class<T> targetClazz)
拷贝列表并对不同类型属性进行转换
支持 map bean copy
|
static <T> T |
copyWithConvert(Object source,
Class<?> sourceClazz,
Class<T> targetClazz)
拷贝对象并对不同类型属性进行转换
支持 map bean copy
|
static <T> T |
copyWithConvert(Object source,
Class<T> targetClazz)
拷贝对象并对不同类型属性进行转换
支持 map bean copy
|
static <T> T |
deepClone(T source)
深度拷贝
|
static BeanDiff |
diff(Map<String,Object> src,
Map<String,Object> dist)
比较Map
|
static BeanDiff |
diff(Object src,
Object dist)
比较对象
|
static Class<?> |
forName(String clazzStr)
forName
|
static Object |
generator(Class<?> superclass,
BeanProperty... props)
给一个class添加字段
|
static Object |
generator(Object superBean,
BeanProperty... props)
给一个Bean添加字段
|
static Object |
getProperty(Object bean,
String propertyName)
获取Bean的属性, 支持 propertyName 多级 :test.user.name
|
static <T> T |
newInstance(Class<?> clazz)
实例化对象
|
static <T> T |
newInstance(String clazzStr)
实例化对象
|
static void |
setProperty(Object bean,
String propertyName,
Object value)
设置Bean属性, 支持 propertyName 多级 :test.user.name
|
static <T> T |
toBean(Map<String,Object> beanMap,
Class<T> valueType)
将map 转为 bean
|
static Map<String,Object> |
toMap(Object bean)
将对象装成map形式,map 不可写
|
static Map<String,Object> |
toNewMap(Object bean)
将对象装成map形式,map 可写
|
copyProperties, copyProperties, copyProperties, findDeclaredMethod, findDeclaredMethodWithMinimalParameters, findEditorByConvention, findMethod, findMethodWithMinimalParameters, findMethodWithMinimalParameters, findPrimaryConstructor, findPropertyForMethod, findPropertyForMethod, findPropertyType, getParameterNames, getPropertyDescriptor, getPropertyDescriptors, getResolvableConstructor, getWriteMethodParameter, instantiate, instantiateClass, instantiateClass, instantiateClass, isSimpleProperty, isSimpleValueType, resolveSignaturepublic static <T> T newInstance(Class<?> clazz)
T - 泛型标记clazz - 类public static <T> T newInstance(String clazzStr)
T - 泛型标记clazzStr - 类名public static Class<?> forName(String clazzStr)
clazzStr - 类名@Nullable public static Object getProperty(@Nullable Object bean, String propertyName)
bean - beanpropertyName - 属性名public static void setProperty(Object bean, String propertyName, Object value)
bean - beanpropertyName - 属性名value - 属性值@Nullable
public static <T> T clone(@Nullable
T source)
支持 map bean
T - 泛型标记source - 源对象@Nullable
public static <T> T deepClone(@Nullable
T source)
source - 待拷贝的对象@Nullable
public static <T> T copy(@Nullable
Object source,
Class<T> clazz)
支持 map bean copy
T - 泛型标记source - 源对象clazz - 类名@Nullable
public static <T> T copy(@Nullable
Object source,
Class sourceClazz,
Class<T> targetClazz)
支持 map bean copy
T - 泛型标记source - 源对象sourceClazz - 源类型targetClazz - 转换成的类型public static <T> List<T> copy(@Nullable Collection<?> sourceList, Class<T> targetClazz)
支持 map bean copy
T - 泛型标记sourceList - 源列表targetClazz - 转换成的类型public static <T> List<T> copy(@Nullable Collection<?> sourceList, @Nullable List<T> targetList, Class<T> targetClazz)
支持 map bean copy
T - 泛型标记sourceList - 源列表targetList - 目标列表targetClazz - 转换成的类型public static void copy(@Nullable
Object source,
@Nullable
Object targetBean)
支持 map bean copy
source - 源对象targetBean - 需要赋值的对象public static void copyNonNull(@Nullable
Object source,
@Nullable
Object targetBean)
支持 bean copy
source - 源对象targetBean - 需要赋值的对象@Nullable
public static <T> T copyWithConvert(@Nullable
Object source,
Class<T> targetClazz)
支持 map bean copy
T - 泛型标记source - 源对象targetClazz - 转换成的类@Nullable
public static <T> T copyWithConvert(@Nullable
Object source,
Class<?> sourceClazz,
Class<T> targetClazz)
支持 map bean copy
T - 泛型标记source - 源对象sourceClazz - 源类targetClazz - 转换成的类public static <T> List<T> copyWithConvert(@Nullable Collection<?> sourceList, Class<T> targetClazz)
支持 map bean copy
T - 泛型标记sourceList - 源对象列表targetClazz - 转换成的类@Nullable
public static <T> T copyProperties(@Nullable
Object source,
Class<T> targetClazz)
throws org.springframework.beans.BeansException
Note: The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored.
This is just a convenience method. For more complex transfer needs,
T - 泛型标记source - the source beantargetClazz - the target bean classorg.springframework.beans.BeansException - if the copying failedpublic static <T> List<T> copyProperties(@Nullable Collection<?> sourceList, Class<T> targetClazz) throws org.springframework.beans.BeansException
Note: The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored.
This is just a convenience method. For more complex transfer needs,
T - 泛型标记sourceList - the source list beantargetClazz - the target bean classorg.springframework.beans.BeansException - if the copying failedpublic static Map<String,Object> toMap(@Nullable Object bean)
bean - 源对象public static Map<String,Object> toNewMap(@Nullable Object bean)
bean - 源对象public static <T> T toBean(Map<String,Object> beanMap, Class<T> valueType)
T - 泛型标记beanMap - mapvalueType - 对象类型@Nullable public static Object generator(@Nullable Object superBean, BeanProperty... props)
superBean - 父级Beanprops - 新增属性public static Object generator(Class<?> superclass, BeanProperty... props)
superclass - 父级props - 新增属性public static BeanDiff diff(Object src, Object dist)
src - 源对象dist - 新对象Copyright © 2024. All rights reserved.