From f2ad31cbe44400eddaae558df17c17fc11e3e735 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 14 Dec 2022 15:28:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20PARAM=5FTYPE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/yulichang/interceptor/MPJInterceptor.java | 10 ---------- .../com/github/yulichang/method/mp/SelectCount.java | 5 +++-- .../com/github/yulichang/method/mp/SelectList.java | 7 ++++--- .../com/github/yulichang/method/mp/SelectMaps.java | 7 ++++--- .../github/yulichang/method/mp/SelectMapsPage.java | 7 ++++--- .../com/github/yulichang/method/mp/SelectObjs.java | 7 ++++--- .../com/github/yulichang/method/mp/SelectOne.java | 7 ++++--- .../com/github/yulichang/method/mp/SelectPage.java | 7 ++++--- .../com/github/yulichang/method/mp/TableAlias.java | 12 ++++++------ .../java/com/github/yulichang/toolkit/Constant.java | 2 -- 10 files changed, 33 insertions(+), 38 deletions(-) diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java index f12cb5b..ba5e47b 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java @@ -3,7 +3,6 @@ package com.github.yulichang.interceptor; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.baomidou.mybatisplus.core.toolkit.*; -import com.github.yulichang.interfaces.MPJBaseJoin; import com.github.yulichang.mapper.MPJTableMapperHelper; import com.github.yulichang.method.MPJResultType; import com.github.yulichang.query.MPJQueryWrapper; @@ -15,8 +14,6 @@ import com.github.yulichang.wrapper.resultmap.Result; import com.github.yulichang.wrapper.segments.Select; import com.github.yulichang.wrapper.segments.SelectLabel; import org.apache.ibatis.executor.Executor; -import org.apache.ibatis.logging.Log; -import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.mapping.ResultFlag; import org.apache.ibatis.mapping.ResultMap; @@ -46,8 +43,6 @@ import java.util.concurrent.ConcurrentHashMap; public class MPJInterceptor implements Interceptor { - private static final Log logger = LogFactory.getLog(MPJInterceptor.class); - private static final List EMPTY_RESULT_MAPPING = new ArrayList<>(0); /** @@ -65,11 +60,6 @@ public class MPJInterceptor implements Interceptor { if (args[1] instanceof Map) { Map map = (Map) args[1]; Object ew = map.containsKey(Constants.WRAPPER) ? map.get(Constants.WRAPPER) : null; - if (!map.containsKey(Constant.PARAM_TYPE)) { - map.put(Constant.PARAM_TYPE, Objects.nonNull(ew) && (ew instanceof MPJBaseJoin)); - } else { - logger.warn(String.format("请不要使用MPJ预留参数名 %s", Constant.PARAM_TYPE)); - } if (CollectionUtils.isNotEmpty(map) && map.containsKey(Constant.CLAZZ)) { Class clazz = (Class) map.get(Constant.CLAZZ); if (Objects.nonNull(clazz)) { diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectCount.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectCount.java index c422f98..e33eb38 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectCount.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectCount.java @@ -2,8 +2,9 @@ package com.github.yulichang.method.mp; import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper; import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.toolkit.Constant; +import com.github.yulichang.interfaces.MPJBaseJoin; import org.apache.ibatis.mapping.MappedStatement; /** @@ -28,7 +29,7 @@ public class SelectCount extends com.baomidou.mybatisplus.core.injector.methods. @Override protected String sqlWhereEntityWrapper(boolean newLine, TableInfo table) { - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), super.sqlWhereEntityWrapper(newLine, table), mpjSqlWhereEntityWrapper(newLine, table)); } } \ No newline at end of file diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectList.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectList.java index a05606a..1602af6 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectList.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectList.java @@ -2,9 +2,10 @@ package com.github.yulichang.method.mp; import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper; import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.toolkit.Constant; +import com.github.yulichang.interfaces.MPJBaseJoin; import org.apache.ibatis.mapping.MappedStatement; /** @@ -29,14 +30,14 @@ public class SelectList extends com.baomidou.mybatisplus.core.injector.methods.S @Override protected String sqlWhereEntityWrapper(boolean newLine, TableInfo table) { - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), super.sqlWhereEntityWrapper(newLine, table), mpjSqlWhereEntityWrapper(newLine, table)); } @Override protected String sqlSelectColumns(TableInfo table, boolean queryWrapper) { String selectColumns = super.sqlSelectColumns(table, queryWrapper); - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), selectColumns, mpjSqlSelectColumns() + StringPool.SPACE + selectColumns); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMaps.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMaps.java index 5f3a964..da91597 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMaps.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMaps.java @@ -2,9 +2,10 @@ package com.github.yulichang.method.mp; import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper; import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.toolkit.Constant; +import com.github.yulichang.interfaces.MPJBaseJoin; import org.apache.ibatis.mapping.MappedStatement; /** @@ -29,14 +30,14 @@ public class SelectMaps extends com.baomidou.mybatisplus.core.injector.methods.S @Override protected String sqlWhereEntityWrapper(boolean newLine, TableInfo table) { - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), super.sqlWhereEntityWrapper(newLine, table), mpjSqlWhereEntityWrapper(newLine, table)); } @Override protected String sqlSelectColumns(TableInfo table, boolean queryWrapper) { String selectColumns = super.sqlSelectColumns(table, queryWrapper); - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), selectColumns, mpjSqlSelectColumns() + StringPool.SPACE + selectColumns); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMapsPage.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMapsPage.java index 402cc5e..b6e592a 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMapsPage.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMapsPage.java @@ -2,9 +2,10 @@ package com.github.yulichang.method.mp; import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper; import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.toolkit.Constant; +import com.github.yulichang.interfaces.MPJBaseJoin; import org.apache.ibatis.mapping.MappedStatement; /** @@ -29,14 +30,14 @@ public class SelectMapsPage extends com.baomidou.mybatisplus.core.injector.metho @Override protected String sqlWhereEntityWrapper(boolean newLine, TableInfo table) { - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), super.sqlWhereEntityWrapper(newLine, table), mpjSqlWhereEntityWrapper(newLine, table)); } @Override protected String sqlSelectColumns(TableInfo table, boolean queryWrapper) { String selectColumns = super.sqlSelectColumns(table, queryWrapper); - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), selectColumns, mpjSqlSelectColumns() + StringPool.SPACE + selectColumns); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectObjs.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectObjs.java index ce07be6..81d5a35 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectObjs.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectObjs.java @@ -2,9 +2,10 @@ package com.github.yulichang.method.mp; import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper; import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.toolkit.Constant; +import com.github.yulichang.interfaces.MPJBaseJoin; import org.apache.ibatis.mapping.MappedStatement; /** @@ -29,14 +30,14 @@ public class SelectObjs extends com.baomidou.mybatisplus.core.injector.methods.S @Override protected String sqlWhereEntityWrapper(boolean newLine, TableInfo table) { - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), super.sqlWhereEntityWrapper(newLine, table), mpjSqlWhereEntityWrapper(newLine, table)); } @Override protected String sqlSelectColumns(TableInfo table, boolean queryWrapper) { String selectColumns = super.sqlSelectColumns(table, queryWrapper); - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), selectColumns, mpjSqlSelectColumns() + StringPool.SPACE + selectColumns); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectOne.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectOne.java index 93cd0a6..f6023c9 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectOne.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectOne.java @@ -2,9 +2,10 @@ package com.github.yulichang.method.mp; import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper; import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.toolkit.Constant; +import com.github.yulichang.interfaces.MPJBaseJoin; import org.apache.ibatis.mapping.MappedStatement; /** @@ -34,14 +35,14 @@ public class SelectOne extends com.baomidou.mybatisplus.core.injector.methods.Se @Override protected String sqlWhereEntityWrapper(boolean newLine, TableInfo table) { - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), super.sqlWhereEntityWrapper(newLine, table), mpjSqlWhereEntityWrapper(newLine, table)); } @Override protected String sqlSelectColumns(TableInfo table, boolean queryWrapper) { String selectColumns = super.sqlSelectColumns(table, queryWrapper); - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), selectColumns, mpjSqlSelectColumns() + StringPool.SPACE + selectColumns); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectPage.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectPage.java index 5816266..e252206 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectPage.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectPage.java @@ -2,9 +2,10 @@ package com.github.yulichang.method.mp; import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper; import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; -import com.github.yulichang.toolkit.Constant; +import com.github.yulichang.interfaces.MPJBaseJoin; import org.apache.ibatis.mapping.MappedStatement; /** @@ -29,14 +30,14 @@ public class SelectPage extends com.baomidou.mybatisplus.core.injector.methods.S @Override protected String sqlWhereEntityWrapper(boolean newLine, TableInfo table) { - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), super.sqlWhereEntityWrapper(newLine, table), mpjSqlWhereEntityWrapper(newLine, table)); } @Override protected String sqlSelectColumns(TableInfo table, boolean queryWrapper) { String selectColumns = super.sqlSelectColumns(table, queryWrapper); - return SqlScriptUtils.convertChoose(String.format("%s == null or !%s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), + return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), selectColumns, mpjSqlSelectColumns() + StringPool.SPACE + selectColumns); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/TableAlias.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/TableAlias.java index 1b2fd6b..8498282 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/TableAlias.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/TableAlias.java @@ -3,8 +3,8 @@ package com.github.yulichang.method.mp; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; +import com.github.yulichang.interfaces.MPJBaseJoin; import com.github.yulichang.method.MPJBaseMethod; -import com.github.yulichang.toolkit.Constant; /** * 兼容原生方法 @@ -15,10 +15,10 @@ import com.github.yulichang.toolkit.Constant; public interface TableAlias extends Constants, MPJBaseMethod { default String getTableName(TableInfo tableInfo) { - return tableInfo.getTableName() + SPACE + SqlScriptUtils.convertIf("${ew.alias}", - String.format("%s != null and %s", Constant.PARAM_TYPE, Constant.PARAM_TYPE), false) - + SPACE + SqlScriptUtils.convertIf("${ew.from}", - String.format("%s != null and %s and %s != null and %s != ''", Constant.PARAM_TYPE, Constant.PARAM_TYPE, - "ew.from", "ew.from"), false); + String from = SqlScriptUtils.convertIf("${ew.from}", + String.format("%s != null and %s != ''", "ew.from", "ew.from"), true); + String alias = SqlScriptUtils.convertIf("${ew.alias}" + NEWLINE + from, + String.format("%s != null and %s instanceof %s", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), true); + return tableInfo.getTableName() + SPACE + alias; } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/Constant.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/Constant.java index c71a8d3..560225a 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/Constant.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/Constant.java @@ -27,8 +27,6 @@ public interface Constant { String CLAZZ = "resultTypeClass_Eg1sG"; - String PARAM_TYPE = "paramType_Gr8re1Ee"; - /** * " LEFT JOIN " */