mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
ifPresent
This commit is contained in:
parent
26d7ff580b
commit
8a347e4a23
@ -3,7 +3,7 @@ package com.github.yulichang.autoconfigure;
|
||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusLanguageDriverAutoConfiguration;
|
||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||
import com.github.yulichang.autoconfigure.conditional.JoinSqlInjectorCondition;
|
||||
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinIfAbsentConsumer;
|
||||
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinIfPresentConsumer;
|
||||
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinPropertiesConsumer;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.MPJInterceptorConfig;
|
||||
@ -11,7 +11,7 @@ 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 com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.slf4j.Logger;
|
||||
@ -63,7 +63,7 @@ public class MybatisPlusJoinAutoConfiguration {
|
||||
|
||||
public MybatisPlusJoinAutoConfiguration(MybatisPlusJoinProperties properties,
|
||||
ObjectProvider<MybatisPlusJoinPropertiesConsumer> propertiesConsumers,
|
||||
ObjectProvider<MybatisPlusJoinIfAbsentConsumer> ifAbsentConsumers) {
|
||||
ObjectProvider<MybatisPlusJoinIfPresentConsumer> ifPresentConsumers) {
|
||||
this.properties = Optional.ofNullable(propertiesConsumers.getIfAvailable()).map(c -> c.config(properties)).orElse(properties);
|
||||
ConfigProperties.banner = this.properties.getBanner();
|
||||
ConfigProperties.subTableLogic = this.properties.getSubTableLogic();
|
||||
@ -72,9 +72,9 @@ public class MybatisPlusJoinAutoConfiguration {
|
||||
ConfigProperties.joinPrefix = this.properties.getJoinPrefix();
|
||||
ConfigProperties.logicDelType = this.properties.getLogicDelType();
|
||||
ConfigProperties.mappingMaxCount = this.properties.getMappingMaxCount();
|
||||
ConfigProperties.ifAbsent = Optional.ofNullable(ifAbsentConsumers.getIfAvailable())
|
||||
.map(m -> (BiPredicate<Object, IfAbsentSqlKeyWordEnum>) m)
|
||||
.orElse((val, key) -> this.properties.getIfAbsent().test(val));
|
||||
ConfigProperties.ifPresent = Optional.ofNullable(ifPresentConsumers.getIfAvailable())
|
||||
.map(m -> (BiPredicate<Object, IfPresentSqlKeyWordEnum>) m)
|
||||
.orElse((val, key) -> this.properties.getIfPresent().test(val));
|
||||
info("mybatis plus join properties config complete");
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.github.yulichang.autoconfigure;
|
||||
|
||||
import com.github.yulichang.config.enums.IfAbsentEnum;
|
||||
import com.github.yulichang.config.enums.IfPresentEnum;
|
||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@ -58,7 +58,7 @@ public class MybatisPlusJoinProperties {
|
||||
private String subQueryAlias = "st";
|
||||
|
||||
/**
|
||||
* Wrapper ifAbsent 判断策略
|
||||
* Wrapper ifPresent 判断策略
|
||||
* <p>
|
||||
* NOT_NULL 非null
|
||||
* <p>
|
||||
@ -66,5 +66,5 @@ public class MybatisPlusJoinProperties {
|
||||
* <p>
|
||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||
*/
|
||||
private IfAbsentEnum ifAbsent = IfAbsentEnum.NOT_EMPTY;
|
||||
private IfPresentEnum ifPresent = IfPresentEnum.NOT_EMPTY;
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
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> {
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.github.yulichang.autoconfigure.consumer;
|
||||
|
||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* 自定义IfPresent策略
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public interface MybatisPlusJoinIfPresentConsumer extends BiPredicate<Object, IfPresentSqlKeyWordEnum> {
|
||||
}
|
@ -57,10 +57,10 @@
|
||||
"description": "子查询表别名."
|
||||
},
|
||||
{
|
||||
"name": "mybatis-plus-join.if-absent",
|
||||
"defaultValue": "com.github.yulichang.config.enums.IfAbsentEnum.NOT_EMPTY",
|
||||
"type": "com.github.yulichang.config.enums.IfAbsentEnum",
|
||||
"description": "IfAbsent方法判断策略,如需自定义请用@Bean形式MybatisPlusJoinIfAbsent."
|
||||
"name": "mybatis-plus-join.if-present",
|
||||
"defaultValue": "com.github.yulichang.config.enums.IfPresentEnum.NOT_EMPTY",
|
||||
"type": "com.github.yulichang.config.enums.IfPresentEnum",
|
||||
"description": "IfPresent方法判断策略,如需自定义请用@Bean形式MybatisPlusJoinIfPresentConsumer."
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package com.github.yulichang.config;
|
||||
|
||||
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.IfPresentEnum;
|
||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
@ -51,7 +51,7 @@ public class ConfigProperties {
|
||||
*/
|
||||
public static String subQueryAlias = "st";
|
||||
/**
|
||||
* Wrapper ifAbsent 判断策略
|
||||
* Wrapper ifPresent 判断策略
|
||||
* <p>
|
||||
* NOT_NULL 非null
|
||||
* <p>
|
||||
@ -59,5 +59,5 @@ public class ConfigProperties {
|
||||
* <p>
|
||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||
*/
|
||||
public static BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = (val, key) -> IfAbsentEnum.NOT_EMPTY.test(val);
|
||||
public static BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = (val, key) -> IfPresentEnum.NOT_EMPTY.test(val);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import java.util.function.Predicate;
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public enum IfAbsentEnum implements Predicate<Object> {
|
||||
public enum IfPresentEnum implements Predicate<Object> {
|
||||
|
||||
/**
|
||||
* 非null
|
||||
@ -28,7 +28,7 @@ public enum IfAbsentEnum implements Predicate<Object> {
|
||||
|
||||
private final Predicate<Object> predicate;
|
||||
|
||||
IfAbsentEnum(Predicate<Object> predicate) {
|
||||
IfPresentEnum(Predicate<Object> predicate) {
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ 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.kt.interfaces.CompareIfAbsent;
|
||||
import com.github.yulichang.kt.interfaces.CompareIfPresent;
|
||||
import com.github.yulichang.kt.interfaces.Func;
|
||||
import com.github.yulichang.kt.interfaces.OnCompare;
|
||||
import com.github.yulichang.toolkit.KtUtils;
|
||||
@ -20,9 +20,9 @@ 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.IfPresentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.CompareStrIfAbsent;
|
||||
import com.github.yulichang.wrapper.interfaces.CompareStrIfPresent;
|
||||
import com.github.yulichang.wrapper.interfaces.FuncStr;
|
||||
import com.github.yulichang.wrapper.interfaces.Join;
|
||||
import kotlin.reflect.KProperty;
|
||||
@ -47,8 +47,8 @@ import static java.util.stream.Collectors.joining;
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked", "DuplicatedCode"})
|
||||
public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T, Children>> extends Wrapper<T>
|
||||
implements CompareIfAbsent<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
||||
CompareStrIfAbsent<Children, String>, FuncStr<Children, String> {
|
||||
implements CompareIfPresent<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
||||
CompareStrIfPresent<Children, String>, FuncStr<Children, String> {
|
||||
|
||||
/**
|
||||
* 占位符
|
||||
@ -125,10 +125,10 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
protected boolean checkSqlInjection = false;
|
||||
|
||||
/**
|
||||
* ifAbsent 策略
|
||||
* ifPresent 策略
|
||||
*/
|
||||
@Getter
|
||||
protected BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = ConfigProperties.ifAbsent;
|
||||
protected BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = ConfigProperties.ifPresent;
|
||||
|
||||
@Override
|
||||
public T getEntity() {
|
||||
@ -181,13 +181,13 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public Children setIfAbsent(BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
this.ifAbsent = ifAbsent;
|
||||
public Children setIfPresent(BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
||||
this.ifPresent = ifPresent;
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public Children setIfAbsent(Predicate<Object> ifAbsent) {
|
||||
this.ifAbsent = (o, k) -> ifAbsent.test(o);
|
||||
public Children setIfPresent(Predicate<Object> ifPresent) {
|
||||
this.ifPresent = (o, k) -> ifPresent.test(o);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@ -659,7 +659,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
index = null;
|
||||
isMain = true;
|
||||
isNo = false;
|
||||
ifAbsent = ConfigProperties.ifAbsent;
|
||||
ifPresent = ConfigProperties.ifPresent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,115 +0,0 @@
|
||||
package com.github.yulichang.kt.interfaces;
|
||||
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import kotlin.reflect.KProperty;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* ifAbsent
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareIfAbsent<Children> extends Compare<Children> {
|
||||
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> getIfAbsent();
|
||||
|
||||
default Children eqIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.EQ), alias, column, val);
|
||||
}
|
||||
|
||||
default Children neIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.NE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children gtIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.GT), alias, column, val);
|
||||
}
|
||||
|
||||
|
||||
default Children geIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.GE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children ltIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.LT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children leIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.LE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children likeIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.LIKE), alisa, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.NOT_LIKE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children likeLeftIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeLeftIfAbsent(KProperty<?> column, Object val) {
|
||||
return notLikeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_LEFT), null, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeLeftIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return notLikeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children likeRightIfAbsent(KProperty<?> column, Object 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, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeRightIfAbsent(KProperty<?> column, Object val) {
|
||||
return notLikeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_RIGHT), null, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeRightIfAbsent(String alias, KProperty<?> column, Object val) {
|
||||
return notLikeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package com.github.yulichang.kt.interfaces;
|
||||
|
||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
||||
import kotlin.reflect.KProperty;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* ifPresent
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareIfPresent<Children> extends Compare<Children> {
|
||||
|
||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> getIfPresent();
|
||||
|
||||
default Children eqIfPresent(KProperty<?> column, Object val) {
|
||||
return eq(getIfPresent().test(val, IfPresentSqlKeyWordEnum.EQ), null, column, val);
|
||||
}
|
||||
|
||||
default Children eqIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return eq(getIfPresent().test(val, IfPresentSqlKeyWordEnum.EQ), alias, column, val);
|
||||
}
|
||||
|
||||
default Children neIfPresent(KProperty<?> column, Object val) {
|
||||
return ne(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NE), null, column, val);
|
||||
}
|
||||
|
||||
default Children neIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return ne(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children gtIfPresent(KProperty<?> column, Object val) {
|
||||
return gt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GT), null, column, val);
|
||||
}
|
||||
|
||||
default Children gtIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return gt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GT), alias, column, val);
|
||||
}
|
||||
|
||||
|
||||
default Children geIfPresent(KProperty<?> column, Object val) {
|
||||
return ge(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GE), null, column, val);
|
||||
}
|
||||
|
||||
default Children geIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return ge(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children ltIfPresent(KProperty<?> column, Object val) {
|
||||
return lt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LT), null, column, val);
|
||||
}
|
||||
|
||||
default Children ltIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return lt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children leIfPresent(KProperty<?> column, Object val) {
|
||||
return le(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LE), null, column, val);
|
||||
}
|
||||
|
||||
default Children leIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return le(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children likeIfPresent(KProperty<?> column, Object val) {
|
||||
return like(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE), null, column, val);
|
||||
}
|
||||
|
||||
default Children likeIfPresent(String alisa, KProperty<?> column, Object val) {
|
||||
return like(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE), alisa, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeIfPresent(KProperty<?> column, Object val) {
|
||||
return notLike(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE), null, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return notLike(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE), alias, column, val);
|
||||
}
|
||||
|
||||
default Children likeLeftIfPresent(KProperty<?> column, Object val) {
|
||||
return likeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_LEFT), null, column, val);
|
||||
}
|
||||
|
||||
default Children likeLeftIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return likeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeLeftIfPresent(KProperty<?> column, Object val) {
|
||||
return notLikeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_LEFT), null, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeLeftIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return notLikeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children likeRightIfPresent(KProperty<?> column, Object val) {
|
||||
return likeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_RIGHT), null, column, val);
|
||||
}
|
||||
|
||||
default Children likeRightIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return likeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeRightIfPresent(KProperty<?> column, Object val) {
|
||||
return notLikeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_RIGHT), null, column, val);
|
||||
}
|
||||
|
||||
default Children notLikeRightIfPresent(String alias, KProperty<?> column, Object val) {
|
||||
return notLikeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
}
|
@ -9,12 +9,12 @@ 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.query.interfaces.CompareIfAbsent;
|
||||
import com.github.yulichang.query.interfaces.CompareIfPresent;
|
||||
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 com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@ -36,7 +36,7 @@ import java.util.stream.Collectors;
|
||||
@SuppressWarnings("unused")
|
||||
public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambdaQueryWrapper<T>>
|
||||
implements Query<MPJLambdaQueryWrapper<T>, T, SFunction<T, ?>>, StringJoin<MPJLambdaQueryWrapper<T>, T>,
|
||||
CompareIfAbsent<MPJLambdaQueryWrapper<T>, SFunction<T, ?>> {
|
||||
CompareIfPresent<MPJLambdaQueryWrapper<T>, SFunction<T, ?>> {
|
||||
|
||||
/**
|
||||
* 查询字段
|
||||
@ -78,7 +78,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
private Function<String, String> tableNameFunc;
|
||||
|
||||
@Getter
|
||||
private BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = ConfigProperties.ifAbsent;
|
||||
private BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = ConfigProperties.ifPresent;
|
||||
|
||||
/**
|
||||
* 不建议直接 new 该实例,使用 Wrappers.lambdaQuery(entity)
|
||||
@ -94,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,
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
||||
super.setEntity(entity);
|
||||
setEntityClass(entityClass);
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
@ -108,7 +108,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
this.selectColumns = selectColumns;
|
||||
this.ignoreColumns = ignoreColumns;
|
||||
this.selectDistinct = selectDistinct;
|
||||
this.ifAbsent = ifAbsent;
|
||||
this.ifPresent = ifPresent;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,7 +235,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
public MPJQueryWrapper<T> stringQuery() {
|
||||
return new MPJQueryWrapper<>(getEntity(), getEntityClass(), paramNameSeq, paramNameValuePairs,
|
||||
expression, sqlSelect, from, lastSql, sqlComment, sqlFirst, selectColumns, ignoreColumns,
|
||||
selectDistinct, ifAbsent);
|
||||
selectDistinct, ifPresent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -337,13 +337,13 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
return this.tableNameFunc.apply(decode);
|
||||
}
|
||||
|
||||
public MPJLambdaQueryWrapper<T> setIfAbsent(BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
this.ifAbsent = ifAbsent;
|
||||
public MPJLambdaQueryWrapper<T> setIfPresent(BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
||||
this.ifPresent = ifPresent;
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public MPJLambdaQueryWrapper<T> setIfAbsent(Predicate<Object> ifAbsent) {
|
||||
this.ifAbsent = (o, k) -> ifAbsent.test(o);
|
||||
public MPJLambdaQueryWrapper<T> setIfPresent(Predicate<Object> ifPresent) {
|
||||
this.ifPresent = (o, k) -> ifPresent.test(o);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@ -355,7 +355,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
protected MPJLambdaQueryWrapper<T> instance() {
|
||||
return new MPJLambdaQueryWrapper<>(getEntity(), getEntityClass(), null, null, paramNameSeq, paramNameValuePairs,
|
||||
new MergeSegments(), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||
null, null, selectDistinct, ifAbsent);
|
||||
null, null, selectDistinct, ifPresent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -391,7 +391,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
from.toNull();
|
||||
selectColumns.clear();
|
||||
ignoreColumns.clear();
|
||||
ifAbsent = ConfigProperties.ifAbsent;
|
||||
ifPresent = ConfigProperties.ifPresent;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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.query.interfaces.CompareIfAbsent;
|
||||
import com.github.yulichang.query.interfaces.CompareIfPresent;
|
||||
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.enums.IfPresentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.Chain;
|
||||
import lombok.Getter;
|
||||
|
||||
@ -43,7 +43,7 @@ import java.util.stream.Collectors;
|
||||
@SuppressWarnings("unused")
|
||||
public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapper<T>> implements
|
||||
Query<MPJQueryWrapper<T>, T, String>, StringJoin<MPJQueryWrapper<T>, T>, Chain<T>,
|
||||
CompareIfAbsent<MPJQueryWrapper<T>, String> {
|
||||
CompareIfPresent<MPJQueryWrapper<T>, String> {
|
||||
|
||||
/**
|
||||
* 查询字段
|
||||
@ -91,7 +91,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
private boolean checkSqlInjection = false;
|
||||
|
||||
@Getter
|
||||
private BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = ConfigProperties.ifAbsent;
|
||||
private BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = ConfigProperties.ifPresent;
|
||||
|
||||
|
||||
public MPJQueryWrapper() {
|
||||
@ -124,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,
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
||||
super.setEntity(entity);
|
||||
setEntityClass(entityClass);
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
@ -138,7 +138,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
this.selectColumns = selectColumns;
|
||||
this.ignoreColumns = ignoreColumns;
|
||||
this.selectDistinct = selectDistinct;
|
||||
this.ifAbsent = ifAbsent;
|
||||
this.ifPresent = ifPresent;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,13 +149,13 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
return this;
|
||||
}
|
||||
|
||||
public MPJQueryWrapper<T> setIfAbsent(BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
this.ifAbsent = ifAbsent;
|
||||
public MPJQueryWrapper<T> setIfPresent(BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
||||
this.ifPresent = ifPresent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MPJQueryWrapper<T> setIfAbsent(Predicate<Object> ifAbsent) {
|
||||
this.ifAbsent = (o, k) -> ifAbsent.test(o);
|
||||
public MPJQueryWrapper<T> setIfPresent(Predicate<Object> ifPresent) {
|
||||
this.ifPresent = (o, k) -> ifPresent.test(o);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -354,7 +354,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
*/
|
||||
public MPJLambdaQueryWrapper<T> lambda() {
|
||||
return new MPJLambdaQueryWrapper<>(getEntity(), getEntityClass(), from, sqlSelect, paramNameSeq, paramNameValuePairs,
|
||||
expression, lastSql, sqlComment, getSqlFirstField(), selectColumns, ignoreColumns, selectDistinct, ifAbsent);
|
||||
expression, lastSql, sqlComment, getSqlFirstField(), selectColumns, ignoreColumns, selectDistinct, ifPresent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -391,7 +391,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
protected MPJQueryWrapper<T> instance() {
|
||||
return new MPJQueryWrapper<>(getEntity(), getEntityClass(), paramNameSeq, paramNameValuePairs, new MergeSegments(),
|
||||
null, null, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||
null, null, selectDistinct, ifAbsent);
|
||||
null, null, selectDistinct, ifPresent);
|
||||
}
|
||||
|
||||
|
||||
@ -402,7 +402,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
from.toNull();
|
||||
selectColumns.clear();
|
||||
ignoreColumns.clear();
|
||||
ifAbsent = ConfigProperties.ifAbsent;
|
||||
ifPresent = ConfigProperties.ifPresent;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,151 +0,0 @@
|
||||
package com.github.yulichang.query.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* 查询条件封装
|
||||
* <p>比较值</p>
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
|
||||
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> getIfAbsent();
|
||||
|
||||
/**
|
||||
* 等于 =
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children eqIfAbsent(R column, Object val) {
|
||||
return eq(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.EQ), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 不等于 <>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children neIfAbsent(R column, Object val) {
|
||||
return ne(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大于 >
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children gtIfAbsent(R column, Object val) {
|
||||
return gt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大于等于 >=
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children geIfAbsent(R column, Object val) {
|
||||
return ge(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于 <
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children ltIfAbsent(R column, Object val) {
|
||||
return lt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于等于 <=
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children leIfAbsent(R column, Object val) {
|
||||
return le(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE '%值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children likeIfAbsent(R column, Object val) {
|
||||
return like(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE '%值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeIfAbsent(R column, Object val) {
|
||||
return notLike(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE '%值'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeLeftIfAbsent(R column, Object val) {
|
||||
return notLikeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE '值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeRightIfAbsent(R column, Object val) {
|
||||
return notLikeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_RIGHT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE '%值'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children likeLeftIfAbsent(R column, Object val) {
|
||||
return likeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE '值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children likeRightIfAbsent(R column, Object val) {
|
||||
return likeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), column, val);
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
package com.github.yulichang.query.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
|
||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* 查询条件封装
|
||||
* <p>比较值</p>
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareIfPresent<Children, R> extends Compare<Children, R> {
|
||||
|
||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> getIfPresent();
|
||||
|
||||
/**
|
||||
* 等于 =
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children eqIfPresent(R column, Object val) {
|
||||
return eq(getIfPresent().test(val, IfPresentSqlKeyWordEnum.EQ), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 不等于 <>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children neIfPresent(R column, Object val) {
|
||||
return ne(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大于 >
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children gtIfPresent(R column, Object val) {
|
||||
return gt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大于等于 >=
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children geIfPresent(R column, Object val) {
|
||||
return ge(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于 <
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children ltIfPresent(R column, Object val) {
|
||||
return lt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于等于 <=
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children leIfPresent(R column, Object val) {
|
||||
return le(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE '%值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children likeIfPresent(R column, Object val) {
|
||||
return like(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE '%值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeIfPresent(R column, Object val) {
|
||||
return notLike(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE '%值'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeLeftIfPresent(R column, Object val) {
|
||||
return notLikeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE '值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeRightIfPresent(R column, Object val) {
|
||||
return notLikeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_RIGHT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE '%值'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children likeLeftIfPresent(R column, Object val) {
|
||||
return likeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE '值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children likeRightIfPresent(R column, Object val) {
|
||||
return likeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_RIGHT), column, val);
|
||||
}
|
||||
}
|
@ -18,7 +18,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.IfPresentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.*;
|
||||
import lombok.Getter;
|
||||
@ -42,8 +42,8 @@ import static java.util.stream.Collectors.joining;
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "unused", "DuplicatedCode"})
|
||||
public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrapper<T, Children>> extends Wrapper<T>
|
||||
implements CompareIfAbsent<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
||||
CompareStrIfAbsent<Children, String>, FuncStr<Children, String> {
|
||||
implements CompareIfPresent<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
||||
CompareStrIfPresent<Children, String>, FuncStr<Children, String> {
|
||||
|
||||
/**
|
||||
* 占位符
|
||||
@ -120,10 +120,10 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
protected boolean checkSqlInjection = false;
|
||||
|
||||
/**
|
||||
* ifAbsent 策略
|
||||
* ifPresent 策略
|
||||
*/
|
||||
@Getter
|
||||
protected BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = ConfigProperties.ifAbsent;
|
||||
protected BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = ConfigProperties.ifPresent;
|
||||
|
||||
@Override
|
||||
public T getEntity() {
|
||||
@ -176,20 +176,20 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public Children setIfAbsent(BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
this.ifAbsent = ifAbsent;
|
||||
public Children setIfPresent(BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
||||
this.ifPresent = ifPresent;
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 ifAbsent
|
||||
* .setIfAbsent(val -> val != null && StringUtils.isNotBlank(val))
|
||||
* 设置 ifPresent
|
||||
* .ifPresent(val -> val != null && StringUtils.isNotBlank(val))
|
||||
*
|
||||
* @param ifAbsent 判断
|
||||
* @param ifPresent 判断
|
||||
* @return Children
|
||||
*/
|
||||
public Children setIfAbsent(Predicate<Object> ifAbsent) {
|
||||
this.ifAbsent = (obj, key) -> ifAbsent.test(obj);
|
||||
public Children setIfPresent(Predicate<Object> ifPresent) {
|
||||
this.ifPresent = (obj, key) -> ifPresent.test(obj);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@ -773,7 +773,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
index = null;
|
||||
isMain = true;
|
||||
isOn = false;
|
||||
ifAbsent = ConfigProperties.ifAbsent;
|
||||
ifPresent = ConfigProperties.ifPresent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,7 +9,7 @@ import com.github.yulichang.config.ConfigProperties;
|
||||
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.enums.IfPresentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.Chain;
|
||||
import com.github.yulichang.wrapper.interfaces.Query;
|
||||
import com.github.yulichang.wrapper.interfaces.QueryLabel;
|
||||
@ -126,7 +126,7 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
|
||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
|
||||
TableList tableList, Integer index, String keyWord, Class<?> joinClass, String tableName,
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent) {
|
||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
||||
super.setEntity(entity);
|
||||
super.setEntityClass(entityClass);
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
@ -142,7 +142,7 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
this.keyWord = keyWord;
|
||||
this.joinClass = joinClass;
|
||||
this.tableName = tableName;
|
||||
this.ifAbsent = ifAbsent;
|
||||
this.ifPresent = ifPresent;
|
||||
}
|
||||
|
||||
|
||||
@ -211,7 +211,7 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
MPJLambdaWrapper<E> wrapper = new MPJLambdaWrapper<E>(null, clazz, SharedString.emptyString(),
|
||||
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
||||
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||
new TableList(), null, null, null, null, ifAbsent) {
|
||||
new TableList(), null, null, null, null, ifPresent) {
|
||||
};
|
||||
wrapper.tableList.setAlias(st);
|
||||
wrapper.tableList.setRootClass(clazz);
|
||||
@ -406,7 +406,7 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
protected MPJLambdaWrapper<T> instance(Integer index, String keyWord, Class<?> joinClass, String tableName) {
|
||||
return new MPJLambdaWrapper<>(getEntity(), getEntityClass(), null, paramNameSeq, paramNameValuePairs,
|
||||
new MergeSegments(), this.paramAlias, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||
this.tableList, index, keyWord, joinClass, tableName, ifAbsent);
|
||||
this.tableList, index, keyWord, joinClass, tableName, ifPresent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -419,6 +419,6 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
if (Objects.nonNull(wrapperMap)) wrapperMap.clear();
|
||||
if (Objects.nonNull(unionSql)) unionSql.toEmpty();
|
||||
resultMapMybatisLabel.clear();
|
||||
ifAbsent = ConfigProperties.ifAbsent;
|
||||
ifPresent = ConfigProperties.ifPresent;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package com.github.yulichang.wrapper.enums;
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
public enum IfAbsentSqlKeyWordEnum {
|
||||
public enum IfPresentSqlKeyWordEnum {
|
||||
EQ,
|
||||
NE,
|
||||
GT,
|
@ -1,114 +0,0 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareIfAbsent<Children> extends Compare<Children> {
|
||||
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> getIfAbsent();
|
||||
|
||||
default <R> Children eqIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.EQ), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children neIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.NE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children gtIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.GT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children geIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.GE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children ltIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.LT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children leIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.LE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.LIKE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.NOT_LIKE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeLeftIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeLeftIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return notLikeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_LEFT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeLeftIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return notLikeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeRightIfAbsent(SFunction<R, ?> column, Object 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, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeRightIfAbsent(SFunction<R, ?> column, Object val) {
|
||||
return notLikeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_RIGHT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeRightIfAbsent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return notLikeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareIfPresent<Children> extends Compare<Children> {
|
||||
|
||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> getIfPresent();
|
||||
|
||||
default <R> Children eqIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return eq(getIfPresent().test(val, IfPresentSqlKeyWordEnum.EQ), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children eqIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return eq(getIfPresent().test(val, IfPresentSqlKeyWordEnum.EQ), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children neIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return ne(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children neIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return ne(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children gtIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return gt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children gtIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return gt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children geIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return ge(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children geIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return ge(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children ltIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return lt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children ltIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return lt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children leIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return le(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children leIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return le(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return like(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return like(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return notLike(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return notLike(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeLeftIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return likeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_LEFT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeLeftIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return likeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeLeftIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return notLikeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_LEFT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeLeftIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return notLikeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_LEFT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeRightIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return likeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_RIGHT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children likeRightIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return likeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeRightIfPresent(SFunction<R, ?> column, Object val) {
|
||||
return notLikeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_RIGHT), null, column, val);
|
||||
}
|
||||
|
||||
default <R> Children notLikeRightIfPresent(String alias, SFunction<R, ?> column, Object val) {
|
||||
return notLikeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_RIGHT), alias, column, val);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareStrIfAbsent<Children, R> extends CompareStr<Children, R> {
|
||||
|
||||
BiPredicate<Object, IfAbsentSqlKeyWordEnum> getIfAbsent();
|
||||
|
||||
default Children eqIfAbsent(R column, Object val) {
|
||||
return eq(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.EQ), column, val);
|
||||
}
|
||||
|
||||
default Children neIfAbsent(R column, Object val) {
|
||||
return ne(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NE), column, val);
|
||||
}
|
||||
|
||||
default Children gtIfAbsent(R column, Object val) {
|
||||
return gt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GT), column, val);
|
||||
}
|
||||
|
||||
default Children geIfAbsent(R column, Object val) {
|
||||
return ge(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.GE), column, val);
|
||||
}
|
||||
|
||||
default Children ltIfAbsent(R column, Object val) {
|
||||
return lt(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LT), column, val);
|
||||
}
|
||||
|
||||
default Children leIfAbsent(R column, Object val) {
|
||||
return le(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LE), column, val);
|
||||
}
|
||||
|
||||
default Children likeIfAbsent(R column, Object val) {
|
||||
return like(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE), column, val);
|
||||
}
|
||||
|
||||
default Children notLikeIfAbsent(R column, Object val) {
|
||||
return notLike(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE), column, val);
|
||||
}
|
||||
|
||||
default Children likeLeftIfAbsent(R column, Object val) {
|
||||
return likeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
default Children likeRightIfAbsent(R column, Object val) {
|
||||
return likeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.LIKE_RIGHT), column, val);
|
||||
}
|
||||
|
||||
default Children notLikeLeftIfAbsent(R column, Object val) {
|
||||
return notLikeLeft(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
default Children notLikeRightIfAbsent(R column, Object val) {
|
||||
return notLikeRight(getIfAbsent().test(val, IfAbsentSqlKeyWordEnum.NOT_LIKE_RIGHT), column, val);
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.9
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareStrIfPresent<Children, R> extends CompareStr<Children, R> {
|
||||
|
||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> getIfPresent();
|
||||
|
||||
default Children eqIfPresent(R column, Object val) {
|
||||
return eq(getIfPresent().test(val, IfPresentSqlKeyWordEnum.EQ), column, val);
|
||||
}
|
||||
|
||||
default Children neIfPresent(R column, Object val) {
|
||||
return ne(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NE), column, val);
|
||||
}
|
||||
|
||||
default Children gtIfPresent(R column, Object val) {
|
||||
return gt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GT), column, val);
|
||||
}
|
||||
|
||||
default Children geIfPresent(R column, Object val) {
|
||||
return ge(getIfPresent().test(val, IfPresentSqlKeyWordEnum.GE), column, val);
|
||||
}
|
||||
|
||||
default Children ltIfPresent(R column, Object val) {
|
||||
return lt(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LT), column, val);
|
||||
}
|
||||
|
||||
default Children leIfPresent(R column, Object val) {
|
||||
return le(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LE), column, val);
|
||||
}
|
||||
|
||||
default Children likeIfPresent(R column, Object val) {
|
||||
return like(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE), column, val);
|
||||
}
|
||||
|
||||
default Children notLikeIfPresent(R column, Object val) {
|
||||
return notLike(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE), column, val);
|
||||
}
|
||||
|
||||
default Children likeLeftIfPresent(R column, Object val) {
|
||||
return likeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
default Children likeRightIfPresent(R column, Object val) {
|
||||
return likeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.LIKE_RIGHT), column, val);
|
||||
}
|
||||
|
||||
default Children notLikeLeftIfPresent(R column, Object val) {
|
||||
return notLikeLeft(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_LEFT), column, val);
|
||||
}
|
||||
|
||||
default Children notLikeRightIfPresent(R column, Object val) {
|
||||
return notLikeRight(getIfPresent().test(val, IfPresentSqlKeyWordEnum.NOT_LIKE_RIGHT), column, val);
|
||||
}
|
||||
}
|
@ -3,13 +3,13 @@ package com.github.yulichang.mybatisplusjoin.solon.plugin;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.MPJInterceptorConfig;
|
||||
import com.github.yulichang.config.enums.IfAbsentEnum;
|
||||
import com.github.yulichang.config.enums.IfPresentEnum;
|
||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||
import com.github.yulichang.extension.mapping.config.MappingConfig;
|
||||
import com.github.yulichang.injector.MPJSqlInjector;
|
||||
import com.github.yulichang.toolkit.SpringContentUtils;
|
||||
import com.github.yulichang.toolkit.reflect.GenericTypeUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.ibatis.solon.MybatisAdapter;
|
||||
import org.apache.ibatis.solon.integration.MybatisAdapterManager;
|
||||
@ -59,10 +59,10 @@ public class XPluginImpl implements Plugin {
|
||||
Arrays.stream(LogicDelTypeEnum.values()).filter(e -> e.name().equalsIgnoreCase(val)).findFirst()
|
||||
.orElseThrow(() -> ExceptionUtils.mpe("mybatis-plus-join.logicDelType 配置错误")));
|
||||
ConfigProperties.mappingMaxCount = prop.get("mappingMaxCount", Integer::parseInt);
|
||||
ConfigProperties.ifAbsent = prop.get("ifAbsent", val ->
|
||||
Arrays.stream(IfAbsentEnum.values()).filter(e -> e.name().equalsIgnoreCase(val)).findFirst()
|
||||
.map(m -> (BiPredicate<Object, IfAbsentSqlKeyWordEnum>) (o, enums) -> m.test(o))
|
||||
.orElseThrow(() -> ExceptionUtils.mpe("mybatis-plus-join.ifAbsent 配置错误")));
|
||||
ConfigProperties.ifPresent = prop.get("ifPresent", val ->
|
||||
Arrays.stream(IfPresentEnum.values()).filter(e -> e.name().equalsIgnoreCase(val)).findFirst()
|
||||
.map(m -> (BiPredicate<Object, IfPresentSqlKeyWordEnum>) (o, enums) -> m.test(o))
|
||||
.orElseThrow(() -> ExceptionUtils.mpe("mybatis-plus-join.ifPresent 配置错误")));
|
||||
// 后续操作
|
||||
context.onEvent(AppLoadEndEvent.class, e -> {
|
||||
List<SqlSessionFactory> sqlSessionFactoryList = MybatisAdapterManager.getAll().values().stream()
|
||||
|
@ -34,7 +34,8 @@ public class CustomWrapperTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <X> CWrapper<T> eqIfAbsent(SFunction<X, ?> column, Object val) {
|
||||
@Override
|
||||
public <X> CWrapper<T> eqIfPresent(SFunction<X, ?> column, Object val) {
|
||||
super.eq(Objects.nonNull(val), column, val);
|
||||
return this;
|
||||
}
|
||||
@ -47,7 +48,7 @@ public class CustomWrapperTest {
|
||||
.selectAll(UserDO.class)
|
||||
// .toChildren(new Ref<CWrapper<UserDO>>())
|
||||
.toChildren(CWrapper::toCWrapper)
|
||||
.eqIfAbsent(UserDO::getId, 1);
|
||||
.eqIfPresent(UserDO::getId, 1);
|
||||
List<UserDO> dos = userMapper.selectList(wrapper);
|
||||
dos.forEach(System.out::println);
|
||||
|
||||
@ -56,7 +57,7 @@ public class CustomWrapperTest {
|
||||
.selectAll(UserDO.class)
|
||||
.toChildren(new Ref<CWrapper<UserDO>>())
|
||||
// .toChildren(CWrapper::toCWrapper)
|
||||
.eqIfAbsent(UserDO::getId, null);
|
||||
.eqIfPresent(UserDO::getId, null);
|
||||
List<UserDO> dos1 = userMapper.selectList(wrapper1);
|
||||
dos1.forEach(System.out::println);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.github.yulichang.test.join.m;
|
||||
|
||||
import com.github.yulichang.config.enums.IfAbsentEnum;
|
||||
import com.github.yulichang.config.enums.IfPresentEnum;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.util.Reset;
|
||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||
@ -13,7 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class IfAbsentTest {
|
||||
public class IfPresentTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@ -21,35 +21,35 @@ public class IfAbsentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void ifAbsent() {
|
||||
assert IfAbsentEnum.NOT_EMPTY.test("\t");
|
||||
assert !IfAbsentEnum.NOT_EMPTY.test("");
|
||||
assert IfAbsentEnum.NOT_EMPTY.test(" ");
|
||||
assert IfAbsentEnum.NOT_EMPTY.test("\r");
|
||||
assert IfAbsentEnum.NOT_EMPTY.test("a");
|
||||
assert IfAbsentEnum.NOT_EMPTY.test(1);
|
||||
assert IfAbsentEnum.NOT_EMPTY.test(true);
|
||||
assert IfAbsentEnum.NOT_EMPTY.test('A');
|
||||
void ifPresent() {
|
||||
assert IfPresentEnum.NOT_EMPTY.test("\t");
|
||||
assert !IfPresentEnum.NOT_EMPTY.test("");
|
||||
assert IfPresentEnum.NOT_EMPTY.test(" ");
|
||||
assert IfPresentEnum.NOT_EMPTY.test("\r");
|
||||
assert IfPresentEnum.NOT_EMPTY.test("a");
|
||||
assert IfPresentEnum.NOT_EMPTY.test(1);
|
||||
assert IfPresentEnum.NOT_EMPTY.test(true);
|
||||
assert IfPresentEnum.NOT_EMPTY.test('A');
|
||||
|
||||
assert !IfAbsentEnum.NOT_BLANK.test("\t");
|
||||
assert !IfAbsentEnum.NOT_BLANK.test("");
|
||||
assert !IfAbsentEnum.NOT_BLANK.test(" ");
|
||||
assert !IfAbsentEnum.NOT_BLANK.test("\r");
|
||||
assert IfAbsentEnum.NOT_BLANK.test("a");
|
||||
assert IfAbsentEnum.NOT_EMPTY.test(1);
|
||||
assert IfAbsentEnum.NOT_EMPTY.test(true);
|
||||
assert IfAbsentEnum.NOT_EMPTY.test('A');
|
||||
assert !IfPresentEnum.NOT_BLANK.test("\t");
|
||||
assert !IfPresentEnum.NOT_BLANK.test("");
|
||||
assert !IfPresentEnum.NOT_BLANK.test(" ");
|
||||
assert !IfPresentEnum.NOT_BLANK.test("\r");
|
||||
assert IfPresentEnum.NOT_BLANK.test("a");
|
||||
assert IfPresentEnum.NOT_EMPTY.test(1);
|
||||
assert IfPresentEnum.NOT_EMPTY.test(true);
|
||||
assert IfPresentEnum.NOT_EMPTY.test('A');
|
||||
|
||||
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)
|
||||
.eqIfAbsent(UserDO::getId, 1)
|
||||
.eqIfAbsent(UserDO::getPid, null)
|
||||
.eqIfAbsent(UserDO::getAddressId, "")
|
||||
.eqIfAbsent(UserDO::getImg, "\t")
|
||||
.eqIfAbsent(UserDO::getName, "张三 1");
|
||||
.eqIfPresent(UserDO::getId, 1)
|
||||
.eqIfPresent(UserDO::getPid, null)
|
||||
.eqIfPresent(UserDO::getAddressId, "")
|
||||
.eqIfPresent(UserDO::getImg, "\t")
|
||||
.eqIfPresent(UserDO::getName, "张三 1");
|
||||
List<UserDO> list = wrapper.list();
|
||||
list.forEach(System.out::println);
|
||||
|
||||
@ -58,12 +58,12 @@ public class IfAbsentTest {
|
||||
"WHERE t.del = false AND (t.id = ? AND t.`name` = ?)");
|
||||
MPJLambdaWrapper<UserDO> wrapper1 = JoinWrappers.lambda(UserDO.class)
|
||||
.selectAll(UserDO.class)
|
||||
.setIfAbsent(IfAbsentEnum.NOT_BLANK)
|
||||
.eqIfAbsent(UserDO::getId, 1)
|
||||
.eqIfAbsent(UserDO::getPid, null)
|
||||
.eqIfAbsent(UserDO::getAddressId, "")
|
||||
.eqIfAbsent(UserDO::getImg, "\t")
|
||||
.eqIfAbsent(UserDO::getName, "张三 1");
|
||||
.setIfPresent(IfPresentEnum.NOT_BLANK)
|
||||
.eqIfPresent(UserDO::getId, 1)
|
||||
.eqIfPresent(UserDO::getPid, null)
|
||||
.eqIfPresent(UserDO::getAddressId, "")
|
||||
.eqIfPresent(UserDO::getImg, "\t")
|
||||
.eqIfPresent(UserDO::getName, "张三 1");
|
||||
List<UserDO> list1 = wrapper1.list();
|
||||
list1.forEach(System.out::println);
|
||||
|
||||
@ -72,12 +72,12 @@ public class IfAbsentTest {
|
||||
"WHERE t.del = false AND (t.id = ? AND t.pid = ? AND t.`name` = ? AND t.head_img = ? AND t.`name` = ?)");
|
||||
MPJLambdaWrapper<UserDO> wrapper2 = JoinWrappers.lambda(UserDO.class)
|
||||
.selectAll(UserDO.class)
|
||||
.setIfAbsent(o -> true)
|
||||
.eqIfAbsent(UserDO::getId, 1)
|
||||
.eqIfAbsent(UserDO::getPid, null)
|
||||
.eqIfAbsent(UserDO::getName, "")
|
||||
.eqIfAbsent(UserDO::getImg, "\t")
|
||||
.eqIfAbsent(UserDO::getName, "张三 1");
|
||||
.setIfPresent(o -> true)
|
||||
.eqIfPresent(UserDO::getId, 1)
|
||||
.eqIfPresent(UserDO::getPid, null)
|
||||
.eqIfPresent(UserDO::getName, "")
|
||||
.eqIfPresent(UserDO::getImg, "\t")
|
||||
.eqIfPresent(UserDO::getName, "张三 1");
|
||||
List<UserDO> list2 = wrapper2.list();
|
||||
list2.forEach(System.out::println);
|
||||
}
|
@ -52,4 +52,7 @@ open class UserDO : ID<Int?>(), Serializable {
|
||||
|
||||
@TableField(exist = false)
|
||||
var addressList2: List<AddressDO>? = null
|
||||
override fun toString(): String {
|
||||
return "UserDO(pid=$pid, name=$name, json=$json, sex=$sex, img=$img, createTime=$createTime, addressId=$addressId, addressId2=$addressId2, del=$del, createBy=$createBy, createName=$createName, updateBy=$updateBy, updateName=$updateName, alias=$alias, children=$children, addressList=$addressList, addressList2=$addressList2)"
|
||||
}
|
||||
}
|
||||
|
@ -734,7 +734,7 @@ class LambdaWrapperTest {
|
||||
assert(dos!!.size == 4)
|
||||
|
||||
ThreadLocalUtils.set(
|
||||
"SELECT id,pid,`name`,`json`,sex,head_img,create_time,address_id,address_id2,del,create_by,update_by FROM `user` t WHERE t.del=false AND (t.id > ? AND t.id < ?)",
|
||||
"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.id < ?)",
|
||||
"SELECT * FROM `user` t WHERE t.del=false AND (t.id > ? AND t.id < ?) "
|
||||
)
|
||||
val dos1: MutableList<UserDO?>? = userMapper.selectList(
|
||||
@ -1009,7 +1009,7 @@ class LambdaWrapperTest {
|
||||
@Test
|
||||
fun joinOrder() {
|
||||
ThreadLocalUtils.set(
|
||||
"SELECT id,user_id,name FROM order_t t ORDER BY t.name DESC",
|
||||
"SELECT t.id, t.user_id, t.name FROM order_t t ORDER BY t.name DESC",
|
||||
"SELECT id,user_id,name FROM order_t t ORDER BY t.name desc"
|
||||
)
|
||||
val wrapper: KtLambdaWrapper<OrderDO> = KtWrappers.query(OrderDO::class.java)
|
||||
|
@ -26,7 +26,7 @@ class CustomWrapperTest {
|
||||
//自定义wrapper扩展
|
||||
class CWrapper<T> : KtLambdaWrapper<T>() {
|
||||
|
||||
fun eqIfAbsent(column: KProperty<*>, `val`: Any?): CWrapper<T> {
|
||||
override fun eqIfPresent(column: KProperty<*>?, `val`: Any?): CWrapper<T> {
|
||||
eq(Objects.nonNull(`val`), column, `val`)
|
||||
return this
|
||||
}
|
||||
@ -42,16 +42,16 @@ class CustomWrapperTest {
|
||||
fun testWrapperCustomer() {
|
||||
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 = ?)")
|
||||
val wrapper: CWrapper<UserDO> = CWrapper<UserDO>()
|
||||
.selectAll(UserDO::class.java)
|
||||
.toChildren<CWrapper<UserDO>> { CWrapper.toCWrapper() }
|
||||
.eqIfAbsent(UserDO::id, 1)
|
||||
.selectAll(UserDO::class.java)
|
||||
.toChildren<CWrapper<UserDO>> { CWrapper.toCWrapper() }
|
||||
.eqIfPresent(UserDO::id, 1)
|
||||
val dos = userMapper?.selectList(wrapper)
|
||||
dos?.forEach(System.out::println)
|
||||
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")
|
||||
val wrapper1: CWrapper<UserDO> = CWrapper<UserDO>()
|
||||
.selectAll(UserDO::class.java)
|
||||
.toChildren(Ref<CWrapper<UserDO>>())
|
||||
.eqIfAbsent(UserDO::id, null)
|
||||
.selectAll(UserDO::class.java)
|
||||
.toChildren(Ref<CWrapper<UserDO>>())
|
||||
.eqIfPresent(UserDO::id, null)
|
||||
val dos1 = userMapper?.selectList(wrapper1)
|
||||
dos1?.forEach(System.out::println)
|
||||
}
|
||||
|
@ -26,3 +26,4 @@ mybatis-plus-join:
|
||||
banner: true
|
||||
sub-table-logic: true
|
||||
ms-cache: true
|
||||
logic-del-type: where
|
Loading…
x
Reference in New Issue
Block a user