Commit c336bb43050fa4bf772c2a5991f5f0bcb81fbc1f
1 parent
5e13ced3
解决initQueryWrapper组装sql查询条件错误 #284
Showing
1 changed file
with
31 additions
and
8 deletions
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/common/system/query/QueryGenerator.java
@@ -39,6 +39,8 @@ public class QueryGenerator { | @@ -39,6 +39,8 @@ public class QueryGenerator { | ||
39 | private static final String STAR = "*"; | 39 | private static final String STAR = "*"; |
40 | private static final String COMMA = ","; | 40 | private static final String COMMA = ","; |
41 | private static final String NOT_EQUAL = "!"; | 41 | private static final String NOT_EQUAL = "!"; |
42 | + /**页面带有规则值查询,空格作为分隔符*/ | ||
43 | + private static final String QUERY_SEPARATE_KEYWORD = " "; | ||
42 | /**高级查询前端传来的参数名*/ | 44 | /**高级查询前端传来的参数名*/ |
43 | private static final String SUPER_QUERY_PARAMS = "superQueryParams"; | 45 | private static final String SUPER_QUERY_PARAMS = "superQueryParams"; |
44 | 46 | ||
@@ -150,6 +152,12 @@ public class QueryGenerator { | @@ -150,6 +152,12 @@ public class QueryGenerator { | ||
150 | //根据参数值带什么关键字符串判断走什么类型的查询 | 152 | //根据参数值带什么关键字符串判断走什么类型的查询 |
151 | QueryRuleEnum rule = convert2Rule(value); | 153 | QueryRuleEnum rule = convert2Rule(value); |
152 | value = replaceValue(rule,value); | 154 | value = replaceValue(rule,value); |
155 | + // add -begin 添加判断为字符串时设为全模糊查询 | ||
156 | + if( (rule==null || QueryRuleEnum.EQ.equals(rule)) && "class java.lang.String".equals(type)) { | ||
157 | + // 可以设置左右模糊或全模糊,因人而异 | ||
158 | + rule = QueryRuleEnum.LIKE; | ||
159 | + } | ||
160 | + // add -end 添加判断为字符串时设为全模糊查询 | ||
153 | addEasyQuery(queryWrapper, name, rule, value); | 161 | addEasyQuery(queryWrapper, name, rule, value); |
154 | } | 162 | } |
155 | 163 | ||
@@ -221,7 +229,7 @@ public class QueryGenerator { | @@ -221,7 +229,7 @@ public class QueryGenerator { | ||
221 | * @param value | 229 | * @param value |
222 | * @return | 230 | * @return |
223 | */ | 231 | */ |
224 | - public static QueryRuleEnum convert2Rule(Object value) { | 232 | + private static QueryRuleEnum convert2Rule(Object value) { |
225 | // 避免空数据 | 233 | // 避免空数据 |
226 | if (value == null) { | 234 | if (value == null) { |
227 | return null; | 235 | return null; |
@@ -231,15 +239,23 @@ public class QueryGenerator { | @@ -231,15 +239,23 @@ public class QueryGenerator { | ||
231 | return null; | 239 | return null; |
232 | } | 240 | } |
233 | QueryRuleEnum rule =null; | 241 | QueryRuleEnum rule =null; |
242 | + | ||
243 | + //update-begin--Author:scott Date:20190724 for:initQueryWrapper组装sql查询条件错误 #284------------------- | ||
244 | + //TODO 此处规则,只适用于 le lt ge gt | ||
234 | // step 2 .>= =< | 245 | // step 2 .>= =< |
235 | - if (rule == null && val.length() >= 2) { | ||
236 | - rule = QueryRuleEnum.getByValue(val.substring(0, 2)); | 246 | + if (rule == null && val.length() >= 3) { |
247 | + if(QUERY_SEPARATE_KEYWORD.equals(val.substring(2, 3))){ | ||
248 | + rule = QueryRuleEnum.getByValue(val.substring(0, 2)); | ||
249 | + } | ||
237 | } | 250 | } |
238 | // step 1 .> < | 251 | // step 1 .> < |
239 | - if (rule == null && val.length() >= 1) { | ||
240 | - rule = QueryRuleEnum.getByValue(val.substring(0, 1)); | 252 | + if (rule == null && val.length() >= 2) { |
253 | + if(QUERY_SEPARATE_KEYWORD.equals(val.substring(1, 2))){ | ||
254 | + rule = QueryRuleEnum.getByValue(val.substring(0, 1)); | ||
255 | + } | ||
241 | } | 256 | } |
242 | - | 257 | + //update-end--Author:scott Date:20190724 for:initQueryWrapper组装sql查询条件错误 #284--------------------- |
258 | + | ||
243 | // step 3 like | 259 | // step 3 like |
244 | if (rule == null && val.contains(STAR)) { | 260 | if (rule == null && val.contains(STAR)) { |
245 | if (val.startsWith(STAR) && val.endsWith(STAR)) { | 261 | if (val.startsWith(STAR) && val.endsWith(STAR)) { |
@@ -269,7 +285,7 @@ public class QueryGenerator { | @@ -269,7 +285,7 @@ public class QueryGenerator { | ||
269 | * @param value | 285 | * @param value |
270 | * @return | 286 | * @return |
271 | */ | 287 | */ |
272 | - public static Object replaceValue(QueryRuleEnum rule, Object value) { | 288 | + private static Object replaceValue(QueryRuleEnum rule, Object value) { |
273 | if (rule == null) { | 289 | if (rule == null) { |
274 | return null; | 290 | return null; |
275 | } | 291 | } |
@@ -286,7 +302,14 @@ public class QueryGenerator { | @@ -286,7 +302,14 @@ public class QueryGenerator { | ||
286 | } else if (rule == QueryRuleEnum.IN) { | 302 | } else if (rule == QueryRuleEnum.IN) { |
287 | value = val.split(","); | 303 | value = val.split(","); |
288 | } else { | 304 | } else { |
289 | - value = val.replace(rule.getValue(),""); | 305 | + //update-begin--Author:scott Date:20190724 for:initQueryWrapper组装sql查询条件错误 #284------------------- |
306 | + if(val.startsWith(rule.getValue())){ | ||
307 | + //TODO 此处逻辑应该注释掉-> 如果查询内容中带有查询匹配规则符号,就会被截取的(比如:>=您好) | ||
308 | + value = val.replaceFirst(rule.getValue(),""); | ||
309 | + }else if(val.startsWith(rule.getCondition()+QUERY_SEPARATE_KEYWORD)){ | ||
310 | + value = val.replaceFirst(rule.getCondition()+QUERY_SEPARATE_KEYWORD,"").trim(); | ||
311 | + } | ||
312 | + //update-end--Author:scott Date:20190724 for:initQueryWrapper组装sql查询条件错误 #284------------------- | ||
290 | } | 313 | } |
291 | return value; | 314 | return value; |
292 | } | 315 | } |