mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
refactor: optimize Row.getIgnoreCase
This commit is contained in:
parent
3ff68d027d
commit
aeb8ae9ad4
@ -273,12 +273,14 @@ public class Row extends LinkedHashMap<String, Object> implements UpdateWrapper<
|
||||
}
|
||||
|
||||
public Object getIgnoreCase(String key) {
|
||||
String camelKey = null;
|
||||
if (key.contains("_")) {
|
||||
camelKey = StringUtil.deleteChar(key, '_');
|
||||
Object result = super.get(key);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String newKey = StringUtil.deleteChar(key, '_', '-');
|
||||
for (String innerKey : keySet()) {
|
||||
if (innerKey.equalsIgnoreCase(key) || (camelKey != null && camelKey.equalsIgnoreCase(innerKey))) {
|
||||
if (newKey.equalsIgnoreCase(StringUtil.deleteChar(innerKey, '_', '-'))) {
|
||||
return super.get(innerKey);
|
||||
}
|
||||
}
|
||||
@ -320,7 +322,7 @@ public class Row extends LinkedHashMap<String, Object> implements UpdateWrapper<
|
||||
return defaultValue;
|
||||
}
|
||||
String r = s.toString();
|
||||
return r.trim().length() == 0 ? defaultValue : r;
|
||||
return r.trim().isEmpty() ? defaultValue : r;
|
||||
}
|
||||
|
||||
public Integer getInt(String key) {
|
||||
|
||||
@ -144,6 +144,20 @@ public class StringUtil {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String deleteChar(String string, char deleteChar1, char deleteChar2) {
|
||||
if (isBlank(string)) {
|
||||
return "";
|
||||
}
|
||||
char[] chars = string.toCharArray();
|
||||
StringBuilder sb = new StringBuilder(string.length());
|
||||
for (char aChar : chars) {
|
||||
if (aChar != deleteChar1 && aChar != deleteChar2) {
|
||||
sb.append(aChar);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串为 null 或者内部字符全部为 ' ', '\t', '\n', '\r' 这四类字符时返回 true
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user