mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
ifPresent -> ifExists
This commit is contained in:
parent
c7ea5485fd
commit
39942b28ce
@ -3,7 +3,7 @@ package com.github.yulichang.autoconfigure;
|
|||||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusLanguageDriverAutoConfiguration;
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusLanguageDriverAutoConfiguration;
|
||||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||||
import com.github.yulichang.autoconfigure.conditional.JoinSqlInjectorCondition;
|
import com.github.yulichang.autoconfigure.conditional.JoinSqlInjectorCondition;
|
||||||
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinIfPresentConsumer;
|
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinIfExistsConsumer;
|
||||||
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinPropertiesConsumer;
|
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinPropertiesConsumer;
|
||||||
import com.github.yulichang.config.ConfigProperties;
|
import com.github.yulichang.config.ConfigProperties;
|
||||||
import com.github.yulichang.config.MPJInterceptorConfig;
|
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.injector.MPJSqlInjector;
|
||||||
import com.github.yulichang.interceptor.MPJInterceptor;
|
import com.github.yulichang.interceptor.MPJInterceptor;
|
||||||
import com.github.yulichang.toolkit.SpringContentUtils;
|
import com.github.yulichang.toolkit.SpringContentUtils;
|
||||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -63,7 +63,7 @@ public class MybatisPlusJoinAutoConfiguration {
|
|||||||
|
|
||||||
public MybatisPlusJoinAutoConfiguration(MybatisPlusJoinProperties properties,
|
public MybatisPlusJoinAutoConfiguration(MybatisPlusJoinProperties properties,
|
||||||
ObjectProvider<MybatisPlusJoinPropertiesConsumer> propertiesConsumers,
|
ObjectProvider<MybatisPlusJoinPropertiesConsumer> propertiesConsumers,
|
||||||
ObjectProvider<MybatisPlusJoinIfPresentConsumer> ifPresentConsumers) {
|
ObjectProvider<MybatisPlusJoinIfExistsConsumer> IfExistsConsumers) {
|
||||||
this.properties = Optional.ofNullable(propertiesConsumers.getIfAvailable()).map(c -> c.config(properties)).orElse(properties);
|
this.properties = Optional.ofNullable(propertiesConsumers.getIfAvailable()).map(c -> c.config(properties)).orElse(properties);
|
||||||
ConfigProperties.banner = this.properties.getBanner();
|
ConfigProperties.banner = this.properties.getBanner();
|
||||||
ConfigProperties.subTableLogic = this.properties.getSubTableLogic();
|
ConfigProperties.subTableLogic = this.properties.getSubTableLogic();
|
||||||
@ -72,9 +72,9 @@ public class MybatisPlusJoinAutoConfiguration {
|
|||||||
ConfigProperties.joinPrefix = this.properties.getJoinPrefix();
|
ConfigProperties.joinPrefix = this.properties.getJoinPrefix();
|
||||||
ConfigProperties.logicDelType = this.properties.getLogicDelType();
|
ConfigProperties.logicDelType = this.properties.getLogicDelType();
|
||||||
ConfigProperties.mappingMaxCount = this.properties.getMappingMaxCount();
|
ConfigProperties.mappingMaxCount = this.properties.getMappingMaxCount();
|
||||||
ConfigProperties.ifPresent = Optional.ofNullable(ifPresentConsumers.getIfAvailable())
|
ConfigProperties.ifExists = Optional.ofNullable(IfExistsConsumers.getIfAvailable())
|
||||||
.map(m -> (BiPredicate<Object, IfPresentSqlKeyWordEnum>) m)
|
.map(m -> (BiPredicate<Object, IfExistsSqlKeyWordEnum>) m)
|
||||||
.orElse((val, key) -> this.properties.getIfPresent().test(val));
|
.orElse((val, key) -> this.properties.getIfExists().test(val));
|
||||||
info("mybatis plus join properties config complete");
|
info("mybatis plus join properties config complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.github.yulichang.autoconfigure;
|
package com.github.yulichang.autoconfigure;
|
||||||
|
|
||||||
import com.github.yulichang.config.enums.IfPresentEnum;
|
import com.github.yulichang.config.enums.IfExistsEnum;
|
||||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
@ -58,7 +58,7 @@ public class MybatisPlusJoinProperties {
|
|||||||
private String subQueryAlias = "st";
|
private String subQueryAlias = "st";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper ifPresent 判断策略
|
* Wrapper IfExists 判断策略
|
||||||
* <p>
|
* <p>
|
||||||
* NOT_NULL 非null
|
* NOT_NULL 非null
|
||||||
* <p>
|
* <p>
|
||||||
@ -66,5 +66,5 @@ public class MybatisPlusJoinProperties {
|
|||||||
* <p>
|
* <p>
|
||||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||||
*/
|
*/
|
||||||
private IfPresentEnum ifPresent = IfPresentEnum.NOT_EMPTY;
|
private IfExistsEnum IfExists = IfExistsEnum.NOT_EMPTY;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.github.yulichang.autoconfigure.consumer;
|
||||||
|
|
||||||
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
|
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义IfExists策略
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.9
|
||||||
|
*/
|
||||||
|
public interface MybatisPlusJoinIfExistsConsumer extends BiPredicate<Object, IfExistsSqlKeyWordEnum> {
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
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": "子查询表别名."
|
"description": "子查询表别名."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "mybatis-plus-join.if-present",
|
"name": "mybatis-plus-join.if-exist",
|
||||||
"defaultValue": "com.github.yulichang.config.enums.IfPresentEnum.NOT_EMPTY",
|
"defaultValue": "com.github.yulichang.config.enums.IfExistsEnum.NOT_EMPTY",
|
||||||
"type": "com.github.yulichang.config.enums.IfPresentEnum",
|
"type": "com.github.yulichang.config.enums.IfExistsEnum",
|
||||||
"description": "IfPresent方法判断策略,如需自定义请用@Bean形式MybatisPlusJoinIfPresentConsumer."
|
"description": "IfExists方法判断策略,如需自定义请用@Bean形式MybatisPlusJoinIfExistsConsumer."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@ package com.github.yulichang.config;
|
|||||||
|
|
||||||
import com.github.yulichang.adapter.AdapterHelper;
|
import com.github.yulichang.adapter.AdapterHelper;
|
||||||
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
||||||
import com.github.yulichang.config.enums.IfPresentEnum;
|
import com.github.yulichang.config.enums.IfExistsEnum;
|
||||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
|
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public class ConfigProperties {
|
|||||||
*/
|
*/
|
||||||
public static String subQueryAlias = "st";
|
public static String subQueryAlias = "st";
|
||||||
/**
|
/**
|
||||||
* Wrapper ifPresent 判断策略
|
* Wrapper IfExists 判断策略
|
||||||
* <p>
|
* <p>
|
||||||
* NOT_NULL 非null
|
* NOT_NULL 非null
|
||||||
* <p>
|
* <p>
|
||||||
@ -59,5 +59,5 @@ public class ConfigProperties {
|
|||||||
* <p>
|
* <p>
|
||||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||||
*/
|
*/
|
||||||
public static BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = (val, key) -> IfPresentEnum.NOT_EMPTY.test(val);
|
public static BiPredicate<Object, IfExistsSqlKeyWordEnum> ifExists = (val, key) -> IfExistsEnum.NOT_EMPTY.test(val);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import java.util.function.Predicate;
|
|||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @since 1.4.9
|
* @since 1.4.9
|
||||||
*/
|
*/
|
||||||
public enum IfPresentEnum implements Predicate<Object> {
|
public enum IfExistsEnum implements Predicate<Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 非null
|
* 非null
|
||||||
@ -28,7 +28,7 @@ public enum IfPresentEnum implements Predicate<Object> {
|
|||||||
|
|
||||||
private final Predicate<Object> predicate;
|
private final Predicate<Object> predicate;
|
||||||
|
|
||||||
IfPresentEnum(Predicate<Object> predicate) {
|
IfExistsEnum(Predicate<Object> predicate) {
|
||||||
this.predicate = 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.SqlUtils;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
|
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
|
||||||
import com.github.yulichang.config.ConfigProperties;
|
import com.github.yulichang.config.ConfigProperties;
|
||||||
import com.github.yulichang.kt.interfaces.CompareIfPresent;
|
import com.github.yulichang.kt.interfaces.CompareIfExists;
|
||||||
import com.github.yulichang.kt.interfaces.Func;
|
import com.github.yulichang.kt.interfaces.Func;
|
||||||
import com.github.yulichang.kt.interfaces.OnCompare;
|
import com.github.yulichang.kt.interfaces.OnCompare;
|
||||||
import com.github.yulichang.toolkit.KtUtils;
|
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.Ref;
|
||||||
import com.github.yulichang.toolkit.TableList;
|
import com.github.yulichang.toolkit.TableList;
|
||||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||||
import com.github.yulichang.wrapper.interfaces.CompareStrIfPresent;
|
import com.github.yulichang.wrapper.interfaces.CompareStrIfExists;
|
||||||
import com.github.yulichang.wrapper.interfaces.FuncStr;
|
import com.github.yulichang.wrapper.interfaces.FuncStr;
|
||||||
import com.github.yulichang.wrapper.interfaces.Join;
|
import com.github.yulichang.wrapper.interfaces.Join;
|
||||||
import kotlin.reflect.KProperty;
|
import kotlin.reflect.KProperty;
|
||||||
@ -47,8 +47,8 @@ import static java.util.stream.Collectors.joining;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unused", "unchecked", "DuplicatedCode"})
|
@SuppressWarnings({"unused", "unchecked", "DuplicatedCode"})
|
||||||
public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T, Children>> extends Wrapper<T>
|
public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T, Children>> extends Wrapper<T>
|
||||||
implements CompareIfPresent<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
implements CompareIfExists<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
||||||
CompareStrIfPresent<Children, String>, FuncStr<Children, String> {
|
CompareStrIfExists<Children, String>, FuncStr<Children, String> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 占位符
|
* 占位符
|
||||||
@ -125,10 +125,10 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
|||||||
protected boolean checkSqlInjection = false;
|
protected boolean checkSqlInjection = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ifPresent 策略
|
* IfExists 策略
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
protected BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = ConfigProperties.ifPresent;
|
protected BiPredicate<Object, IfExistsSqlKeyWordEnum> ifExists = ConfigProperties.ifExists;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T getEntity() {
|
public T getEntity() {
|
||||||
@ -181,13 +181,13 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
|||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Children setIfPresent(BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
public Children setIfExists(BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||||
this.ifPresent = ifPresent;
|
this.ifExists = IfExists;
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Children setIfPresent(Predicate<Object> ifPresent) {
|
public Children setIfExists(Predicate<Object> IfExists) {
|
||||||
this.ifPresent = (o, k) -> ifPresent.test(o);
|
this.ifExists = (o, k) -> IfExists.test(o);
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,7 +659,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
|||||||
index = null;
|
index = null;
|
||||||
isMain = true;
|
isMain = true;
|
||||||
isNo = false;
|
isNo = false;
|
||||||
ifPresent = ConfigProperties.ifPresent;
|
ifExists = ConfigProperties.ifExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,115 @@
|
|||||||
|
package com.github.yulichang.kt.interfaces;
|
||||||
|
|
||||||
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
|
import kotlin.reflect.KProperty;
|
||||||
|
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IfExists
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.9
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface CompareIfExists<Children> extends Compare<Children> {
|
||||||
|
|
||||||
|
BiPredicate<Object, IfExistsSqlKeyWordEnum> getIfExists();
|
||||||
|
|
||||||
|
default Children eqIfExists(KProperty<?> column, Object val) {
|
||||||
|
return eq(getIfExists().test(val, IfExistsSqlKeyWordEnum.EQ), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children eqIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return eq(getIfExists().test(val, IfExistsSqlKeyWordEnum.EQ), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children neIfExists(KProperty<?> column, Object val) {
|
||||||
|
return ne(getIfExists().test(val, IfExistsSqlKeyWordEnum.NE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children neIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return ne(getIfExists().test(val, IfExistsSqlKeyWordEnum.NE), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children gtIfExists(KProperty<?> column, Object val) {
|
||||||
|
return gt(getIfExists().test(val, IfExistsSqlKeyWordEnum.GT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children gtIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return gt(getIfExists().test(val, IfExistsSqlKeyWordEnum.GT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
default Children geIfExists(KProperty<?> column, Object val) {
|
||||||
|
return ge(getIfExists().test(val, IfExistsSqlKeyWordEnum.GE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children geIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return ge(getIfExists().test(val, IfExistsSqlKeyWordEnum.GE), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children ltIfExists(KProperty<?> column, Object val) {
|
||||||
|
return lt(getIfExists().test(val, IfExistsSqlKeyWordEnum.LT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children ltIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return lt(getIfExists().test(val, IfExistsSqlKeyWordEnum.LT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children leIfExists(KProperty<?> column, Object val) {
|
||||||
|
return le(getIfExists().test(val, IfExistsSqlKeyWordEnum.LE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children leIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return le(getIfExists().test(val, IfExistsSqlKeyWordEnum.LE), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children likeIfExists(KProperty<?> column, Object val) {
|
||||||
|
return like(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children likeIfExists(String alisa, KProperty<?> column, Object val) {
|
||||||
|
return like(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE), alisa, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children notLikeIfExists(KProperty<?> column, Object val) {
|
||||||
|
return notLike(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children notLikeIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return notLike(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children likeLeftIfExists(KProperty<?> column, Object val) {
|
||||||
|
return likeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_LEFT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children likeLeftIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return likeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_LEFT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children notLikeLeftIfExists(KProperty<?> column, Object val) {
|
||||||
|
return notLikeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_LEFT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children notLikeLeftIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return notLikeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_LEFT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children likeRightIfExists(KProperty<?> column, Object val) {
|
||||||
|
return likeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_RIGHT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children likeRightIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return likeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_RIGHT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children notLikeRightIfExists(KProperty<?> column, Object val) {
|
||||||
|
return notLikeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_RIGHT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children notLikeRightIfExists(String alias, KProperty<?> column, Object val) {
|
||||||
|
return notLikeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_RIGHT), alias, column, val);
|
||||||
|
}
|
||||||
|
}
|
@ -1,115 +0,0 @@
|
|||||||
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.*;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
import com.github.yulichang.config.ConfigProperties;
|
import com.github.yulichang.config.ConfigProperties;
|
||||||
import com.github.yulichang.query.interfaces.CompareIfPresent;
|
import com.github.yulichang.query.interfaces.CompareIfExists;
|
||||||
import com.github.yulichang.query.interfaces.StringJoin;
|
import com.github.yulichang.query.interfaces.StringJoin;
|
||||||
import com.github.yulichang.toolkit.Asserts;
|
import com.github.yulichang.toolkit.Asserts;
|
||||||
import com.github.yulichang.toolkit.TableHelper;
|
import com.github.yulichang.toolkit.TableHelper;
|
||||||
import com.github.yulichang.toolkit.ThrowOptional;
|
import com.github.yulichang.toolkit.ThrowOptional;
|
||||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@ -36,7 +36,7 @@ import java.util.stream.Collectors;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambdaQueryWrapper<T>>
|
public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambdaQueryWrapper<T>>
|
||||||
implements Query<MPJLambdaQueryWrapper<T>, T, SFunction<T, ?>>, StringJoin<MPJLambdaQueryWrapper<T>, T>,
|
implements Query<MPJLambdaQueryWrapper<T>, T, SFunction<T, ?>>, StringJoin<MPJLambdaQueryWrapper<T>, T>,
|
||||||
CompareIfPresent<MPJLambdaQueryWrapper<T>, SFunction<T, ?>> {
|
CompareIfExists<MPJLambdaQueryWrapper<T>, SFunction<T, ?>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询字段
|
* 查询字段
|
||||||
@ -78,7 +78,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
|||||||
private Function<String, String> tableNameFunc;
|
private Function<String, String> tableNameFunc;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = ConfigProperties.ifPresent;
|
private BiPredicate<Object, IfExistsSqlKeyWordEnum> ifExists = ConfigProperties.ifExists;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不建议直接 new 该实例,使用 Wrappers.lambdaQuery(entity)
|
* 不建议直接 new 该实例,使用 Wrappers.lambdaQuery(entity)
|
||||||
@ -94,7 +94,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
|||||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments,
|
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments,
|
||||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
|
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
|
||||||
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct,
|
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct,
|
||||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||||
super.setEntity(entity);
|
super.setEntity(entity);
|
||||||
setEntityClass(entityClass);
|
setEntityClass(entityClass);
|
||||||
this.paramNameSeq = paramNameSeq;
|
this.paramNameSeq = paramNameSeq;
|
||||||
@ -108,7 +108,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
|||||||
this.selectColumns = selectColumns;
|
this.selectColumns = selectColumns;
|
||||||
this.ignoreColumns = ignoreColumns;
|
this.ignoreColumns = ignoreColumns;
|
||||||
this.selectDistinct = selectDistinct;
|
this.selectDistinct = selectDistinct;
|
||||||
this.ifPresent = ifPresent;
|
this.ifExists = IfExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -235,7 +235,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
|||||||
public MPJQueryWrapper<T> stringQuery() {
|
public MPJQueryWrapper<T> stringQuery() {
|
||||||
return new MPJQueryWrapper<>(getEntity(), getEntityClass(), paramNameSeq, paramNameValuePairs,
|
return new MPJQueryWrapper<>(getEntity(), getEntityClass(), paramNameSeq, paramNameValuePairs,
|
||||||
expression, sqlSelect, from, lastSql, sqlComment, sqlFirst, selectColumns, ignoreColumns,
|
expression, sqlSelect, from, lastSql, sqlComment, sqlFirst, selectColumns, ignoreColumns,
|
||||||
selectDistinct, ifPresent);
|
selectDistinct, ifExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -337,13 +337,13 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
|||||||
return this.tableNameFunc.apply(decode);
|
return this.tableNameFunc.apply(decode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPJLambdaQueryWrapper<T> setIfPresent(BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
public MPJLambdaQueryWrapper<T> setIfExists(BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||||
this.ifPresent = ifPresent;
|
this.ifExists = IfExists;
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPJLambdaQueryWrapper<T> setIfPresent(Predicate<Object> ifPresent) {
|
public MPJLambdaQueryWrapper<T> setIfExists(Predicate<Object> IfExists) {
|
||||||
this.ifPresent = (o, k) -> ifPresent.test(o);
|
this.ifExists = (o, k) -> IfExists.test(o);
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
|||||||
protected MPJLambdaQueryWrapper<T> instance() {
|
protected MPJLambdaQueryWrapper<T> instance() {
|
||||||
return new MPJLambdaQueryWrapper<>(getEntity(), getEntityClass(), null, null, paramNameSeq, paramNameValuePairs,
|
return new MPJLambdaQueryWrapper<>(getEntity(), getEntityClass(), null, null, paramNameSeq, paramNameValuePairs,
|
||||||
new MergeSegments(), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
new MergeSegments(), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||||
null, null, selectDistinct, ifPresent);
|
null, null, selectDistinct, ifExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -391,7 +391,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
|||||||
from.toNull();
|
from.toNull();
|
||||||
selectColumns.clear();
|
selectColumns.clear();
|
||||||
ignoreColumns.clear();
|
ignoreColumns.clear();
|
||||||
ifPresent = ConfigProperties.ifPresent;
|
ifExists = ConfigProperties.ifExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,13 +11,13 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||||
import com.github.yulichang.config.ConfigProperties;
|
import com.github.yulichang.config.ConfigProperties;
|
||||||
import com.github.yulichang.query.interfaces.CompareIfPresent;
|
import com.github.yulichang.query.interfaces.CompareIfExists;
|
||||||
import com.github.yulichang.query.interfaces.StringJoin;
|
import com.github.yulichang.query.interfaces.StringJoin;
|
||||||
import com.github.yulichang.toolkit.Asserts;
|
import com.github.yulichang.toolkit.Asserts;
|
||||||
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
||||||
import com.github.yulichang.toolkit.TableHelper;
|
import com.github.yulichang.toolkit.TableHelper;
|
||||||
import com.github.yulichang.toolkit.ThrowOptional;
|
import com.github.yulichang.toolkit.ThrowOptional;
|
||||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
import com.github.yulichang.wrapper.interfaces.Chain;
|
import com.github.yulichang.wrapper.interfaces.Chain;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ import java.util.stream.Collectors;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapper<T>> implements
|
public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapper<T>> implements
|
||||||
Query<MPJQueryWrapper<T>, T, String>, StringJoin<MPJQueryWrapper<T>, T>, Chain<T>,
|
Query<MPJQueryWrapper<T>, T, String>, StringJoin<MPJQueryWrapper<T>, T>, Chain<T>,
|
||||||
CompareIfPresent<MPJQueryWrapper<T>, String> {
|
CompareIfExists<MPJQueryWrapper<T>, String> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询字段
|
* 查询字段
|
||||||
@ -91,7 +91,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
|||||||
private boolean checkSqlInjection = false;
|
private boolean checkSqlInjection = false;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = ConfigProperties.ifPresent;
|
private BiPredicate<Object, IfExistsSqlKeyWordEnum> ifExists = ConfigProperties.ifExists;
|
||||||
|
|
||||||
|
|
||||||
public MPJQueryWrapper() {
|
public MPJQueryWrapper() {
|
||||||
@ -124,7 +124,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
|||||||
SharedString sqlSelect, SharedString from, SharedString lastSql,
|
SharedString sqlSelect, SharedString from, SharedString lastSql,
|
||||||
SharedString sqlComment, SharedString sqlFirst,
|
SharedString sqlComment, SharedString sqlFirst,
|
||||||
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct,
|
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct,
|
||||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||||
super.setEntity(entity);
|
super.setEntity(entity);
|
||||||
setEntityClass(entityClass);
|
setEntityClass(entityClass);
|
||||||
this.paramNameSeq = paramNameSeq;
|
this.paramNameSeq = paramNameSeq;
|
||||||
@ -138,7 +138,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
|||||||
this.selectColumns = selectColumns;
|
this.selectColumns = selectColumns;
|
||||||
this.ignoreColumns = ignoreColumns;
|
this.ignoreColumns = ignoreColumns;
|
||||||
this.selectDistinct = selectDistinct;
|
this.selectDistinct = selectDistinct;
|
||||||
this.ifPresent = ifPresent;
|
this.ifExists = IfExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,13 +149,13 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPJQueryWrapper<T> setIfPresent(BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
public MPJQueryWrapper<T> setIfExists(BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||||
this.ifPresent = ifPresent;
|
this.ifExists = IfExists;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPJQueryWrapper<T> setIfPresent(Predicate<Object> ifPresent) {
|
public MPJQueryWrapper<T> setIfExists(Predicate<Object> IfExists) {
|
||||||
this.ifPresent = (o, k) -> ifPresent.test(o);
|
this.ifExists = (o, k) -> IfExists.test(o);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,7 +354,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
|||||||
*/
|
*/
|
||||||
public MPJLambdaQueryWrapper<T> lambda() {
|
public MPJLambdaQueryWrapper<T> lambda() {
|
||||||
return new MPJLambdaQueryWrapper<>(getEntity(), getEntityClass(), from, sqlSelect, paramNameSeq, paramNameValuePairs,
|
return new MPJLambdaQueryWrapper<>(getEntity(), getEntityClass(), from, sqlSelect, paramNameSeq, paramNameValuePairs,
|
||||||
expression, lastSql, sqlComment, getSqlFirstField(), selectColumns, ignoreColumns, selectDistinct, ifPresent);
|
expression, lastSql, sqlComment, getSqlFirstField(), selectColumns, ignoreColumns, selectDistinct, ifExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -391,7 +391,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
|||||||
protected MPJQueryWrapper<T> instance() {
|
protected MPJQueryWrapper<T> instance() {
|
||||||
return new MPJQueryWrapper<>(getEntity(), getEntityClass(), paramNameSeq, paramNameValuePairs, new MergeSegments(),
|
return new MPJQueryWrapper<>(getEntity(), getEntityClass(), paramNameSeq, paramNameValuePairs, new MergeSegments(),
|
||||||
null, null, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
null, null, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||||
null, null, selectDistinct, ifPresent);
|
null, null, selectDistinct, ifExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -402,7 +402,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
|||||||
from.toNull();
|
from.toNull();
|
||||||
selectColumns.clear();
|
selectColumns.clear();
|
||||||
ignoreColumns.clear();
|
ignoreColumns.clear();
|
||||||
ifPresent = ConfigProperties.ifPresent;
|
ifExists = ConfigProperties.ifExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,151 @@
|
|||||||
|
package com.github.yulichang.query.interfaces;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
|
||||||
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
|
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询条件封装
|
||||||
|
* <p>比较值</p>
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.9
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface CompareIfExists<Children, R> extends Compare<Children, R> {
|
||||||
|
|
||||||
|
BiPredicate<Object, IfExistsSqlKeyWordEnum> getIfExists();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 等于 =
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children eqIfExists(R column, Object val) {
|
||||||
|
return eq(getIfExists().test(val, IfExistsSqlKeyWordEnum.EQ), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不等于 <>
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children neIfExists(R column, Object val) {
|
||||||
|
return ne(getIfExists().test(val, IfExistsSqlKeyWordEnum.NE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大于 >
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children gtIfExists(R column, Object val) {
|
||||||
|
return gt(getIfExists().test(val, IfExistsSqlKeyWordEnum.GT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大于等于 >=
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children geIfExists(R column, Object val) {
|
||||||
|
return ge(getIfExists().test(val, IfExistsSqlKeyWordEnum.GE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小于 <
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children ltIfExists(R column, Object val) {
|
||||||
|
return lt(getIfExists().test(val, IfExistsSqlKeyWordEnum.LT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小于等于 <=
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children leIfExists(R column, Object val) {
|
||||||
|
return le(getIfExists().test(val, IfExistsSqlKeyWordEnum.LE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIKE '%值%'
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children likeIfExists(R column, Object val) {
|
||||||
|
return like(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOT LIKE '%值%'
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children notLikeIfExists(R column, Object val) {
|
||||||
|
return notLike(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOT LIKE '%值'
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children notLikeLeftIfExists(R column, Object val) {
|
||||||
|
return notLikeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_LEFT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOT LIKE '值%'
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children notLikeRightIfExists(R column, Object val) {
|
||||||
|
return notLikeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_RIGHT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIKE '%值'
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children likeLeftIfExists(R column, Object val) {
|
||||||
|
return likeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_LEFT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIKE '值%'
|
||||||
|
*
|
||||||
|
* @param column 字段
|
||||||
|
* @param val 值
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
default Children likeRightIfExists(R column, Object val) {
|
||||||
|
return likeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_RIGHT), column, val);
|
||||||
|
}
|
||||||
|
}
|
@ -1,151 +0,0 @@
|
|||||||
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.Ref;
|
||||||
import com.github.yulichang.toolkit.TableList;
|
import com.github.yulichang.toolkit.TableList;
|
||||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||||
import com.github.yulichang.wrapper.interfaces.*;
|
import com.github.yulichang.wrapper.interfaces.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -42,8 +42,8 @@ import static java.util.stream.Collectors.joining;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked", "unused", "DuplicatedCode"})
|
@SuppressWarnings({"unchecked", "unused", "DuplicatedCode"})
|
||||||
public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrapper<T, Children>> extends Wrapper<T>
|
public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrapper<T, Children>> extends Wrapper<T>
|
||||||
implements CompareIfPresent<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
implements CompareIfExists<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
||||||
CompareStrIfPresent<Children, String>, FuncStr<Children, String> {
|
CompareStrIfExists<Children, String>, FuncStr<Children, String> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 占位符
|
* 占位符
|
||||||
@ -120,10 +120,10 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
|||||||
protected boolean checkSqlInjection = false;
|
protected boolean checkSqlInjection = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ifPresent 策略
|
* IfExists 策略
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
protected BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent = ConfigProperties.ifPresent;
|
protected BiPredicate<Object, IfExistsSqlKeyWordEnum> ifExists = ConfigProperties.ifExists;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T getEntity() {
|
public T getEntity() {
|
||||||
@ -176,20 +176,20 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
|||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Children setIfPresent(BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
public Children setIfExists(BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||||
this.ifPresent = ifPresent;
|
this.ifExists = IfExists;
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置 ifPresent
|
* 设置 IfExists
|
||||||
* .ifPresent(val -> val != null && StringUtils.isNotBlank(val))
|
* .IfExists(val -> val != null && StringUtils.isNotBlank(val))
|
||||||
*
|
*
|
||||||
* @param ifPresent 判断
|
* @param IfExists 判断
|
||||||
* @return Children
|
* @return Children
|
||||||
*/
|
*/
|
||||||
public Children setIfPresent(Predicate<Object> ifPresent) {
|
public Children setIfExists(Predicate<Object> IfExists) {
|
||||||
this.ifPresent = (obj, key) -> ifPresent.test(obj);
|
this.ifExists = (obj, key) -> IfExists.test(obj);
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -773,7 +773,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
|||||||
index = null;
|
index = null;
|
||||||
isMain = true;
|
isMain = true;
|
||||||
isOn = false;
|
isOn = false;
|
||||||
ifPresent = ConfigProperties.ifPresent;
|
ifExists = ConfigProperties.ifExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,7 @@ import com.github.yulichang.config.ConfigProperties;
|
|||||||
import com.github.yulichang.toolkit.LambdaUtils;
|
import com.github.yulichang.toolkit.LambdaUtils;
|
||||||
import com.github.yulichang.toolkit.*;
|
import com.github.yulichang.toolkit.*;
|
||||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||||
import com.github.yulichang.wrapper.enums.IfPresentSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
import com.github.yulichang.wrapper.interfaces.Chain;
|
import com.github.yulichang.wrapper.interfaces.Chain;
|
||||||
import com.github.yulichang.wrapper.interfaces.Query;
|
import com.github.yulichang.wrapper.interfaces.Query;
|
||||||
import com.github.yulichang.wrapper.interfaces.QueryLabel;
|
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,
|
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
|
||||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
|
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
|
||||||
TableList tableList, Integer index, String keyWord, Class<?> joinClass, String tableName,
|
TableList tableList, Integer index, String keyWord, Class<?> joinClass, String tableName,
|
||||||
BiPredicate<Object, IfPresentSqlKeyWordEnum> ifPresent) {
|
BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
|
||||||
super.setEntity(entity);
|
super.setEntity(entity);
|
||||||
super.setEntityClass(entityClass);
|
super.setEntityClass(entityClass);
|
||||||
this.paramNameSeq = paramNameSeq;
|
this.paramNameSeq = paramNameSeq;
|
||||||
@ -142,7 +142,7 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
this.keyWord = keyWord;
|
this.keyWord = keyWord;
|
||||||
this.joinClass = joinClass;
|
this.joinClass = joinClass;
|
||||||
this.tableName = tableName;
|
this.tableName = tableName;
|
||||||
this.ifPresent = ifPresent;
|
this.ifExists = IfExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
MPJLambdaWrapper<E> wrapper = new MPJLambdaWrapper<E>(null, clazz, SharedString.emptyString(),
|
MPJLambdaWrapper<E> wrapper = new MPJLambdaWrapper<E>(null, clazz, SharedString.emptyString(),
|
||||||
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
||||||
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||||
new TableList(), null, null, null, null, ifPresent) {
|
new TableList(), null, null, null, null, ifExists) {
|
||||||
};
|
};
|
||||||
wrapper.tableList.setAlias(st);
|
wrapper.tableList.setAlias(st);
|
||||||
wrapper.tableList.setRootClass(clazz);
|
wrapper.tableList.setRootClass(clazz);
|
||||||
@ -409,7 +409,7 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
protected MPJLambdaWrapper<T> instance(Integer index, String keyWord, Class<?> joinClass, String tableName) {
|
protected MPJLambdaWrapper<T> instance(Integer index, String keyWord, Class<?> joinClass, String tableName) {
|
||||||
return new MPJLambdaWrapper<>(getEntity(), getEntityClass(), null, paramNameSeq, paramNameValuePairs,
|
return new MPJLambdaWrapper<>(getEntity(), getEntityClass(), null, paramNameSeq, paramNameValuePairs,
|
||||||
new MergeSegments(), this.paramAlias, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
new MergeSegments(), this.paramAlias, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||||
this.tableList, index, keyWord, joinClass, tableName, ifPresent);
|
this.tableList, index, keyWord, joinClass, tableName, ifExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -422,6 +422,6 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
|||||||
if (Objects.nonNull(wrapperMap)) wrapperMap.clear();
|
if (Objects.nonNull(wrapperMap)) wrapperMap.clear();
|
||||||
if (Objects.nonNull(unionSql)) unionSql.toEmpty();
|
if (Objects.nonNull(unionSql)) unionSql.toEmpty();
|
||||||
resultMapMybatisLabel.clear();
|
resultMapMybatisLabel.clear();
|
||||||
ifPresent = ConfigProperties.ifPresent;
|
ifExists = ConfigProperties.ifExists;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ package com.github.yulichang.wrapper.enums;
|
|||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @since 1.4.9
|
* @since 1.4.9
|
||||||
*/
|
*/
|
||||||
public enum IfPresentSqlKeyWordEnum {
|
public enum IfExistsSqlKeyWordEnum {
|
||||||
EQ,
|
EQ,
|
||||||
NE,
|
NE,
|
||||||
GT,
|
GT,
|
@ -0,0 +1,114 @@
|
|||||||
|
package com.github.yulichang.wrapper.interfaces;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
|
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.9
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface CompareIfExists<Children> extends Compare<Children> {
|
||||||
|
|
||||||
|
BiPredicate<Object, IfExistsSqlKeyWordEnum> getIfExists();
|
||||||
|
|
||||||
|
default <R> Children eqIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return eq(getIfExists().test(val, IfExistsSqlKeyWordEnum.EQ), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children eqIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return eq(getIfExists().test(val, IfExistsSqlKeyWordEnum.EQ), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children neIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return ne(getIfExists().test(val, IfExistsSqlKeyWordEnum.NE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children neIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return ne(getIfExists().test(val, IfExistsSqlKeyWordEnum.NE), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children gtIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return gt(getIfExists().test(val, IfExistsSqlKeyWordEnum.GT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children gtIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return gt(getIfExists().test(val, IfExistsSqlKeyWordEnum.GT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children geIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return ge(getIfExists().test(val, IfExistsSqlKeyWordEnum.GE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children geIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return ge(getIfExists().test(val, IfExistsSqlKeyWordEnum.GE), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children ltIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return lt(getIfExists().test(val, IfExistsSqlKeyWordEnum.LT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children ltIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return lt(getIfExists().test(val, IfExistsSqlKeyWordEnum.LT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children leIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return le(getIfExists().test(val, IfExistsSqlKeyWordEnum.LE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children leIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return le(getIfExists().test(val, IfExistsSqlKeyWordEnum.LE), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children likeIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return like(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children likeIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return like(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children notLikeIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return notLike(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children notLikeIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return notLike(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children likeLeftIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return likeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_LEFT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children likeLeftIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return likeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_LEFT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children notLikeLeftIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return notLikeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_LEFT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children notLikeLeftIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return notLikeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_LEFT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children likeRightIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return likeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_RIGHT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children likeRightIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return likeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_RIGHT), alias, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children notLikeRightIfExists(SFunction<R, ?> column, Object val) {
|
||||||
|
return notLikeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_RIGHT), null, column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <R> Children notLikeRightIfExists(String alias, SFunction<R, ?> column, Object val) {
|
||||||
|
return notLikeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_RIGHT), alias, column, val);
|
||||||
|
}
|
||||||
|
}
|
@ -1,114 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.github.yulichang.wrapper.interfaces;
|
||||||
|
|
||||||
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
|
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.9
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface CompareStrIfExists<Children, R> extends CompareStr<Children, R> {
|
||||||
|
|
||||||
|
BiPredicate<Object, IfExistsSqlKeyWordEnum> getIfExists();
|
||||||
|
|
||||||
|
default Children eqIfExists(R column, Object val) {
|
||||||
|
return eq(getIfExists().test(val, IfExistsSqlKeyWordEnum.EQ), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children neIfExists(R column, Object val) {
|
||||||
|
return ne(getIfExists().test(val, IfExistsSqlKeyWordEnum.NE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children gtIfExists(R column, Object val) {
|
||||||
|
return gt(getIfExists().test(val, IfExistsSqlKeyWordEnum.GT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children geIfExists(R column, Object val) {
|
||||||
|
return ge(getIfExists().test(val, IfExistsSqlKeyWordEnum.GE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children ltIfExists(R column, Object val) {
|
||||||
|
return lt(getIfExists().test(val, IfExistsSqlKeyWordEnum.LT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children leIfExists(R column, Object val) {
|
||||||
|
return le(getIfExists().test(val, IfExistsSqlKeyWordEnum.LE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children likeIfExists(R column, Object val) {
|
||||||
|
return like(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children notLikeIfExists(R column, Object val) {
|
||||||
|
return notLike(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children likeLeftIfExists(R column, Object val) {
|
||||||
|
return likeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_LEFT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children likeRightIfExists(R column, Object val) {
|
||||||
|
return likeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.LIKE_RIGHT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children notLikeLeftIfExists(R column, Object val) {
|
||||||
|
return notLikeLeft(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_LEFT), column, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Children notLikeRightIfExists(R column, Object val) {
|
||||||
|
return notLikeRight(getIfExists().test(val, IfExistsSqlKeyWordEnum.NOT_LIKE_RIGHT), column, val);
|
||||||
|
}
|
||||||
|
}
|
@ -1,65 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -30,7 +30,6 @@ import java.util.stream.Collectors;
|
|||||||
@SuppressWarnings({"unused", "DuplicatedCode"})
|
@SuppressWarnings({"unused", "DuplicatedCode"})
|
||||||
public interface Query<Children> extends Serializable {
|
public interface Query<Children> extends Serializable {
|
||||||
|
|
||||||
|
|
||||||
List<Select> getSelectColum();
|
List<Select> getSelectColum();
|
||||||
|
|
||||||
Children getChildren();
|
Children getChildren();
|
||||||
@ -100,7 +99,8 @@ public interface Query<Children> extends Serializable {
|
|||||||
* @param column 列
|
* @param column 列
|
||||||
*/
|
*/
|
||||||
default <E> Children selectAs(String column, SFunction<E, ?> alias) {
|
default <E> Children selectAs(String column, SFunction<E, ?> alias) {
|
||||||
getSelectColum().add(new SelectString(column + Constants.AS + LambdaUtils.getName(alias), LambdaUtils.getName(alias)));
|
String name = LambdaUtils.getName(alias);
|
||||||
|
getSelectColum().add(new SelectString(column + Constants.AS + name, name));
|
||||||
return getChildren();
|
return getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,8 +112,8 @@ public interface Query<Children> extends Serializable {
|
|||||||
default <E, X> Children selectAs(String index, SFunction<E, ?> column, SFunction<X, ?> alias) {
|
default <E, X> Children selectAs(String index, SFunction<E, ?> column, SFunction<X, ?> alias) {
|
||||||
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(LambdaUtils.getEntityClass(column));
|
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(LambdaUtils.getEntityClass(column));
|
||||||
SelectCache cache = cacheMap.get(LambdaUtils.getName(column));
|
SelectCache cache = cacheMap.get(LambdaUtils.getName(column));
|
||||||
getSelectColum().add(new SelectString(
|
String name = LambdaUtils.getName(alias);
|
||||||
index + Constants.DOT + cache.getColumn() + Constants.AS + LambdaUtils.getName(alias), LambdaUtils.getName(alias)));
|
getSelectColum().add(new SelectString(index + Constants.DOT + cache.getColumn() + Constants.AS + name, name));
|
||||||
return getChildren();
|
return getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public class CustomWrapperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <X> CWrapper<T> eqIfPresent(SFunction<X, ?> column, Object val) {
|
public <X> CWrapper<T> eqIfExists(SFunction<X, ?> column, Object val) {
|
||||||
super.eq(Objects.nonNull(val), column, val);
|
super.eq(Objects.nonNull(val), column, val);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ public class CustomWrapperTest {
|
|||||||
.selectAll(UserDO.class)
|
.selectAll(UserDO.class)
|
||||||
// .toChildren(new Ref<CWrapper<UserDO>>())
|
// .toChildren(new Ref<CWrapper<UserDO>>())
|
||||||
.toChildren(CWrapper::toCWrapper)
|
.toChildren(CWrapper::toCWrapper)
|
||||||
.eqIfPresent(UserDO::getId, 1);
|
.eqIfExists(UserDO::getId, 1);
|
||||||
List<UserDO> dos = userMapper.selectList(wrapper);
|
List<UserDO> dos = userMapper.selectList(wrapper);
|
||||||
dos.forEach(System.out::println);
|
dos.forEach(System.out::println);
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class CustomWrapperTest {
|
|||||||
.selectAll(UserDO.class)
|
.selectAll(UserDO.class)
|
||||||
.toChildren(new Ref<CWrapper<UserDO>>())
|
.toChildren(new Ref<CWrapper<UserDO>>())
|
||||||
// .toChildren(CWrapper::toCWrapper)
|
// .toChildren(CWrapper::toCWrapper)
|
||||||
.eqIfPresent(UserDO::getId, null);
|
.eqIfExists(UserDO::getId, null);
|
||||||
List<UserDO> dos1 = userMapper.selectList(wrapper1);
|
List<UserDO> dos1 = userMapper.selectList(wrapper1);
|
||||||
dos1.forEach(System.out::println);
|
dos1.forEach(System.out::println);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.github.yulichang.test.join.m;
|
package com.github.yulichang.test.join.m;
|
||||||
|
|
||||||
import com.github.yulichang.config.enums.IfPresentEnum;
|
import com.github.yulichang.config.enums.IfExistsEnum;
|
||||||
import com.github.yulichang.test.join.entity.UserDO;
|
import com.github.yulichang.test.join.entity.UserDO;
|
||||||
import com.github.yulichang.test.util.Reset;
|
import com.github.yulichang.test.util.Reset;
|
||||||
import com.github.yulichang.test.util.ThreadLocalUtils;
|
import com.github.yulichang.test.util.ThreadLocalUtils;
|
||||||
@ -13,7 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class IfPresentTest {
|
public class IfExistsTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
@ -21,35 +21,35 @@ public class IfPresentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void ifPresent() {
|
void IfExists() {
|
||||||
assert IfPresentEnum.NOT_EMPTY.test("\t");
|
assert IfExistsEnum.NOT_EMPTY.test("\t");
|
||||||
assert !IfPresentEnum.NOT_EMPTY.test("");
|
assert !IfExistsEnum.NOT_EMPTY.test("");
|
||||||
assert IfPresentEnum.NOT_EMPTY.test(" ");
|
assert IfExistsEnum.NOT_EMPTY.test(" ");
|
||||||
assert IfPresentEnum.NOT_EMPTY.test("\r");
|
assert IfExistsEnum.NOT_EMPTY.test("\r");
|
||||||
assert IfPresentEnum.NOT_EMPTY.test("a");
|
assert IfExistsEnum.NOT_EMPTY.test("a");
|
||||||
assert IfPresentEnum.NOT_EMPTY.test(1);
|
assert IfExistsEnum.NOT_EMPTY.test(1);
|
||||||
assert IfPresentEnum.NOT_EMPTY.test(true);
|
assert IfExistsEnum.NOT_EMPTY.test(true);
|
||||||
assert IfPresentEnum.NOT_EMPTY.test('A');
|
assert IfExistsEnum.NOT_EMPTY.test('A');
|
||||||
|
|
||||||
assert !IfPresentEnum.NOT_BLANK.test("\t");
|
assert !IfExistsEnum.NOT_BLANK.test("\t");
|
||||||
assert !IfPresentEnum.NOT_BLANK.test("");
|
assert !IfExistsEnum.NOT_BLANK.test("");
|
||||||
assert !IfPresentEnum.NOT_BLANK.test(" ");
|
assert !IfExistsEnum.NOT_BLANK.test(" ");
|
||||||
assert !IfPresentEnum.NOT_BLANK.test("\r");
|
assert !IfExistsEnum.NOT_BLANK.test("\r");
|
||||||
assert IfPresentEnum.NOT_BLANK.test("a");
|
assert IfExistsEnum.NOT_BLANK.test("a");
|
||||||
assert IfPresentEnum.NOT_EMPTY.test(1);
|
assert IfExistsEnum.NOT_EMPTY.test(1);
|
||||||
assert IfPresentEnum.NOT_EMPTY.test(true);
|
assert IfExistsEnum.NOT_EMPTY.test(true);
|
||||||
assert IfPresentEnum.NOT_EMPTY.test('A');
|
assert IfExistsEnum.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, " +
|
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 " +
|
"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` = ?)");
|
"WHERE t.del = false AND (t.id = ? AND t.head_img = ? AND t.`name` = ?)");
|
||||||
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
|
||||||
.selectAll(UserDO.class)
|
.selectAll(UserDO.class)
|
||||||
.eqIfPresent(UserDO::getId, 1)
|
.eqIfExists(UserDO::getId, 1)
|
||||||
.eqIfPresent(UserDO::getPid, null)
|
.eqIfExists(UserDO::getPid, null)
|
||||||
.eqIfPresent(UserDO::getAddressId, "")
|
.eqIfExists(UserDO::getAddressId, "")
|
||||||
.eqIfPresent(UserDO::getImg, "\t")
|
.eqIfExists(UserDO::getImg, "\t")
|
||||||
.eqIfPresent(UserDO::getName, "张三 1");
|
.eqIfExists(UserDO::getName, "张三 1");
|
||||||
List<UserDO> list = wrapper.list();
|
List<UserDO> list = wrapper.list();
|
||||||
list.forEach(System.out::println);
|
list.forEach(System.out::println);
|
||||||
|
|
||||||
@ -58,12 +58,12 @@ public class IfPresentTest {
|
|||||||
"WHERE t.del = false AND (t.id = ? AND t.`name` = ?)");
|
"WHERE t.del = false AND (t.id = ? AND t.`name` = ?)");
|
||||||
MPJLambdaWrapper<UserDO> wrapper1 = JoinWrappers.lambda(UserDO.class)
|
MPJLambdaWrapper<UserDO> wrapper1 = JoinWrappers.lambda(UserDO.class)
|
||||||
.selectAll(UserDO.class)
|
.selectAll(UserDO.class)
|
||||||
.setIfPresent(IfPresentEnum.NOT_BLANK)
|
.setIfExists(IfExistsEnum.NOT_BLANK)
|
||||||
.eqIfPresent(UserDO::getId, 1)
|
.eqIfExists(UserDO::getId, 1)
|
||||||
.eqIfPresent(UserDO::getPid, null)
|
.eqIfExists(UserDO::getPid, null)
|
||||||
.eqIfPresent(UserDO::getAddressId, "")
|
.eqIfExists(UserDO::getAddressId, "")
|
||||||
.eqIfPresent(UserDO::getImg, "\t")
|
.eqIfExists(UserDO::getImg, "\t")
|
||||||
.eqIfPresent(UserDO::getName, "张三 1");
|
.eqIfExists(UserDO::getName, "张三 1");
|
||||||
List<UserDO> list1 = wrapper1.list();
|
List<UserDO> list1 = wrapper1.list();
|
||||||
list1.forEach(System.out::println);
|
list1.forEach(System.out::println);
|
||||||
|
|
||||||
@ -72,12 +72,12 @@ public class IfPresentTest {
|
|||||||
"WHERE t.del = false AND (t.id = ? AND t.pid = ? AND t.`name` = ? AND t.head_img = ? AND t.`name` = ?)");
|
"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)
|
MPJLambdaWrapper<UserDO> wrapper2 = JoinWrappers.lambda(UserDO.class)
|
||||||
.selectAll(UserDO.class)
|
.selectAll(UserDO.class)
|
||||||
.setIfPresent(o -> true)
|
.setIfExists(o -> true)
|
||||||
.eqIfPresent(UserDO::getId, 1)
|
.eqIfExists(UserDO::getId, 1)
|
||||||
.eqIfPresent(UserDO::getPid, null)
|
.eqIfExists(UserDO::getPid, null)
|
||||||
.eqIfPresent(UserDO::getName, "")
|
.eqIfExists(UserDO::getName, "")
|
||||||
.eqIfPresent(UserDO::getImg, "\t")
|
.eqIfExists(UserDO::getImg, "\t")
|
||||||
.eqIfPresent(UserDO::getName, "张三 1");
|
.eqIfExists(UserDO::getName, "张三 1");
|
||||||
List<UserDO> list2 = wrapper2.list();
|
List<UserDO> list2 = wrapper2.list();
|
||||||
list2.forEach(System.out::println);
|
list2.forEach(System.out::println);
|
||||||
}
|
}
|
@ -26,7 +26,7 @@ class CustomWrapperTest {
|
|||||||
//自定义wrapper扩展
|
//自定义wrapper扩展
|
||||||
class CWrapper<T> : KtLambdaWrapper<T>() {
|
class CWrapper<T> : KtLambdaWrapper<T>() {
|
||||||
|
|
||||||
override fun eqIfPresent(column: KProperty<*>?, `val`: Any?): CWrapper<T> {
|
override fun eqIfExists(column: KProperty<*>?, `val`: Any?): CWrapper<T> {
|
||||||
eq(Objects.nonNull(`val`), column, `val`)
|
eq(Objects.nonNull(`val`), column, `val`)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@ -44,14 +44,14 @@ class CustomWrapperTest {
|
|||||||
val wrapper: CWrapper<UserDO> = CWrapper<UserDO>()
|
val wrapper: CWrapper<UserDO> = CWrapper<UserDO>()
|
||||||
.selectAll(UserDO::class.java)
|
.selectAll(UserDO::class.java)
|
||||||
.toChildren<CWrapper<UserDO>> { CWrapper.toCWrapper() }
|
.toChildren<CWrapper<UserDO>> { CWrapper.toCWrapper() }
|
||||||
.eqIfPresent(UserDO::id, 1)
|
.eqIfExists(UserDO::id, 1)
|
||||||
val dos = userMapper?.selectList(wrapper)
|
val dos = userMapper?.selectList(wrapper)
|
||||||
dos?.forEach(System.out::println)
|
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")
|
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>()
|
val wrapper1: CWrapper<UserDO> = CWrapper<UserDO>()
|
||||||
.selectAll(UserDO::class.java)
|
.selectAll(UserDO::class.java)
|
||||||
.toChildren(Ref<CWrapper<UserDO>>())
|
.toChildren(Ref<CWrapper<UserDO>>())
|
||||||
.eqIfPresent(UserDO::id, null)
|
.eqIfExists(UserDO::id, null)
|
||||||
val dos1 = userMapper?.selectList(wrapper1)
|
val dos1 = userMapper?.selectList(wrapper1)
|
||||||
dos1?.forEach(System.out::println)
|
dos1?.forEach(System.out::println)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user