mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bug
This commit is contained in:
parent
f1b6d84fe7
commit
05b3d83a37
@ -19,6 +19,7 @@
|
||||
* 【http 】 修复HttpCookie设置cookies的方法,不符合RFC6265规范问题(pr#418@Gitee)
|
||||
* 【http 】 修复Extractor中filter无效问题
|
||||
* 【json 】 修复JSONGetter.getJSONArray判断null的问题(issue#I4C15H@Gitee)
|
||||
* 【db 】 修复Condition没占位符的情况下sql没引号问题(issue#1846@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -257,6 +257,16 @@ public class Condition extends CloneSupport<Condition> {
|
||||
return OPERATOR_IS.equalsIgnoreCase(this.operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否LIKE条件
|
||||
*
|
||||
* @return 是否LIKE条件
|
||||
* @since 5.7.14
|
||||
*/
|
||||
public boolean isOperatorLike() {
|
||||
return OPERATOR_LIKE.equalsIgnoreCase(this.operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查值是否为null,如果为null转换为 "IS NULL"形式
|
||||
*
|
||||
@ -343,7 +353,9 @@ public class Condition extends CloneSupport<Condition> {
|
||||
}
|
||||
} else {
|
||||
// 直接使用条件值
|
||||
conditionStrBuilder.append(" ").append(this.value);
|
||||
final String valueStr = String.valueOf(this.value);
|
||||
conditionStrBuilder.append(" ").append(isOperatorLike() ?
|
||||
StrUtil.wrap(valueStr, "'") : valueStr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -536,14 +548,14 @@ public class Condition extends CloneSupport<Condition> {
|
||||
* @param value 被转换的字符串值
|
||||
* @return 转换后的值
|
||||
*/
|
||||
private static Object tryToNumber(String value){
|
||||
private static Object tryToNumber(String value) {
|
||||
value = StrUtil.trim(value);
|
||||
if(false == NumberUtil.isNumber(value)){
|
||||
if (false == NumberUtil.isNumber(value)) {
|
||||
return value;
|
||||
}
|
||||
try{
|
||||
try {
|
||||
return NumberUtil.parseNumber(value);
|
||||
} catch (Exception ignore){
|
||||
} catch (Exception ignore) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class ConditionBuilder implements Builder<String> {
|
||||
* 创建构建器
|
||||
*
|
||||
* @param conditions 条件列表
|
||||
* @return {@link ConditionBuilder}
|
||||
* @return ConditionBuilder
|
||||
*/
|
||||
public static ConditionBuilder of(Condition... conditions) {
|
||||
return new ConditionBuilder(conditions);
|
||||
|
@ -85,17 +85,17 @@ public class SqlUtil {
|
||||
* 创建LIKE语句中的值,创建的结果为:
|
||||
*
|
||||
* <pre>
|
||||
* 1、LikeType.StartWith: %value
|
||||
* 2、LikeType.EndWith: value%
|
||||
* 3、LikeType.Contains: %value%
|
||||
* 1、LikeType.StartWith: '%value'
|
||||
* 2、LikeType.EndWith: 'value%'
|
||||
* 3、LikeType.Contains: '%value%'
|
||||
* </pre>
|
||||
* <p>
|
||||
* 如果withLikeKeyword为true,则结果为:
|
||||
*
|
||||
* <pre>
|
||||
* 1、LikeType.StartWith: LIKE %value
|
||||
* 2、LikeType.EndWith: LIKE value%
|
||||
* 3、LikeType.Contains: LIKE %value%
|
||||
* 1、LikeType.StartWith: LIKE '%value'
|
||||
* 2、LikeType.EndWith: LIKE 'value%'
|
||||
* 3、LikeType.Contains: LIKE '%value%'
|
||||
* </pre>
|
||||
*
|
||||
* @param value 被查找值
|
||||
|
@ -21,7 +21,7 @@ public class SqlBuilderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void orderByTest(){
|
||||
public void orderByTest() {
|
||||
SqlBuilder builder = SqlBuilder.create().select("id", "username").from("user")
|
||||
.join("role", SqlBuilder.Join.INNER)
|
||||
.on("user.id = role.user_id")
|
||||
@ -31,4 +31,17 @@ public class SqlBuilderTest {
|
||||
|
||||
Assert.assertEquals("SELECT id,username FROM user INNER JOIN role ON user.id = role.user_id WHERE age >= ? AND username LIKE ? ORDER BY id", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void likeTest() {
|
||||
Condition conditionEquals = new Condition("user", "123", Condition.LikeType.Contains);
|
||||
conditionEquals.setPlaceHolder(false);
|
||||
|
||||
SqlBuilder sqlBuilder = new SqlBuilder();
|
||||
sqlBuilder.select("id");
|
||||
sqlBuilder.from("user");
|
||||
sqlBuilder.where(conditionEquals);
|
||||
String s1 = sqlBuilder.build();
|
||||
Assert.assertEquals("SELECT id FROM user WHERE user LIKE '%123%'", s1);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user