mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add methods
This commit is contained in:
parent
2d2819ad28
commit
2881062f33
@ -7,9 +7,11 @@
|
|||||||
|
|
||||||
### ❌不兼容特性
|
### ❌不兼容特性
|
||||||
* 【extra 】 升级jakarta.validation-api到3.x,包名变更导致不能向下兼容
|
* 【extra 】 升级jakarta.validation-api到3.x,包名变更导致不能向下兼容
|
||||||
|
* 【core 】 BeanUtil删除了beanToMap(Object)方法,因为有可变参数的方法,这个删除可能导致直接升级找不到方法,重新编译项目即可。
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 Singleton增加部分方法(pr#609@Gitee)
|
* 【core 】 Singleton增加部分方法(pr#609@Gitee)
|
||||||
|
* 【core 】 BeanUtil增加beanToMap重载(pr#2292@Github)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【db 】 修复RedisDS无法设置maxWaitMillis问题(issue#I54TZ9@Gitee)
|
* 【db 】 修复RedisDS无法设置maxWaitMillis问题(issue#I54TZ9@Gitee)
|
||||||
|
@ -24,8 +24,6 @@ import java.beans.PropertyEditorManager;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -608,38 +606,24 @@ public class BeanUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------- beanToMap
|
// --------------------------------------------------------------------------------------------- beanToMap
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对象转Map,不进行驼峰转下划线,不忽略值为空的字段
|
* 将bean的部分属性转换成map<br>
|
||||||
*
|
* 可选拷贝哪些属性值,默认是不忽略值为{@code null}的值的。
|
||||||
* @param bean bean对象
|
|
||||||
* @return Map
|
|
||||||
*/
|
|
||||||
public static Map<String, Object> beanToMap(Object bean) {
|
|
||||||
return beanToMap(bean, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将bean的部分属性转换成map
|
|
||||||
*
|
*
|
||||||
* @param bean bean
|
* @param bean bean
|
||||||
* @param properties 属性值
|
* @param properties 需要拷贝的属性值,{@code null}或空表示拷贝所有值
|
||||||
* @return Map
|
* @return Map
|
||||||
|
* @since 5.8.0
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> beanToMap(Object bean, String... properties) {
|
public static Map<String, Object> beanToMap(Object bean, String... properties) {
|
||||||
if (ArrayUtil.isEmpty(properties)) {
|
Editor<String> keyEditor = null;
|
||||||
return Collections.emptyMap();
|
if(ArrayUtil.isNotEmpty(properties)){
|
||||||
|
final Set<String> propertiesSet = CollUtil.set(false, properties);
|
||||||
|
keyEditor = property -> propertiesSet.contains(property) ? property : null;
|
||||||
}
|
}
|
||||||
Set<String> propertiesSet = Arrays.stream(properties).collect(Collectors.toSet());
|
|
||||||
// 指明了要复制的属性 所以不忽略null值
|
// 指明了要复制的属性 所以不忽略null值
|
||||||
return beanToMap(bean, new HashMap<>(properties.length), false,
|
return beanToMap(bean, new LinkedHashMap<>(properties.length, 1), false, keyEditor);
|
||||||
property -> {
|
|
||||||
if (!propertiesSet.contains(property)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return property;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user