mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
添加ifAbsent
This commit is contained in:
parent
eda25c23f8
commit
a2756a9dde
@ -3,13 +3,15 @@ package com.github.yulichang.autoconfigure;
|
||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusLanguageDriverAutoConfiguration;
|
||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||
import com.github.yulichang.autoconfigure.conditional.MPJSqlInjectorCondition;
|
||||
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinIfAbsentConsumer;
|
||||
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinPropertiesConsumer;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.MPJInterceptorConfig;
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.extension.mapping.config.MappingConfig;
|
||||
import com.github.yulichang.injector.MPJSqlInjector;
|
||||
import com.github.yulichang.interceptor.MPJInterceptor;
|
||||
import com.github.yulichang.toolkit.SpringContentUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.slf4j.Logger;
|
||||
@ -40,6 +42,7 @@ import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* springboot 自动配置类
|
||||
@ -60,7 +63,7 @@ public class MybatisPlusJoinAutoConfiguration {
|
||||
|
||||
public MybatisPlusJoinAutoConfiguration(MybatisPlusJoinProperties properties,
|
||||
ObjectProvider<MybatisPlusJoinPropertiesConsumer> propertiesConsumers,
|
||||
ObjectProvider<MybatisPlusJoinIfAbsent> ifAbsentConsumers) {
|
||||
ObjectProvider<MybatisPlusJoinIfAbsentConsumer> ifAbsentConsumers) {
|
||||
this.properties = Optional.ofNullable(propertiesConsumers.getIfAvailable()).map(c -> c.config(properties)).orElse(properties);
|
||||
ConfigProperties.banner = this.properties.getBanner();
|
||||
ConfigProperties.subTableLogic = this.properties.getSubTableLogic();
|
||||
@ -69,7 +72,8 @@ public class MybatisPlusJoinAutoConfiguration {
|
||||
ConfigProperties.joinPrefix = this.properties.getJoinPrefix();
|
||||
ConfigProperties.logicDelType = this.properties.getLogicDelType();
|
||||
ConfigProperties.mappingMaxCount = this.properties.getMappingMaxCount();
|
||||
ConfigProperties.ifAbsent = Optional.ofNullable(ifAbsentConsumers.getIfAvailable()).orElse(this.properties.getIfAbsent());
|
||||
ConfigProperties.ifAbsent = Optional.ofNullable(ifAbsentConsumers.getIfAvailable())
|
||||
.map(m -> (BiPredicate<Object, IfAbsentSqlKeyWordEnum>) m).orElse(this.properties.getIfAbsent());
|
||||
info("mybatis plus join properties config complete");
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.github.yulichang.autoconfigure.consumer;
|
||||
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* 自定义IfAbsent策略
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public interface MybatisPlusJoinIfAbsentConsumer extends BiPredicate<Object, IfAbsentSqlKeyWordEnum> {
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
package com.github.yulichang.autoconfigure;
|
||||
package com.github.yulichang.autoconfigure.consumer;
|
||||
|
||||
import com.github.yulichang.autoconfigure.MybatisPlusJoinProperties;
|
||||
|
||||
/**
|
||||
* 自定义配置
|
@ -4,6 +4,9 @@ import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
||||
import com.github.yulichang.config.enums.IfAbsentEnum;
|
||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
@ -56,5 +59,5 @@ public class ConfigProperties {
|
||||
* <p>
|
||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||
*/
|
||||
public static MybatisPlusJoinIfAbsent ifAbsent = IfAbsentEnum.NOT_EMPTY;
|
||||
public static BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = IfAbsentEnum.NOT_EMPTY;
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
package com.github.yulichang.config;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* 自定义IfAbsent策略
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public interface MybatisPlusJoinIfAbsent extends Predicate<Object> {
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.github.yulichang.config.enums;
|
||||
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.toolkit.MPJStringUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* 条件判断策略
|
||||
@ -12,29 +12,29 @@ import java.util.function.Predicate;
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public enum IfAbsentEnum implements MybatisPlusJoinIfAbsent {
|
||||
public enum IfAbsentEnum implements BiPredicate<Object, IfAbsentSqlKeyWordEnum> {
|
||||
|
||||
/**
|
||||
* 非null
|
||||
*/
|
||||
NOT_NULL(Objects::nonNull),
|
||||
NOT_NULL((val, key) -> Objects.nonNull(val)),
|
||||
/**
|
||||
* 非空字符串 例: "" -> false, " " -> true ...
|
||||
*/
|
||||
NOT_EMPTY(val -> NOT_NULL.and(v -> v instanceof CharSequence).and(v -> MPJStringUtils.isNotEmpty((CharSequence) v)).test(val)),
|
||||
NOT_EMPTY((val, key) -> NOT_NULL.test(val, key) && (!(val instanceof CharSequence) || MPJStringUtils.isNotEmpty((CharSequence) val))),
|
||||
/**
|
||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||
*/
|
||||
NOT_BLANK(val -> NOT_NULL.and(v -> v instanceof CharSequence).and(v -> MPJStringUtils.isNotBlank((CharSequence) v)).test(val));
|
||||
NOT_BLANK((val, key) -> NOT_NULL.test(val, key) && (!(val instanceof CharSequence) || MPJStringUtils.isNotBlank((CharSequence) val)));
|
||||
|
||||
private final Predicate<Object> predicate;
|
||||
private final BiPredicate<Object, IfAbsentSqlKeyWordEnum> predicate;
|
||||
|
||||
IfAbsentEnum(Predicate<Object> predicate) {
|
||||
IfAbsentEnum(BiPredicate<Object, IfAbsentSqlKeyWordEnum> predicate) {
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Object obj) {
|
||||
return this.predicate.test(obj);
|
||||
public boolean test(Object obj, IfAbsentSqlKeyWordEnum keyword) {
|
||||
return this.predicate.test(obj, keyword);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.kt.interfaces.CompareIfAbsent;
|
||||
import com.github.yulichang.kt.interfaces.Func;
|
||||
import com.github.yulichang.kt.interfaces.OnCompare;
|
||||
@ -21,6 +20,7 @@ import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
||||
import com.github.yulichang.toolkit.Ref;
|
||||
import com.github.yulichang.toolkit.TableList;
|
||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.CompareStrIfAbsent;
|
||||
import com.github.yulichang.wrapper.interfaces.FuncStr;
|
||||
@ -32,6 +32,7 @@ import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*;
|
||||
@ -127,7 +128,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
* ifAbsent 策略
|
||||
*/
|
||||
@Getter
|
||||
protected MybatisPlusJoinIfAbsent ifAbsent = ConfigProperties.ifAbsent;
|
||||
protected BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = ConfigProperties.ifAbsent;
|
||||
|
||||
@Override
|
||||
public T getEntity() {
|
||||
@ -180,11 +181,16 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public Children setIfAbsent(MybatisPlusJoinIfAbsent ifAbsent) {
|
||||
public Children setIfAbsent(BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
this.ifAbsent = ifAbsent;
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public Children setIfAbsent(Predicate<Object> ifAbsent) {
|
||||
this.ifAbsent = (o, k) -> ifAbsent.test(o);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children allEq(boolean condition, Map<KProperty<?>, ?> params, boolean null2IsNull) {
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.github.yulichang.kt.interfaces;
|
||||
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import kotlin.reflect.KProperty;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* ifAbsent
|
||||
*
|
||||
@ -12,86 +14,86 @@ import kotlin.reflect.KProperty;
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareIfAbsent<Children> extends Compare<Children> {
|
||||
|
||||
MybatisPlusJoinIfAbsent getIfAbsent();
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> getIfAbsent();
|
||||
|
||||
default Children eqIfAbsent(KProperty<?> column, Object val) {
|
||||
return eq(getIfAbsent().test(val), null, column, val);
|
||||
return eq(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.EQ), null, column, val);
|
||||
}
|
||||
|
||||
default Children eqIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return eq(getIfAbsent().test(val), alias, column, val);
|
||||
return eq(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.EQ), alias, column, val);
|
||||
}
|
||||
|
||||
default Children neIfAbsent(KProperty<?> column, Object val) {
|
||||
return ne(getIfAbsent().test(val), null, column, val);
|
||||
return ne(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NE), null, column, val);
|
||||
}
|
||||
|
||||
default Children neIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return ne(getIfAbsent().test(val), alias, column, val);
|
||||
return ne(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children gtIfAbsent(KProperty<?> column, Object val) {
|
||||
return gt(getIfAbsent().test(val), null, column, val);
|
||||
return gt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GT), null, column, val);
|
||||
}
|
||||
|
||||
default Children gtIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return gt(getIfAbsent().test(val), alias, column, val);
|
||||
return gt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GT), alias, column, val);
|
||||
}
|
||||
|
||||
|
||||
default Children geIfAbsent(KProperty<?> column, Object val) {
|
||||
return ge(getIfAbsent().test(val), null, column, val);
|
||||
return ge(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GE), null, column, val);
|
||||
}
|
||||
|
||||
default Children geIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return ge(getIfAbsent().test(val), alias, column, val);
|
||||
return ge(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children ltIfAbsent(KProperty<?> column, Object val) {
|
||||
return lt(getIfAbsent().test(val), null, column, val);
|
||||
return lt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LT), null, column, val);
|
||||
}
|
||||
|
||||
default Children ltIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return lt(getIfAbsent().test(val), alias, column, val);
|
||||
return lt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children leIfAbsent(KProperty<?> column, Object val) {
|
||||
return le(getIfAbsent().test(val), null, column, val);
|
||||
return le(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LE), null, column, val);
|
||||
}
|
||||
|
||||
default Children leIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return le(getIfAbsent().test(val), alias, column, val);
|
||||
return le(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children likeIfAbsent(KProperty<?> column, Object val) {
|
||||
return like(getIfAbsent().test(val), null, column, val);
|
||||
return like(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE), null, column, val);
|
||||
}
|
||||
|
||||
default Children likeIfAbsent(String alisa, KProperty<?> column, Object val) {
|
||||
return like(getIfAbsent().test(val), alisa, column, val);
|
||||
return like(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE), alisa, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeIfAbsent(KProperty<?> column, Object val) {
|
||||
return notLike(getIfAbsent().test(val), null, column, val);
|
||||
return notLike(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE), null, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return notLike(getIfAbsent().test(val), alias, column, val);
|
||||
return notLike(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children likeLeftIfAbsent(KProperty<?> column, Object val) {
|
||||
return likeLeft(getIfAbsent().test(val), null, column, val);
|
||||
return likeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_LEFT), null, column, val);
|
||||
}
|
||||
|
||||
default Children likeLeftIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return likeLeft(getIfAbsent().test(val), alias, column, val);
|
||||
return likeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children likeRightIfAbsent(KProperty<?> column, Object val) {
|
||||
return likeRight(getIfAbsent().test(val), null, column, val);
|
||||
return likeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), null, column, val);
|
||||
}
|
||||
|
||||
default Children likeRightIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return likeRight(getIfAbsent().test(val), alias, column, val);
|
||||
return likeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
}
|
||||
|
@ -9,18 +9,19 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.query.interfaces.CompareIfAbsent;
|
||||
import com.github.yulichang.query.interfaces.StringJoin;
|
||||
import com.github.yulichang.toolkit.Asserts;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.ThrowOptional;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
@ -77,7 +78,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
private Function<String, String> tableNameFunc;
|
||||
|
||||
@Getter
|
||||
private MybatisPlusJoinIfAbsent ifAbsent = ConfigProperties.ifAbsent;
|
||||
private BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = ConfigProperties.ifAbsent;
|
||||
|
||||
/**
|
||||
* 不建议直接 new 该实例,使用 Wrappers.lambdaQuery(entity)
|
||||
@ -93,7 +94,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments,
|
||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
|
||||
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct,
|
||||
MybatisPlusJoinIfAbsent ifAbsent) {
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
super.setEntity(entity);
|
||||
setEntityClass(entityClass);
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
@ -336,11 +337,16 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
return this.tableNameFunc.apply(decode);
|
||||
}
|
||||
|
||||
public MPJLambdaQueryWrapper<T> setIfAbsent(MybatisPlusJoinIfAbsent ifAbsent) {
|
||||
public MPJLambdaQueryWrapper<T> setIfAbsent(BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
this.ifAbsent = ifAbsent;
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public MPJLambdaQueryWrapper<T> setIfAbsent(Predicate<Object> ifAbsent) {
|
||||
this.ifAbsent = (o, k) -> ifAbsent.test(o);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于生成嵌套 sql
|
||||
* <p>故 sqlSelect selectColumn ignoreColumns from不向下传递</p>
|
||||
|
@ -11,13 +11,13 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.query.interfaces.CompareIfAbsent;
|
||||
import com.github.yulichang.query.interfaces.StringJoin;
|
||||
import com.github.yulichang.toolkit.Asserts;
|
||||
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.ThrowOptional;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.Chain;
|
||||
import lombok.Getter;
|
||||
|
||||
@ -28,6 +28,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
@ -90,7 +91,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
private boolean checkSqlInjection = false;
|
||||
|
||||
@Getter
|
||||
private MybatisPlusJoinIfAbsent ifAbsent = ConfigProperties.ifAbsent;
|
||||
private BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = ConfigProperties.ifAbsent;
|
||||
|
||||
|
||||
public MPJQueryWrapper() {
|
||||
@ -123,7 +124,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
SharedString sqlSelect, SharedString from, SharedString lastSql,
|
||||
SharedString sqlComment, SharedString sqlFirst,
|
||||
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct,
|
||||
MybatisPlusJoinIfAbsent ifAbsent) {
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
super.setEntity(entity);
|
||||
setEntityClass(entityClass);
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
@ -148,11 +149,16 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
return this;
|
||||
}
|
||||
|
||||
public MPJQueryWrapper<T> setIfAbsent(MybatisPlusJoinIfAbsent ifAbsent) {
|
||||
public MPJQueryWrapper<T> setIfAbsent(BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
this.ifAbsent = ifAbsent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MPJQueryWrapper<T> setIfAbsent(Predicate<Object> ifAbsent) {
|
||||
this.ifAbsent = (o, k) -> ifAbsent.test(o);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String columnToString(String column) {
|
||||
if (checkSqlInjection && MPJSqlInjectionUtils.check(column)) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.github.yulichang.query.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* 查询条件封装
|
||||
@ -13,7 +15,7 @@ import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
|
||||
MybatisPlusJoinIfAbsent getIfAbsent();
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> getIfAbsent();
|
||||
|
||||
/**
|
||||
* 等于 =
|
||||
@ -23,7 +25,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children eqIfAbsent(R column, Object val) {
|
||||
return eq(getIfAbsent().test(val), column, val);
|
||||
return eq(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.EQ), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,7 +36,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children neIfAbsent(R column, Object val) {
|
||||
return ne(getIfAbsent().test(val), column, val);
|
||||
return ne(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +47,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children gtIfAbsent(R column, Object val) {
|
||||
return gt(getIfAbsent().test(val), column, val);
|
||||
return gt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,7 +58,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children geIfAbsent(R column, Object val) {
|
||||
return ge(getIfAbsent().test(val), column, val);
|
||||
return ge(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,7 +69,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children ltIfAbsent(R column, Object val) {
|
||||
return lt(getIfAbsent().test(val), column, val);
|
||||
return lt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,7 +80,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children leIfAbsent(R column, Object val) {
|
||||
return le(getIfAbsent().test(val), column, val);
|
||||
return le(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +91,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children likeIfAbsent(R column, Object val) {
|
||||
return like(getIfAbsent().test(val), column, val);
|
||||
return like(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,7 +102,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeIfAbsent(R column, Object val) {
|
||||
return notLike(getIfAbsent().test(val), column, val);
|
||||
return notLike(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +113,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeLeftIfAbsent(R column, Object val) {
|
||||
return notLikeLeft(getIfAbsent().test(val), column, val);
|
||||
return notLikeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,7 +124,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeRightIfAbsent(R column, Object val) {
|
||||
return notLikeRight(getIfAbsent().test(val), column, val);
|
||||
return notLikeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_RIGHT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,7 +135,7 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children likeLeftIfAbsent(R column, Object val) {
|
||||
return likeLeft(getIfAbsent().test(val), column, val);
|
||||
return likeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,6 +146,6 @@ public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
* @return children
|
||||
*/
|
||||
default Children likeRightIfAbsent(R column, Object val) {
|
||||
return likeRight(getIfAbsent().test(val), column, val);
|
||||
return likeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), column, val);
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,12 @@ import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
||||
import com.github.yulichang.toolkit.Ref;
|
||||
import com.github.yulichang.toolkit.TableList;
|
||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.*;
|
||||
import lombok.Getter;
|
||||
@ -27,6 +27,7 @@ import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*;
|
||||
@ -122,7 +123,7 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
||||
* ifAbsent 策略
|
||||
*/
|
||||
@Getter
|
||||
protected MybatisPlusJoinIfAbsent ifAbsent = ConfigProperties.ifAbsent;
|
||||
protected BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = ConfigProperties.ifAbsent;
|
||||
|
||||
@Override
|
||||
public T getEntity() {
|
||||
@ -175,6 +176,11 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public Children setIfAbsent(BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
this.ifAbsent = ifAbsent;
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 ifAbsent
|
||||
* .setIfAbsent(val -> val != null && StringUtils.isNotBlank(val))
|
||||
@ -182,8 +188,8 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
|
||||
* @param ifAbsent 判断
|
||||
* @return Children
|
||||
*/
|
||||
public Children setIfAbsent(MybatisPlusJoinIfAbsent ifAbsent) {
|
||||
this.ifAbsent = ifAbsent;
|
||||
public Children setIfAbsent(Predicate<Object> ifAbsent) {
|
||||
this.ifAbsent = (obj, key) -> ifAbsent.test(obj);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
|
@ -6,10 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.Chain;
|
||||
import com.github.yulichang.wrapper.interfaces.Query;
|
||||
import com.github.yulichang.wrapper.interfaces.QueryLabel;
|
||||
@ -20,6 +20,7 @@ import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -125,7 +126,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
|
||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
|
||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
|
||||
TableList tableList, Integer index, String keyWord, Class<?> joinClass, String tableName,
|
||||
MybatisPlusJoinIfAbsent ifAbsent) {
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
super.setEntity(entity);
|
||||
super.setEntityClass(entityClass);
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.github.yulichang.wrapper.enums;
|
||||
|
||||
/**
|
||||
* if absent 枚举
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public enum IfAbsentSqlKeyWordEnum {
|
||||
EQ,
|
||||
NE,
|
||||
GT,
|
||||
GE,
|
||||
LT,
|
||||
LE,
|
||||
LIKE,
|
||||
NOT_LIKE,
|
||||
LIKE_RIGHT,
|
||||
NOT_LIKE_RIGHT,
|
||||
LIKE_LEFT,
|
||||
NOT_LIKE_LEFT
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||
@ -12,85 +14,85 @@ import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareIfAbsent<Children> extends Compare<Children> {
|
||||
|
||||
MybatisPlusJoinIfAbsent getIfAbsent();
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> getIfAbsent();
|
||||
|
||||
default <R> Children eqIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return eq(getIfAbsent().test(val), null, column, val);
|
||||
return eq(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.EQ), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children eqIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return eq(getIfAbsent().test(val), alias, column, val);
|
||||
return eq(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.EQ), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children neIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return ne(getIfAbsent().test(val), null, column, val);
|
||||
return ne(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children neIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return ne(getIfAbsent().test(val), alias, column, val);
|
||||
return ne(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children gtIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return gt(getIfAbsent().test(val), null, column, val);
|
||||
return gt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children gtIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return gt(getIfAbsent().test(val), alias, column, val);
|
||||
return gt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children geIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return ge(getIfAbsent().test(val), null, column, val);
|
||||
return ge(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children geIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return ge(getIfAbsent().test(val), alias, column, val);
|
||||
return ge(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children ltIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return lt(getIfAbsent().test(val), null, column, val);
|
||||
return lt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children ltIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return lt(getIfAbsent().test(val), alias, column, val);
|
||||
return lt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children leIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return le(getIfAbsent().test(val), null, column, val);
|
||||
return le(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children leIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return le(getIfAbsent().test(val), alias, column, val);
|
||||
return le(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return like(getIfAbsent().test(val), null, column, val);
|
||||
return like(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return like(getIfAbsent().test(val), alias, column, val);
|
||||
return like(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return notLike(getIfAbsent().test(val), null, column, val);
|
||||
return notLike(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return notLike(getIfAbsent().test(val), alias, column, val);
|
||||
return notLike(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeLeftIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return likeLeft(getIfAbsent().test(val), null, column, val);
|
||||
return likeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_LEFT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeLeftIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return likeLeft(getIfAbsent().test(val), alias, column, val);
|
||||
return likeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeRightIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return likeRight(getIfAbsent().test(val), null, column, val);
|
||||
return likeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeRightIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return likeRight(getIfAbsent().test(val), alias, column, val);
|
||||
return likeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||
@ -11,45 +13,45 @@ import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareStrIfAbsent<Children, R> extends CompareStr<Children, R> {
|
||||
|
||||
MybatisPlusJoinIfAbsent getIfAbsent();
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> getIfAbsent();
|
||||
|
||||
default Children eqIfAbsent(R column, Object val) {
|
||||
return eq(getIfAbsent().test(val), column, val);
|
||||
return eq(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.EQ), column, val);
|
||||
}
|
||||
|
||||
default Children neIfAbsent(R column, Object val) {
|
||||
return ne(getIfAbsent().test(val), column, val);
|
||||
return ne(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NE), column, val);
|
||||
}
|
||||
|
||||
default Children gtIfAbsent(R column, Object val) {
|
||||
return gt(getIfAbsent().test(val), column, val);
|
||||
return gt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GT), column, val);
|
||||
}
|
||||
|
||||
default Children geIfAbsent(R column, Object val) {
|
||||
return ge(getIfAbsent().test(val), column, val);
|
||||
return ge(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GE), column, val);
|
||||
}
|
||||
|
||||
default Children ltIfAbsent(R column, Object val) {
|
||||
return lt(getIfAbsent().test(val), column, val);
|
||||
return lt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LT), column, val);
|
||||
}
|
||||
|
||||
default Children leIfAbsent(R column, Object val) {
|
||||
return le(getIfAbsent().test(val), column, val);
|
||||
return le(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LE), column, val);
|
||||
}
|
||||
|
||||
default Children likeIfAbsent(R column, Object val) {
|
||||
return like(getIfAbsent().test(val), column, val);
|
||||
return like(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE), column, val);
|
||||
}
|
||||
|
||||
default Children notLikeIfAbsent(R column, Object val) {
|
||||
return notLike(getIfAbsent().test(val), column, val);
|
||||
return notLike(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE), column, val);
|
||||
}
|
||||
|
||||
default Children likeLeftIfAbsent(R column, Object val) {
|
||||
return likeLeft(getIfAbsent().test(val), column, val);
|
||||
return likeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
default Children likeRightIfAbsent(R column, Object val) {
|
||||
return likeRight(getIfAbsent().test(val), column, val);
|
||||
return likeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), column, val);
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,24 @@ public class IfAbsentTest {
|
||||
|
||||
@Test
|
||||
void ifAbsent() {
|
||||
assert IfAbsentEnum.NOT_EMPTY.test("\t", null);
|
||||
assert !IfAbsentEnum.NOT_EMPTY.test("", null);
|
||||
assert IfAbsentEnum.NOT_EMPTY.test(" ", null);
|
||||
assert IfAbsentEnum.NOT_EMPTY.test("\r", null);
|
||||
assert IfAbsentEnum.NOT_EMPTY.test("a", null);
|
||||
|
||||
assert !IfAbsentEnum.NOT_BLANK.test("\t", null);
|
||||
assert !IfAbsentEnum.NOT_BLANK.test("", null);
|
||||
assert !IfAbsentEnum.NOT_BLANK.test(" ", null);
|
||||
assert !IfAbsentEnum.NOT_BLANK.test("\r", null);
|
||||
assert IfAbsentEnum.NOT_BLANK.test("a", null);
|
||||
|
||||
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
||||
"t.address_id2, t.del, t.create_by, t.update_by FROM `user` t " +
|
||||
"WHERE t.del = false AND (t.id = ? AND t.head_img = ? AND t.`name` = ?)");
|
||||
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
||||
.selectAll(UserDO.class)
|
||||
.eq(UserDO::getId, 1)
|
||||
.eqIfAbsent(UserDO::getId, 1)
|
||||
.eqIfAbsent(UserDO::getPid, null)
|
||||
.eqIfAbsent(UserDO::getAddressId, "")
|
||||
.eqIfAbsent(UserDO::getImg, "\t")
|
||||
@ -41,7 +53,7 @@ public class IfAbsentTest {
|
||||
MPJLambdaWrapper<UserDO> wrapper1 = JoinWrappers.lambda(UserDO.class)
|
||||
.selectAll(UserDO.class)
|
||||
.setIfAbsent(IfAbsentEnum.NOT_BLANK)
|
||||
.eq(UserDO::getId, 1)
|
||||
.eqIfAbsent(UserDO::getId, 1)
|
||||
.eqIfAbsent(UserDO::getPid, null)
|
||||
.eqIfAbsent(UserDO::getAddressId, "")
|
||||
.eqIfAbsent(UserDO::getImg, "\t")
|
||||
@ -55,7 +67,7 @@ public class IfAbsentTest {
|
||||
MPJLambdaWrapper<UserDO> wrapper2 = JoinWrappers.lambda(UserDO.class)
|
||||
.selectAll(UserDO.class)
|
||||
.setIfAbsent(o -> true)
|
||||
.eq(UserDO::getId, 1)
|
||||
.eqIfAbsent(UserDO::getId, 1)
|
||||
.eqIfAbsent(UserDO::getPid, null)
|
||||
.eqIfAbsent(UserDO::getName, "")
|
||||
.eqIfAbsent(UserDO::getImg, "\t")
|
||||
|
Loading…
x
Reference in New Issue
Block a user