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