添加ifAbsent

This commit is contained in:
yulichang 2023-12-23 16:55:51 +08:00
parent a822c4f78e
commit 665e433051
19 changed files with 895 additions and 58 deletions

View File

@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.github.yulichang.autoconfigure.conditional.MPJSqlInjectorCondition;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.config.MPJInterceptorConfig;
import com.github.yulichang.config.enums.LogicDelTypeEnum;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
import com.github.yulichang.extension.mapping.config.MappingConfig;
import com.github.yulichang.injector.MPJSqlInjector;
import com.github.yulichang.interceptor.MPJInterceptor;
@ -56,20 +56,21 @@ public class MybatisPlusJoinAutoConfiguration {
private static final Logger logger = LoggerFactory.getLogger(MybatisPlusJoinAutoConfiguration.class);
@SuppressWarnings("FieldCanBeLocal")
private final MybatisPlusJoinProperties properties;
public MybatisPlusJoinAutoConfiguration(MybatisPlusJoinProperties properties,
ObjectProvider<MybatisPlusJoinPropertiesConsumer> propertiesConsumers) {
ObjectProvider<MybatisPlusJoinPropertiesConsumer> propertiesConsumers,
ObjectProvider<MybatisPlusJoinIfAbsent> ifAbsentConsumers) {
this.properties = Optional.ofNullable(propertiesConsumers.getIfAvailable()).map(c -> c.config(properties)).orElse(properties);
ConfigProperties.banner = this.properties.getBanner();
ConfigProperties.subTableLogic = this.properties.getSubTableLogic();
ConfigProperties.msCache = this.properties.isMsCache();
ConfigProperties.tableAlias = this.properties.getTableAlias();
ConfigProperties.joinPrefix = this.properties.getJoinPrefix();
ConfigProperties.logicDelType = "where".equalsIgnoreCase(this.properties.getLogicDelType()) ?
LogicDelTypeEnum.WHERE : LogicDelTypeEnum.ON;
ConfigProperties.logicDelType = this.properties.getLogicDelType();
ConfigProperties.mappingMaxCount = this.properties.getMappingMaxCount();
ConfigProperties.ifAbsent = Optional.ofNullable(ifAbsentConsumers.getIfAvailable()).orElse(this.properties.getIfAbsent());
info("mybatis plus join properties config complete");
}
/**
@ -101,7 +102,7 @@ public class MybatisPlusJoinAutoConfiguration {
@ConditionalOnBean(ISqlInjector.class)
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
public MPJSqlInjector mpjSqlInjector(ISqlInjector sqlInjector) {
logger.info("MPJSqlInjector init");
info("mybatis plus join SqlInjector init");
return new MPJSqlInjector(sqlInjector);
}
@ -113,7 +114,7 @@ public class MybatisPlusJoinAutoConfiguration {
@ConditionalOnMissingBean(ISqlInjector.class)
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
public MPJSqlInjector mpjSqlInjectorOnMiss() {
logger.info("MPJSqlInjector init");
info("mybatis plus join SqlInjector init");
return new MPJSqlInjector();
}
@ -129,6 +130,12 @@ public class MybatisPlusJoinAutoConfiguration {
}
}
private void info(String info) {
if (properties.getBanner()) {
logger.info(info);
}
}
@Configuration
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
public static class MPJSpringContext implements SpringContentUtils.SpringContext, BeanFactoryPostProcessor, ApplicationContextAware {

View File

@ -1,5 +1,7 @@
package com.github.yulichang.autoconfigure;
import com.github.yulichang.config.enums.IfAbsentEnum;
import com.github.yulichang.config.enums.LogicDelTypeEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ -43,7 +45,7 @@ public class MybatisPlusJoinProperties {
/**
* 逻辑删除类型 支持 where on
*/
private String logicDelType = "on";
private LogicDelTypeEnum logicDelType = LogicDelTypeEnum.ON;
/**
* 映射查询最大深度
@ -54,4 +56,15 @@ public class MybatisPlusJoinProperties {
* 子查询别名
*/
private String subQueryAlias = "st";
/**
* Wrapper ifAbsent 判断策略
* <p>
* NOT_NULL 非null
* <p>
* NOT_EMPTY 非空字符串 "" -> false, " " -> true ...
* <p>
* NOT_BLANK 非空白字符串 "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
*/
private IfAbsentEnum ifAbsent = IfAbsentEnum.NOT_EMPTY;
}

View File

@ -40,8 +40,8 @@
},
{
"name": "mybatis-plus-join.logic-del-type",
"defaultValue": "on",
"type": "java.lang.String",
"defaultValue": "com.github.yulichang.config.enums.LogicDelTypeEnum.ON",
"type": "com.github.yulichang.config.enums.LogicDelTypeEnum",
"description": "逻辑删除的位置支持where和on两个."
},
{
@ -55,21 +55,12 @@
"defaultValue": "st",
"type": "java.lang.String",
"description": "子查询表别名."
}
],
"hints": [
},
{
"name": "mybatis-plus-join.logic-del-type",
"values": [
{
"value": "where",
"description": "logic delete condition to where."
},
{
"value": "on",
"description": "logic delete condition to on."
}
]
"name": "mybatis-plus-join.ifAbsent",
"defaultValue": "com.github.yulichang.config.enums.IfAbsentEnum.NOT_EMPTY",
"type": "com.github.yulichang.config.enums.IfAbsentEnum",
"description": "IfAbsent方法判断策略,如需自定义请用@Bean形式MybatisPlusJoinIfAbsent."
}
]
}

View File

@ -2,6 +2,7 @@ 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.LogicDelTypeEnum;
/**
@ -11,7 +12,7 @@ import com.github.yulichang.config.enums.LogicDelTypeEnum;
public class ConfigProperties {
/**
* 是否开启副表逻辑删除
* 是否打印banner
*/
public static boolean banner = true;
/**
@ -35,7 +36,7 @@ public class ConfigProperties {
*/
public static LogicDelTypeEnum logicDelType = LogicDelTypeEnum.ON;
/**
* 逻辑删除类型 支持 where on
* 映射查询最大深度
*/
public static int mappingMaxCount = 5;
/**
@ -46,4 +47,14 @@ public class ConfigProperties {
* 子查询别名
*/
public static String subQueryAlias = "st";
/**
* Wrapper ifAbsent 判断策略
* <p>
* NOT_NULL 非null
* <p>
* NOT_EMPTY 非空字符串 "" -> false, " " -> true ...
* <p>
* NOT_BLANK 非空白字符串 "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
*/
public static MybatisPlusJoinIfAbsent ifAbsent = IfAbsentEnum.NOT_EMPTY;
}

View File

@ -0,0 +1,12 @@
package com.github.yulichang.config;
import java.util.function.Predicate;
/**
* 自定义IfAbsent策略
*
* @author yulichang
* @since 1.4.9
*/
public interface MybatisPlusJoinIfAbsent extends Predicate<Object> {
}

View File

@ -0,0 +1,40 @@
package com.github.yulichang.config.enums;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
import com.github.yulichang.toolkit.MPJStringUtils;
import java.util.Objects;
import java.util.function.Predicate;
/**
* 条件判断策略
*
* @author yulichang
* @since 1.4.9
*/
public enum IfAbsentEnum implements MybatisPlusJoinIfAbsent {
/**
* 非null
*/
NOT_NULL(Objects::nonNull),
/**
* 非空字符串 "" -> false, " " -> true ...
*/
NOT_EMPTY(val -> NOT_NULL.and(v -> v instanceof CharSequence).and(v -> MPJStringUtils.isNotEmpty((CharSequence) v)).test(val)),
/**
* NOT_BLANK 非空白字符串 "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
*/
NOT_BLANK(val -> NOT_NULL.and(v -> v instanceof CharSequence).and(v -> MPJStringUtils.isNotBlank((CharSequence) v)).test(val));
private final Predicate<Object> predicate;
IfAbsentEnum(Predicate<Object> predicate) {
this.predicate = predicate;
}
@Override
public boolean test(Object obj) {
return this.predicate.test(obj);
}
}

View File

@ -11,7 +11,9 @@ import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
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.kt.interfaces.Compare;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
import com.github.yulichang.kt.interfaces.CompareIfAbsent;
import com.github.yulichang.kt.interfaces.Func;
import com.github.yulichang.kt.interfaces.OnCompare;
import com.github.yulichang.toolkit.KtUtils;
@ -20,7 +22,7 @@ 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.PrefixEnum;
import com.github.yulichang.wrapper.interfaces.CompareStr;
import com.github.yulichang.wrapper.interfaces.CompareStrIfAbsent;
import com.github.yulichang.wrapper.interfaces.FuncStr;
import com.github.yulichang.wrapper.interfaces.Join;
import kotlin.reflect.KProperty;
@ -44,8 +46,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 Compare<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
CompareStr<Children, String>, FuncStr<Children, String> {
implements CompareIfAbsent<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
CompareStrIfAbsent<Children, String>, FuncStr<Children, String> {
/**
* 占位符
@ -121,6 +123,12 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
*/
protected boolean checkSqlInjection = false;
/**
* ifAbsent 策略
*/
@Getter
protected MybatisPlusJoinIfAbsent ifAbsent = ConfigProperties.ifAbsent;
@Override
public T getEntity() {
return entity;
@ -172,6 +180,11 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
return typedThis;
}
public Children setIfAbsent(MybatisPlusJoinIfAbsent ifAbsent) {
this.ifAbsent = ifAbsent;
return typedThis;
}
@Override
public Children allEq(boolean condition, Map<KProperty<?>, ?> params, boolean null2IsNull) {
if (condition && CollectionUtils.isNotEmpty(params)) {
@ -630,6 +643,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
index = null;
isMain = true;
isNo = false;
ifAbsent = ConfigProperties.ifAbsent;
}
/**

View File

@ -0,0 +1,97 @@
package com.github.yulichang.kt.interfaces;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
import kotlin.reflect.KProperty;
/**
* ifAbsent
*
* @author yulichang
* @since 1.4.9
*/
@SuppressWarnings("unused")
public interface CompareIfAbsent<Children> extends Compare<Children> {
MybatisPlusJoinIfAbsent getIfAbsent();
default Children eqIfAbsent(KProperty<?> column, Object val) {
return eq(getIfAbsent().test(val), null, column, val);
}
default Children eqIfAbsent(String alias, KProperty<?> column, Object val) {
return eq(getIfAbsent().test(val), alias, column, val);
}
default Children neIfAbsent(KProperty<?> column, Object val) {
return ne(getIfAbsent().test(val), null, column, val);
}
default Children neIfAbsent(String alias, KProperty<?> column, Object val) {
return ne(getIfAbsent().test(val), alias, column, val);
}
default Children gtIfAbsent(KProperty<?> column, Object val) {
return gt(getIfAbsent().test(val), null, column, val);
}
default Children gtIfAbsent(String alias, KProperty<?> column, Object val) {
return gt(getIfAbsent().test(val), alias, column, val);
}
default Children geIfAbsent(KProperty<?> column, Object val) {
return ge(getIfAbsent().test(val), null, column, val);
}
default Children geIfAbsent(String alias, KProperty<?> column, Object val) {
return ge(getIfAbsent().test(val), alias, column, val);
}
default Children ltIfAbsent(KProperty<?> column, Object val) {
return lt(getIfAbsent().test(val), null, column, val);
}
default Children ltIfAbsent(String alias, KProperty<?> column, Object val) {
return lt(getIfAbsent().test(val), alias, column, val);
}
default Children leIfAbsent(KProperty<?> column, Object val) {
return le(getIfAbsent().test(val), null, column, val);
}
default Children leIfAbsent(String alias, KProperty<?> column, Object val) {
return le(getIfAbsent().test(val), alias, column, val);
}
default Children likeIfAbsent(KProperty<?> column, Object val) {
return like(getIfAbsent().test(val), null, column, val);
}
default Children likeIfAbsent(String alisa, KProperty<?> column, Object val) {
return like(getIfAbsent().test(val), alisa, column, val);
}
default Children notLikeIfAbsent(KProperty<?> column, Object val) {
return notLike(getIfAbsent().test(val), null, column, val);
}
default Children notLikeIfAbsent(String alias, KProperty<?> column, Object val) {
return notLike(getIfAbsent().test(val), alias, column, val);
}
default Children likeLeftIfAbsent(KProperty<?> column, Object val) {
return likeLeft(getIfAbsent().test(val), null, column, val);
}
default Children likeLeftIfAbsent(String alias, KProperty<?> column, Object val) {
return likeLeft(getIfAbsent().test(val), alias, column, val);
}
default Children likeRightIfAbsent(KProperty<?> column, Object val) {
return likeRight(getIfAbsent().test(val), null, column, val);
}
default Children likeRightIfAbsent(String alias, KProperty<?> column, Object val) {
return likeRight(getIfAbsent().test(val), alias, column, val);
}
}

View File

@ -6,18 +6,22 @@ import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
import com.github.yulichang.query.interfaces.CompareIfAbsent;
import com.github.yulichang.query.interfaces.StringJoin;
import com.github.yulichang.toolkit.Asserts;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.toolkit.ThrowOptional;
import lombok.Getter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@ -30,7 +34,8 @@ 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> {
implements Query<MPJLambdaQueryWrapper<T>, T, SFunction<T, ?>>, StringJoin<MPJLambdaQueryWrapper<T>, T>,
CompareIfAbsent<MPJLambdaQueryWrapper<T>, SFunction<T, ?>> {
/**
* 查询字段
@ -45,7 +50,8 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
/**
* 主表别名
*/
private final String alias = ConfigProperties.tableAlias;
@Getter
private String alias = ConfigProperties.tableAlias;
/**
* 查询的列
@ -61,6 +67,17 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
* 是否 select distinct
*/
private boolean selectDistinct = false;
/**
* 主表逻辑删除
*/
private boolean logicSql = true;
/**
* 动态表名
*/
private Function<String, String> tableNameFunc;
@Getter
private MybatisPlusJoinIfAbsent ifAbsent = ConfigProperties.ifAbsent;
/**
* 不建议直接 new 该实例使用 Wrappers.lambdaQuery(entity)
@ -75,9 +92,10 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
MPJLambdaQueryWrapper(T entity, Class<T> entityClass, SharedString from, SharedString sqlSelect, AtomicInteger paramNameSeq,
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments,
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct) {
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct,
MybatisPlusJoinIfAbsent ifAbsent) {
super.setEntity(entity);
super.setEntityClass(entityClass);
setEntityClass(entityClass);
this.paramNameSeq = paramNameSeq;
this.paramNameValuePairs = paramNameValuePairs;
this.expression = mergeSegments;
@ -85,10 +103,11 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
this.from = from;
this.lastSql = lastSql;
this.sqlComment = sqlComment;
this.sqlFirst = sqlFirst;
ThrowOptional.tryDo(() -> this.sqlFirst = sqlFirst).catchDo();
this.selectColumns = selectColumns;
this.ignoreColumns = ignoreColumns;
this.selectDistinct = selectDistinct;
this.ifAbsent = ifAbsent;
}
/**
@ -214,7 +233,8 @@ 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);
expression, sqlSelect, from, lastSql, sqlComment, sqlFirst, selectColumns, ignoreColumns,
selectDistinct, ifAbsent);
}
@Override
@ -241,15 +261,86 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
return from.getStringValue();
}
public String getAlias() {
return alias;
public MPJLambdaQueryWrapper<T> setAlias(String alias) {
Assert.isTrue(StringUtils.isNotBlank(alias), "别名不能为空");
this.alias = alias;
return typedThis;
}
/**
* 逻辑删除
*/
public String getSubLogicSql() {
return StringPool.EMPTY;
}
/**
* 关闭主表逻辑删除
*/
public MPJLambdaQueryWrapper<T> disableLogicDel() {
this.logicSql = false;
return typedThis;
}
/**
* 启用主表逻辑删除
*/
public MPJLambdaQueryWrapper<T> enableLogicDel() {
this.logicSql = true;
return typedThis;
}
/**
* 逻辑删除
*/
public boolean getLogicSql() {
return logicSql;
}
public boolean getSelectDistinct() {
return selectDistinct;
}
/**
* 动态表名
* 如果主表需要动态表名,主表实体必须添加 @DynamicTableName 注解
* 关联表则不需要 加不加注解都会生效
* <p>
*
* @see com.github.yulichang.annotation.DynamicTableName
*/
public MPJLambdaQueryWrapper<T> setTableName(Function<String, String> func) {
this.tableNameFunc = func;
return typedThis;
}
public String getTableName(String tableName) {
if (this.tableNameFunc == null) {
return tableName;
}
return this.tableNameFunc.apply(tableName);
}
@SuppressWarnings("DuplicatedCode")
public String getTableNameEnc(String tableName) {
String decode;
try {
decode = URLDecoder.decode(tableName, "UTF-8");
} catch (UnsupportedEncodingException e) {
decode = tableName;
}
if (this.tableNameFunc == null) {
return decode;
}
return this.tableNameFunc.apply(decode);
}
public MPJLambdaQueryWrapper<T> setIfAbsent(MybatisPlusJoinIfAbsent ifAbsent) {
this.ifAbsent = ifAbsent;
return typedThis;
}
/**
* 用于生成嵌套 sql
* <p> sqlSelect selectColumn ignoreColumns from不向下传递</p>
@ -257,7 +348,34 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
@Override
protected MPJLambdaQueryWrapper<T> instance() {
return new MPJLambdaQueryWrapper<>(getEntity(), getEntityClass(), null, null, paramNameSeq, paramNameValuePairs,
new MergeSegments(), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(), null, null, selectDistinct);
new MergeSegments(), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
null, null, selectDistinct, ifAbsent);
}
@Override
public Class<T> getEntityClass() {
try {
return super.getEntityClass();
} catch (Throwable throwable) {
return null;
}
}
@Override
public MPJLambdaQueryWrapper<T> setEntityClass(Class<T> entityClass) {
try {
return super.setEntityClass(entityClass);
} catch (Throwable throwable) {
return this;
}
}
public SharedString getSqlFirstField() {
try {
return sqlSelect;
} catch (Throwable throwable) {
return SharedString.emptyString();
}
}
@Override
@ -267,6 +385,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
from.toNull();
selectColumns.clear();
ignoreColumns.clear();
ifAbsent = ConfigProperties.ifAbsent;
}
@Override

View File

@ -11,10 +11,13 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.github.yulichang.adapter.base.tookit.VersionUtils;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
import com.github.yulichang.query.interfaces.CompareIfAbsent;
import com.github.yulichang.query.interfaces.StringJoin;
import com.github.yulichang.toolkit.Asserts;
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.toolkit.ThrowOptional;
import com.github.yulichang.wrapper.interfaces.Chain;
import lombok.Getter;
@ -38,7 +41,8 @@ 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> {
Query<MPJQueryWrapper<T>, T, String>, StringJoin<MPJQueryWrapper<T>, T>, Chain<T>,
CompareIfAbsent<MPJQueryWrapper<T>, String> {
/**
* 查询字段
@ -85,6 +89,9 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
*/
private boolean checkSqlInjection = false;
@Getter
private MybatisPlusJoinIfAbsent ifAbsent = ConfigProperties.ifAbsent;
public MPJQueryWrapper() {
super.initNeed();
@ -115,9 +122,10 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments,
SharedString sqlSelect, SharedString from, SharedString lastSql,
SharedString sqlComment, SharedString sqlFirst,
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct) {
List<String> selectColumns, List<String> ignoreColumns, boolean selectDistinct,
MybatisPlusJoinIfAbsent ifAbsent) {
super.setEntity(entity);
super.setEntityClass(entityClass);
setEntityClass(entityClass);
this.paramNameSeq = paramNameSeq;
this.paramNameValuePairs = paramNameValuePairs;
this.expression = mergeSegments;
@ -125,10 +133,11 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
this.lastSql = lastSql;
this.from = from;
this.sqlComment = sqlComment;
this.sqlFirst = sqlFirst;
ThrowOptional.tryDo(() -> this.sqlFirst = sqlFirst).catchDo();
this.selectColumns = selectColumns;
this.ignoreColumns = ignoreColumns;
this.selectDistinct = selectDistinct;
this.ifAbsent = ifAbsent;
}
/**
@ -139,6 +148,11 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
return this;
}
public MPJQueryWrapper<T> setIfAbsent(MybatisPlusJoinIfAbsent ifAbsent) {
this.ifAbsent = ifAbsent;
return this;
}
@Override
protected String columnToString(String column) {
if (checkSqlInjection && MPJSqlInjectionUtils.check(column)) {
@ -315,6 +329,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
return this.tableNameFunc.apply(tableName);
}
@SuppressWarnings("DuplicatedCode")
public String getTableNameEnc(String tableName) {
String decode;
try {
@ -333,7 +348,33 @@ 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, sqlFirst, selectColumns, ignoreColumns, selectDistinct);
expression, lastSql, sqlComment, getSqlFirstField(), selectColumns, ignoreColumns, selectDistinct, ifAbsent);
}
@Override
public Class<T> getEntityClass() {
try {
return super.getEntityClass();
} catch (Throwable throwable) {
return null;
}
}
@Override
public MPJQueryWrapper<T> setEntityClass(Class<T> entityClass) {
try {
return super.setEntityClass(entityClass);
} catch (Throwable throwable) {
return this;
}
}
public SharedString getSqlFirstField() {
try {
return sqlSelect;
} catch (Throwable throwable) {
return SharedString.emptyString();
}
}
/**
@ -343,7 +384,8 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
@Override
protected MPJQueryWrapper<T> instance() {
return new MPJQueryWrapper<>(getEntity(), getEntityClass(), paramNameSeq, paramNameValuePairs, new MergeSegments(),
null, null, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(), null, null, selectDistinct);
null, null, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
null, null, selectDistinct, ifAbsent);
}
@ -354,6 +396,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
from.toNull();
selectColumns.clear();
ignoreColumns.clear();
ifAbsent = ConfigProperties.ifAbsent;
}
@Override

View File

@ -0,0 +1,149 @@
package com.github.yulichang.query.interfaces;
import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
/**
* 查询条件封装
* <p>比较值</p>
*
* @author yulichang
* @since 1.4.9
*/
@SuppressWarnings("unused")
public interface CompareIfAbsent<Children, R> extends Compare<Children, R> {
MybatisPlusJoinIfAbsent getIfAbsent();
/**
* 等于 =
*
* @param column 字段
* @param val
* @return children
*/
default Children eqIfAbsent(R column, Object val) {
return eq(getIfAbsent().test(val), column, val);
}
/**
* 不等于 &lt;&gt;
*
* @param column 字段
* @param val
* @return children
*/
default Children neIfAbsent(R column, Object val) {
return ne(getIfAbsent().test(val), column, val);
}
/**
* 大于 &gt;
*
* @param column 字段
* @param val
* @return children
*/
default Children gtIfAbsent(R column, Object val) {
return gt(getIfAbsent().test(val), column, val);
}
/**
* 大于等于 &gt;=
*
* @param column 字段
* @param val
* @return children
*/
default Children geIfAbsent(R column, Object val) {
return ge(getIfAbsent().test(val), column, val);
}
/**
* 小于 &lt;
*
* @param column 字段
* @param val
* @return children
*/
default Children ltIfAbsent(R column, Object val) {
return lt(getIfAbsent().test(val), column, val);
}
/**
* 小于等于 &lt;=
*
* @param column 字段
* @param val
* @return children
*/
default Children leIfAbsent(R column, Object val) {
return le(getIfAbsent().test(val), column, val);
}
/**
* LIKE '%%'
*
* @param column 字段
* @param val
* @return children
*/
default Children likeIfAbsent(R column, Object val) {
return like(getIfAbsent().test(val), column, val);
}
/**
* NOT LIKE '%%'
*
* @param column 字段
* @param val
* @return children
*/
default Children notLikeIfAbsent(R column, Object val) {
return notLike(getIfAbsent().test(val), column, val);
}
/**
* NOT LIKE '%'
*
* @param column 字段
* @param val
* @return children
*/
default Children notLikeLeftIfAbsent(R column, Object val) {
return notLikeLeft(getIfAbsent().test(val), column, val);
}
/**
* NOT LIKE '%'
*
* @param column 字段
* @param val
* @return children
*/
default Children notLikeRightIfAbsent(R column, Object val) {
return notLikeRight(getIfAbsent().test(val), column, val);
}
/**
* LIKE '%'
*
* @param column 字段
* @param val
* @return children
*/
default Children likeLeftIfAbsent(R column, Object val) {
return likeLeft(getIfAbsent().test(val), column, val);
}
/**
* LIKE '%'
*
* @param column 字段
* @param val
* @return children
*/
default Children likeRightIfAbsent(R column, Object val) {
return likeRight(getIfAbsent().test(val), column, val);
}
}

View File

@ -598,10 +598,25 @@ public final class MPJStringUtils {
/**
* 过滤sql黑名单字符存在 SQL 注入去除空白内容
*/
Matcher matcher = REPLACE_BLANK.matcher(str);
str = matcher.replaceAll("");
str = replaceAllBlank(str);
}
return str;
}
/**
* 字符串去除空白内容
* <ul>
* <li>\n 回车</li>
* <li>\t 水平制表符</li>
* <li>\s 空格</li>
* <li>\r 换行</li>
* </ul>
*
* @param str 字符串
*/
public static String replaceAllBlank(String str) {
Matcher matcher = REPLACE_BLANK.matcher(str);
return matcher.replaceAll("");
}
}

View File

@ -0,0 +1,53 @@
package com.github.yulichang.toolkit;
import java.util.Objects;
import java.util.function.Consumer;
/**
* @author yulichang
* @since 1.4.9
*/
@SuppressWarnings("unused")
public class ThrowOptional {
private ThrowOptional() {
}
private DoSomething doSomething;
public static ThrowOptional tryDo(DoSomething doSomething) {
ThrowOptional optional = new ThrowOptional();
Objects.requireNonNull(doSomething);
optional.doSomething = doSomething;
return optional;
}
public void catchDo() {
try {
this.doSomething.doSomething();
} catch (Throwable ignored) {
}
}
public void catchDo(DoSomething doSomething) {
try {
this.doSomething.doSomething();
} catch (Throwable ignored) {
doSomething.doSomething();
}
}
public void catchDo(Consumer<Throwable> consumer) {
try {
this.doSomething.doSomething();
} catch (Throwable throwable) {
consumer.accept(throwable);
}
}
@FunctionalInterface
public interface DoSomething {
void doSomething();
}
}

View File

@ -12,6 +12,8 @@ import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
import com.github.yulichang.toolkit.Ref;
@ -39,8 +41,8 @@ import static java.util.stream.Collectors.joining;
*/
@SuppressWarnings({"unchecked", "unused", "DuplicatedCode"})
public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<T, Children>> extends Wrapper<T>
implements Compare<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
CompareStr<Children, String>, FuncStr<Children, String> {
implements CompareIfAbsent<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
CompareStrIfAbsent<Children, String>, FuncStr<Children, String> {
/**
* 占位符
@ -116,6 +118,12 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
*/
protected boolean checkSqlInjection = false;
/**
* ifAbsent 策略
*/
@Getter
protected MybatisPlusJoinIfAbsent ifAbsent = ConfigProperties.ifAbsent;
@Override
public T getEntity() {
return entity;
@ -167,6 +175,18 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
return typedThis;
}
/**
* 设置 ifAbsent
* .setIfAbsent(val -> val != null && StringUtils.isNotBlank(val))
*
* @param ifAbsent 判断
* @return Children
*/
public Children setIfAbsent(MybatisPlusJoinIfAbsent ifAbsent) {
this.ifAbsent = ifAbsent;
return typedThis;
}
@Override
public <X, V> Children allEq(boolean condition, Map<SFunction<X, ?>, V> params, boolean null2IsNull) {
if (condition && CollectionUtils.isNotEmpty(params)) {
@ -400,7 +420,7 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
public <R> Children groupBy(boolean condition, String alias, List<SFunction<R, ?>> columns) {
return maybeDo(condition, () -> {
if (CollectionUtils.isNotEmpty(columns)) {
final String finalOne = columnsToString(index, isOn ? PrefixEnum.ON_FIRST : PrefixEnum.CD_FIRST, alias, columns);
final String finalOne = columnsToString(index, isOn ? PrefixEnum.ON_FIRST : PrefixEnum.CD_FIRST, alias, columns);
appendSqlSegments(GROUP_BY, () -> finalOne);
}
});
@ -737,6 +757,7 @@ public abstract class MPJAbstractWrapper<T, Children extends MPJAbstractWrapper<
index = null;
isMain = true;
isOn = false;
ifAbsent = ConfigProperties.ifAbsent;
}
/**

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.*;
import com.github.yulichang.toolkit.support.ColumnCache;
@ -123,7 +124,8 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
MPJLambdaWrapper(T entity, Class<T> entityClass, SharedString sqlSelect, AtomicInteger paramNameSeq,
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
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,
MybatisPlusJoinIfAbsent ifAbsent) {
super.setEntity(entity);
super.setEntityClass(entityClass);
this.paramNameSeq = paramNameSeq;
@ -139,6 +141,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
this.keyWord = keyWord;
this.joinClass = joinClass;
this.tableName = tableName;
this.ifAbsent = ifAbsent;
}
@ -207,7 +210,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
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) {
new TableList(), null, null, null, null, ifAbsent) {
};
wrapper.tableList.setAlias(st);
wrapper.tableList.setRootClass(clazz);
@ -402,7 +405,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
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);
this.tableList, index, keyWord, joinClass, tableName, ifAbsent);
}
@Override
@ -415,5 +418,6 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
if (Objects.nonNull(wrapperMap)) wrapperMap.clear();
if (Objects.nonNull(unionSql)) unionSql.toEmpty();
resultMapMybatisLabel.clear();
ifAbsent = ConfigProperties.ifAbsent;
}
}

View File

@ -0,0 +1,96 @@
package com.github.yulichang.wrapper.interfaces;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
/**
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
*
* @author yulichang
* @since 1.4.9
*/
@SuppressWarnings("unused")
public interface CompareIfAbsent<Children> extends Compare<Children> {
MybatisPlusJoinIfAbsent getIfAbsent();
default <R> Children eqIfAbsent(SFunction<R, ?> column, Object val) {
return eq(getIfAbsent().test(val), null, column, val);
}
default <R> Children eqIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return eq(getIfAbsent().test(val), alias, column, val);
}
default <R> Children neIfAbsent(SFunction<R, ?> column, Object val) {
return ne(getIfAbsent().test(val), null, column, val);
}
default <R> Children neIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return ne(getIfAbsent().test(val), alias, column, val);
}
default <R> Children gtIfAbsent(SFunction<R, ?> column, Object val) {
return gt(getIfAbsent().test(val), null, column, val);
}
default <R> Children gtIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return gt(getIfAbsent().test(val), alias, column, val);
}
default <R> Children geIfAbsent(SFunction<R, ?> column, Object val) {
return ge(getIfAbsent().test(val), null, column, val);
}
default <R> Children geIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return ge(getIfAbsent().test(val), alias, column, val);
}
default <R> Children ltIfAbsent(SFunction<R, ?> column, Object val) {
return lt(getIfAbsent().test(val), null, column, val);
}
default <R> Children ltIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return lt(getIfAbsent().test(val), alias, column, val);
}
default <R> Children leIfAbsent(SFunction<R, ?> column, Object val) {
return le(getIfAbsent().test(val), null, column, val);
}
default <R> Children leIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return le(getIfAbsent().test(val), alias, column, val);
}
default <R> Children likeIfAbsent(SFunction<R, ?> column, Object val) {
return like(getIfAbsent().test(val), null, column, val);
}
default <R> Children likeIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return like(getIfAbsent().test(val), alias, column, val);
}
default <R> Children notLikeIfAbsent(SFunction<R, ?> column, Object val) {
return notLike(getIfAbsent().test(val), null, column, val);
}
default <R> Children notLikeIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return notLike(getIfAbsent().test(val), alias, column, val);
}
default <R> Children likeLeftIfAbsent(SFunction<R, ?> column, Object val) {
return likeLeft(getIfAbsent().test(val), null, column, val);
}
default <R> Children likeLeftIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return likeLeft(getIfAbsent().test(val), alias, column, val);
}
default <R> Children likeRightIfAbsent(SFunction<R, ?> column, Object val) {
return likeRight(getIfAbsent().test(val), null, column, val);
}
default <R> Children likeRightIfAbsent(String alias, SFunction<R, ?> column, Object val) {
return likeRight(getIfAbsent().test(val), alias, column, val);
}
}

View File

@ -0,0 +1,55 @@
package com.github.yulichang.wrapper.interfaces;
import com.github.yulichang.config.MybatisPlusJoinIfAbsent;
/**
* {@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> {
MybatisPlusJoinIfAbsent getIfAbsent();
default Children eqIfAbsent(R column, Object val) {
return eq(getIfAbsent().test(val), column, val);
}
default Children neIfAbsent(R column, Object val) {
return ne(getIfAbsent().test(val), column, val);
}
default Children gtIfAbsent(R column, Object val) {
return gt(getIfAbsent().test(val), column, val);
}
default Children geIfAbsent(R column, Object val) {
return ge(getIfAbsent().test(val), column, val);
}
default Children ltIfAbsent(R column, Object val) {
return lt(getIfAbsent().test(val), column, val);
}
default Children leIfAbsent(R column, Object val) {
return le(getIfAbsent().test(val), column, val);
}
default Children likeIfAbsent(R column, Object val) {
return like(getIfAbsent().test(val), column, val);
}
default Children notLikeIfAbsent(R column, Object val) {
return notLike(getIfAbsent().test(val), column, val);
}
default Children likeLeftIfAbsent(R column, Object val) {
return likeLeft(getIfAbsent().test(val), column, val);
}
default Children likeRightIfAbsent(R column, Object val) {
return likeRight(getIfAbsent().test(val), column, val);
}
}

View File

@ -115,4 +115,35 @@ class QueryWrapperTest {
System.out.println(joinMaps);
}
@Test
void test5() {
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 LEFT JOIN address t2 ON t2.user_id = t.id " +
"WHERE t.del = false AND (t.id <= ?)");
List<UserDO> userDO = userMapper.selectJoinList(UserDO.class, new MPJQueryWrapper<UserDO>()
.selectAll(UserDO.class)
.leftJoin("address t2 on t2.user_id = t.id")
.le("t.id ", 10).lambda());
System.out.println(userDO);
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, t2.address AS userAddress FROM `user` t " +
"LEFT JOIN address t2 ON t2.user_id = t.id WHERE t.del = false AND (t.id <= ?)");
List<UserDTO> dto = userMapper.selectJoinList(UserDTO.class, new MPJQueryWrapper<UserDO>()
.selectAll(UserDO.class)
.select("t2.address AS userAddress")
.leftJoin("address t2 on t2.user_id = t.id")
.le("t.id ", 10).lambda());
System.out.println(dto);
}
@Test
void test6() {
ThreadLocalUtils.set("SELECT t.id AS idea, t.user_id AS uuid, t.tenant_id FROM user_tenant t WHERE (t.id <= ?) AND t.tenant_id = 1");
List<UserTenantDO> userDO = userTenantMapper.selectJoinList(UserTenantDO.class, new MPJQueryWrapper<UserTenantDO>()
.selectAll(UserTenantDO.class)
.le("t.id ", 10).lambda());
System.out.println(userDO);
}
}

View File

@ -0,0 +1,66 @@
package com.github.yulichang.test.join.m;
import com.github.yulichang.config.enums.IfAbsentEnum;
import com.github.yulichang.test.join.entity.UserDO;
import com.github.yulichang.test.util.Reset;
import com.github.yulichang.test.util.ThreadLocalUtils;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
public class IfAbsentTest {
@BeforeEach
void setUp() {
Reset.reset();
}
@Test
void ifAbsent() {
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
"t.address_id2, t.del, t.create_by, t.update_by FROM `user` t " +
"WHERE t.del = false AND (t.id = ? AND t.head_img = ? AND t.`name` = ?)");
MPJLambdaWrapper<UserDO> wrapper = JoinWrappers.lambda(UserDO.class)
.selectAll(UserDO.class)
.eq(UserDO::getId, 1)
.eqIfAbsent(UserDO::getPid, null)
.eqIfAbsent(UserDO::getAddressId, "")
.eqIfAbsent(UserDO::getImg, "\t")
.eqIfAbsent(UserDO::getName, "张三 1");
List<UserDO> list = wrapper.list();
list.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 AND (t.id = ? AND t.`name` = ?)");
MPJLambdaWrapper<UserDO> wrapper1 = JoinWrappers.lambda(UserDO.class)
.selectAll(UserDO.class)
.setIfAbsent(IfAbsentEnum.NOT_BLANK)
.eq(UserDO::getId, 1)
.eqIfAbsent(UserDO::getPid, null)
.eqIfAbsent(UserDO::getAddressId, "")
.eqIfAbsent(UserDO::getImg, "\t")
.eqIfAbsent(UserDO::getName, "张三 1");
List<UserDO> list1 = wrapper1.list();
list1.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 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)
.eq(UserDO::getId, 1)
.eqIfAbsent(UserDO::getPid, null)
.eqIfAbsent(UserDO::getName, "")
.eqIfAbsent(UserDO::getImg, "\t")
.eqIfAbsent(UserDO::getName, "张三 1");
List<UserDO> list2 = wrapper2.list();
list2.forEach(System.out::println);
}
}