mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add isXXX support
This commit is contained in:
parent
cd9d902ff3
commit
78aaab53bc
@ -3,12 +3,13 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.6.3 (2021-04-02)
|
||||
# 5.6.3 (2021-04-03)
|
||||
|
||||
### 新特性
|
||||
* 【core 】 修改数字转换的实现,增加按照指定端序转换(pr#1492@Github)
|
||||
* 【core 】 修改拆分byte数组时最后一组长度的规则(pr#1494@Github)
|
||||
* 【core 】 新增根据日期获取节气(pr#1496@Github)
|
||||
* 【core 】 mapToBean()添加对布尔值is前缀的识别(pr#294@Gitee)
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 修复Validator.isUrl()传空返回true(issue#I3ETTY@Gitee)
|
||||
|
@ -10,7 +10,14 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* Map值提供者,支持驼峰和下划线的key兼容。<br>
|
||||
* 假设目标属性为firstName,则Map中为firstName或first_name都可以对应到值。
|
||||
* 假设目标属性为firstName,则Map中以下形式的值都可以对应:
|
||||
* <ul>
|
||||
* <li>firstName</li>
|
||||
* <li>first_name</li>
|
||||
* <li>isFirstName(如果为Boolean或boolean类型的值)</li>
|
||||
* <li>is_first_name(如果为Boolean或boolean类型的值)</li>
|
||||
* </ul>
|
||||
* 为firstName或first_name都可以对应到值。
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
@ -50,17 +57,22 @@ public class MapValueProvider implements ValueProvider<String> {
|
||||
|
||||
@Override
|
||||
public Object value(String key, Type valueType) {
|
||||
Object value = map.get(getKey(key, valueType));
|
||||
final String key1 = getKey(key, valueType);
|
||||
if (null == key1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Object value = map.get(key1);
|
||||
return Convert.convertWithCheck(valueType, value, null, this.ignoreError);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(String key) {
|
||||
return map.containsKey(getKey(key, null));
|
||||
return null != getKey(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得map中可能包含的key
|
||||
* 获得map中可能包含的key,不包含返回null
|
||||
*
|
||||
* @param key map中可能包含的key
|
||||
* @param valueType 值类型,用于判断是否为Boolean,可以为null
|
||||
@ -72,27 +84,26 @@ public class MapValueProvider implements ValueProvider<String> {
|
||||
}
|
||||
|
||||
//检查下划线模式
|
||||
String containKey = StrUtil.toUnderlineCase(key);
|
||||
if (map.containsKey(containKey)) {
|
||||
return containKey;
|
||||
String customKey = StrUtil.toUnderlineCase(key);
|
||||
if (map.containsKey(customKey)) {
|
||||
return customKey;
|
||||
}
|
||||
|
||||
//检查boolean类型
|
||||
if (null == valueType || Boolean.class == valueType || boolean.class == valueType) {
|
||||
//boolean类型字段字段名支持两种方式
|
||||
containKey = StrUtil.upperFirstAndAddPre(key, "is");
|
||||
if (map.containsKey(containKey)) {
|
||||
return containKey;
|
||||
customKey = StrUtil.upperFirstAndAddPre(key, "is");
|
||||
if (map.containsKey(customKey)) {
|
||||
return customKey;
|
||||
}
|
||||
|
||||
//检查下划线模式
|
||||
containKey = StrUtil.toUnderlineCase(containKey);
|
||||
if (map.containsKey(containKey)) {
|
||||
return containKey;
|
||||
customKey = StrUtil.toUnderlineCase(customKey);
|
||||
if (map.containsKey(customKey)) {
|
||||
return customKey;
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user