Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jeecg
jeecg-boot
提交
05c926c2
J
jeecg-boot
项目概览
jeecg
/
jeecg-boot
上一次同步 3 年多
通知
865
Star
24375
Fork
84
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jeecg-boot
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
05c926c2
编写于
7月 24, 2019
作者:
JEECG低代码平台
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
解决initQueryWrapper组装sql查询条件错误 #284
上级
5b5fa424
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
8 deletion
+31
-8
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/common/system/query/QueryGenerator.java
...in/java/org/jeecg/common/system/query/QueryGenerator.java
+31
-8
未找到文件。
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/common/system/query/QueryGenerator.java
浏览文件 @
05c926c2
...
@@ -39,6 +39,8 @@ public class QueryGenerator {
...
@@ -39,6 +39,8 @@ public class QueryGenerator {
private
static
final
String
STAR
=
"*"
;
private
static
final
String
STAR
=
"*"
;
private
static
final
String
COMMA
=
","
;
private
static
final
String
COMMA
=
","
;
private
static
final
String
NOT_EQUAL
=
"!"
;
private
static
final
String
NOT_EQUAL
=
"!"
;
/**页面带有规则值查询,空格作为分隔符*/
private
static
final
String
QUERY_SEPARATE_KEYWORD
=
" "
;
/**高级查询前端传来的参数名*/
/**高级查询前端传来的参数名*/
private
static
final
String
SUPER_QUERY_PARAMS
=
"superQueryParams"
;
private
static
final
String
SUPER_QUERY_PARAMS
=
"superQueryParams"
;
...
@@ -150,6 +152,12 @@ public class QueryGenerator {
...
@@ -150,6 +152,12 @@ public class QueryGenerator {
//根据参数值带什么关键字符串判断走什么类型的查询
//根据参数值带什么关键字符串判断走什么类型的查询
QueryRuleEnum
rule
=
convert2Rule
(
value
);
QueryRuleEnum
rule
=
convert2Rule
(
value
);
value
=
replaceValue
(
rule
,
value
);
value
=
replaceValue
(
rule
,
value
);
// add -begin 添加判断为字符串时设为全模糊查询
if
(
(
rule
==
null
||
QueryRuleEnum
.
EQ
.
equals
(
rule
))
&&
"class java.lang.String"
.
equals
(
type
))
{
// 可以设置左右模糊或全模糊,因人而异
rule
=
QueryRuleEnum
.
LIKE
;
}
// add -end 添加判断为字符串时设为全模糊查询
addEasyQuery
(
queryWrapper
,
name
,
rule
,
value
);
addEasyQuery
(
queryWrapper
,
name
,
rule
,
value
);
}
}
...
@@ -221,7 +229,7 @@ public class QueryGenerator {
...
@@ -221,7 +229,7 @@ public class QueryGenerator {
* @param value
* @param value
* @return
* @return
*/
*/
p
ublic
static
QueryRuleEnum
convert2Rule
(
Object
value
)
{
p
rivate
static
QueryRuleEnum
convert2Rule
(
Object
value
)
{
// 避免空数据
// 避免空数据
if
(
value
==
null
)
{
if
(
value
==
null
)
{
return
null
;
return
null
;
...
@@ -231,15 +239,23 @@ public class QueryGenerator {
...
@@ -231,15 +239,23 @@ public class QueryGenerator {
return
null
;
return
null
;
}
}
QueryRuleEnum
rule
=
null
;
QueryRuleEnum
rule
=
null
;
//update-begin--Author:scott Date:20190724 for:initQueryWrapper组装sql查询条件错误 #284-------------------
//TODO 此处规则,只适用于 le lt ge gt
// step 2 .>= =<
// step 2 .>= =<
if
(
rule
==
null
&&
val
.
length
()
>=
2
)
{
if
(
rule
==
null
&&
val
.
length
()
>=
3
)
{
rule
=
QueryRuleEnum
.
getByValue
(
val
.
substring
(
0
,
2
));
if
(
QUERY_SEPARATE_KEYWORD
.
equals
(
val
.
substring
(
2
,
3
))){
rule
=
QueryRuleEnum
.
getByValue
(
val
.
substring
(
0
,
2
));
}
}
}
// step 1 .> <
// step 1 .> <
if
(
rule
==
null
&&
val
.
length
()
>=
1
)
{
if
(
rule
==
null
&&
val
.
length
()
>=
2
)
{
rule
=
QueryRuleEnum
.
getByValue
(
val
.
substring
(
0
,
1
));
if
(
QUERY_SEPARATE_KEYWORD
.
equals
(
val
.
substring
(
1
,
2
))){
rule
=
QueryRuleEnum
.
getByValue
(
val
.
substring
(
0
,
1
));
}
}
}
//update-end--Author:scott Date:20190724 for:initQueryWrapper组装sql查询条件错误 #284---------------------
// step 3 like
// step 3 like
if
(
rule
==
null
&&
val
.
contains
(
STAR
))
{
if
(
rule
==
null
&&
val
.
contains
(
STAR
))
{
if
(
val
.
startsWith
(
STAR
)
&&
val
.
endsWith
(
STAR
))
{
if
(
val
.
startsWith
(
STAR
)
&&
val
.
endsWith
(
STAR
))
{
...
@@ -269,7 +285,7 @@ public class QueryGenerator {
...
@@ -269,7 +285,7 @@ public class QueryGenerator {
* @param value
* @param value
* @return
* @return
*/
*/
p
ublic
static
Object
replaceValue
(
QueryRuleEnum
rule
,
Object
value
)
{
p
rivate
static
Object
replaceValue
(
QueryRuleEnum
rule
,
Object
value
)
{
if
(
rule
==
null
)
{
if
(
rule
==
null
)
{
return
null
;
return
null
;
}
}
...
@@ -286,7 +302,14 @@ public class QueryGenerator {
...
@@ -286,7 +302,14 @@ public class QueryGenerator {
}
else
if
(
rule
==
QueryRuleEnum
.
IN
)
{
}
else
if
(
rule
==
QueryRuleEnum
.
IN
)
{
value
=
val
.
split
(
","
);
value
=
val
.
split
(
","
);
}
else
{
}
else
{
value
=
val
.
replace
(
rule
.
getValue
(),
""
);
//update-begin--Author:scott Date:20190724 for:initQueryWrapper组装sql查询条件错误 #284-------------------
if
(
val
.
startsWith
(
rule
.
getValue
())){
//TODO 此处逻辑应该注释掉-> 如果查询内容中带有查询匹配规则符号,就会被截取的(比如:>=您好)
value
=
val
.
replaceFirst
(
rule
.
getValue
(),
""
);
}
else
if
(
val
.
startsWith
(
rule
.
getCondition
()+
QUERY_SEPARATE_KEYWORD
)){
value
=
val
.
replaceFirst
(
rule
.
getCondition
()+
QUERY_SEPARATE_KEYWORD
,
""
).
trim
();
}
//update-end--Author:scott Date:20190724 for:initQueryWrapper组装sql查询条件错误 #284-------------------
}
}
return
value
;
return
value
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录