fix db bug

This commit is contained in:
Looly 2021-02-25 21:59:39 +08:00
parent 95e0292757
commit d615b5147b
3 changed files with 42 additions and 16 deletions

View File

@ -3,7 +3,7 @@
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.5.9 (2021-02-20) # 5.5.9 (2021-02-25)
### 新特性 ### 新特性
* 【crypto 】 PemUtil.readPemKey支持ECpr#1366@Github * 【crypto 】 PemUtil.readPemKey支持ECpr#1366@Github
@ -21,6 +21,7 @@
* 【poi 】 修复ExcelPicUtil中图表报错问题issue#I38857@Gitee * 【poi 】 修复ExcelPicUtil中图表报错问题issue#I38857@Gitee
* 【core 】 修复ListUtil.page方法返回空列表无法编辑问题issue#1415@Github * 【core 】 修复ListUtil.page方法返回空列表无法编辑问题issue#1415@Github
* 【core 】 修复ListUtil.sub中step不通结果不一致问题issue#1409@Github * 【core 】 修复ListUtil.sub中step不通结果不一致问题issue#1409@Github
* 【db 】 修复Condition转换参数值时未转换数字异常issue#I38LTM@Gitee
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------

View File

@ -5,6 +5,7 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.StrSpliter; import cn.hutool.core.text.StrSpliter;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil; import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import java.util.Arrays; import java.util.Arrays;
@ -444,7 +445,7 @@ public class Condition extends CloneSupport<Condition> {
return; return;
} }
valueStr = valueStr.trim(); valueStr = StrUtil.trim(valueStr);
// 处理null // 处理null
if (StrUtil.endWithIgnoreCase(valueStr, "null")) { if (StrUtil.endWithIgnoreCase(valueStr, "null")) {
@ -463,7 +464,7 @@ public class Condition extends CloneSupport<Condition> {
} }
} }
List<String> strs = StrUtil.split(valueStr, StrUtil.C_SPACE, 2); final List<String> strs = StrUtil.split(valueStr, StrUtil.C_SPACE, 2);
if (strs.size() < 2) { if (strs.size() < 2) {
return; return;
} }
@ -472,7 +473,8 @@ public class Condition extends CloneSupport<Condition> {
final String firstPart = strs.get(0).trim().toUpperCase(); final String firstPart = strs.get(0).trim().toUpperCase();
if (OPERATORS.contains(firstPart)) { if (OPERATORS.contains(firstPart)) {
this.operator = firstPart; this.operator = firstPart;
this.value = strs.get(1).trim(); // 比较符号后跟大部分为数字此处做转换
this.value = tryToNumber(strs.get(1));
return; return;
} }
@ -526,5 +528,20 @@ public class Condition extends CloneSupport<Condition> {
} }
return value.substring(from, to); return value.substring(from, to);
} }
/**
* 尝试转换为数字转换失败返回字符串
*
* @param value 被转换的字符串值
* @return 转换后的值
*/
private static Object tryToNumber(String value){
value = StrUtil.trim(value);
try{
return NumberUtil.parseNumber(value);
} catch (Exception ignore){
return value;
}
}
// ----------------------------------------------------------------------------------------------- Private method end // ----------------------------------------------------------------------------------------------- Private method end
} }

View File

@ -52,4 +52,12 @@ public class ConditionTest {
conditionBetween.setPlaceHolder(false); conditionBetween.setPlaceHolder(false);
Assert.assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString()); Assert.assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString());
} }
@Test
public void parseTest(){
final Condition age = Condition.parse("age", "< 10");
Assert.assertEquals("age < ?", age.toString());
// issue I38LTM
Assert.assertSame(Long.class, age.getValue().getClass());
}
} }