Commit 8d2c33e9b0848decc7ddc9b242639a36dfc147a1
1 parent
af4f52a2
解决字符串型字段等值查询条件前端传空字符串不能正常忽略问题
Showing
1 changed file
with
3 additions
and
5 deletions
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java
| 1 | package cn.iocoder.yudao.framework.mybatis.core.query; | 1 | package cn.iocoder.yudao.framework.mybatis.core.query; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.lang.Assert; | ||
| 4 | import cn.hutool.core.util.ArrayUtil; | 3 | import cn.hutool.core.util.ArrayUtil; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 4 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 6 | -import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants; | ||
| 7 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 5 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 8 | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | 6 | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| 9 | import com.baomidou.mybatisplus.core.toolkit.support.SFunction; | 7 | import com.baomidou.mybatisplus.core.toolkit.support.SFunction; |
| @@ -13,7 +11,7 @@ import java.util.Collection; | @@ -13,7 +11,7 @@ import java.util.Collection; | ||
| 13 | 11 | ||
| 14 | /** | 12 | /** |
| 15 | * 拓展 MyBatis Plus QueryWrapper 类,主要增加如下功能: | 13 | * 拓展 MyBatis Plus QueryWrapper 类,主要增加如下功能: |
| 16 | - * | 14 | + * <p> |
| 17 | * 1. 拼接条件的方法,增加 xxxIfPresent 方法,用于判断值不存在的时候,不要拼接到条件中。 | 15 | * 1. 拼接条件的方法,增加 xxxIfPresent 方法,用于判断值不存在的时候,不要拼接到条件中。 |
| 18 | * | 16 | * |
| 19 | * @param <T> 数据类型 | 17 | * @param <T> 数据类型 |
| @@ -42,14 +40,14 @@ public class LambdaQueryWrapperX<T> extends LambdaQueryWrapper<T> { | @@ -42,14 +40,14 @@ public class LambdaQueryWrapperX<T> extends LambdaQueryWrapper<T> { | ||
| 42 | } | 40 | } |
| 43 | 41 | ||
| 44 | public LambdaQueryWrapperX<T> eqIfPresent(SFunction<T, ?> column, Object val) { | 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 | return (LambdaQueryWrapperX<T>) super.eq(column, val); | 44 | return (LambdaQueryWrapperX<T>) super.eq(column, val); |
| 47 | } | 45 | } |
| 48 | return this; | 46 | return this; |
| 49 | } | 47 | } |
| 50 | 48 | ||
| 51 | public LambdaQueryWrapperX<T> neIfPresent(SFunction<T, ?> column, Object val) { | 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 | return (LambdaQueryWrapperX<T>) super.ne(column, val); | 51 | return (LambdaQueryWrapperX<T>) super.ne(column, val); |
| 54 | } | 52 | } |
| 55 | return this; | 53 | return this; |