Commit 8d2c33e9b0848decc7ddc9b242639a36dfc147a1

Authored by shizhong
1 parent af4f52a2

解决字符串型字段等值查询条件前端传空字符串不能正常忽略问题

yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java
1 1 package cn.iocoder.yudao.framework.mybatis.core.query;
2 2  
3   -import cn.hutool.core.lang.Assert;
4 3 import cn.hutool.core.util.ArrayUtil;
5 4 import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
6   -import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants;
7 5 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
8 6 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
9 7 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
... ... @@ -13,7 +11,7 @@ import java.util.Collection;
13 11  
14 12 /**
15 13 * 拓展 MyBatis Plus QueryWrapper 类,主要增加如下功能:
16   - *
  14 + * <p>
17 15 * 1. 拼接条件的方法,增加 xxxIfPresent 方法,用于判断值不存在的时候,不要拼接到条件中。
18 16 *
19 17 * @param <T> 数据类型
... ... @@ -42,14 +40,14 @@ public class LambdaQueryWrapperX&lt;T&gt; extends LambdaQueryWrapper&lt;T&gt; {
42 40 }
43 41  
44 42 public LambdaQueryWrapperX<T> eqIfPresent(SFunction<T, ?> column, Object val) {
45   - if (val != null) {
  43 + if (val instanceof String && StringUtils.hasText((String) val) || !(val instanceof String) && val != null) {
46 44 return (LambdaQueryWrapperX<T>) super.eq(column, val);
47 45 }
48 46 return this;
49 47 }
50 48  
51 49 public LambdaQueryWrapperX<T> neIfPresent(SFunction<T, ?> column, Object val) {
52   - if (val != null) {
  50 + if (val instanceof String && StringUtils.hasText((String) val) || !(val instanceof String) && val != null) {
53 51 return (LambdaQueryWrapperX<T>) super.ne(column, val);
54 52 }
55 53 return this;
... ...