From 5cc0c3200458a8ef9a24b53fc7e4f6df13d069c2 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 30 Nov 2022 19:16:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/github/yulichang/method/MPJBaseMethod.java | 9 ++++----- .../com/github/yulichang/query/MPJQueryWrapper.java | 3 +-- .../yulichang/test/join/LambdaWrapperTest.java | 7 +++---- .../github/yulichang/test/join/QueryWrapperTest.java | 12 ++++++++++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJBaseMethod.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJBaseMethod.java index 07ce1fd..2867e58 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJBaseMethod.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJBaseMethod.java @@ -30,12 +30,11 @@ public interface MPJBaseMethod extends Constants { if (ConfigProperties.subTableLogic) { sqlScript += (NEWLINE + String.format("${%s.subLogicSql}", WRAPPER)); } - String normalSqlScript = SqlScriptUtils.convertIf(String.format("AND ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_NONEMPTYOFNORMAL), true); - normalSqlScript += NEWLINE; - normalSqlScript += SqlScriptUtils.convertIf(String.format(" ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_EMPTYOFNORMAL), true); - sqlScript += normalSqlScript; - sqlScript = SqlScriptUtils.convertChoose(String.format("%s != null", WRAPPER), sqlScript, table.getLogicDeleteSql(false, true)); + sqlScript += SqlScriptUtils.convertIf(String.format("AND ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_NONEMPTYOFNORMAL), true); + sqlScript += NEWLINE; sqlScript = SqlScriptUtils.convertWhere(sqlScript); + sqlScript += SqlScriptUtils.convertIf(String.format(" ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_EMPTYOFNORMAL), true); + sqlScript = SqlScriptUtils.convertChoose(String.format("%s != null", WRAPPER), sqlScript, table.getLogicDeleteSql(false, true)); return newLine ? NEWLINE + sqlScript : sqlScript; } else { String sqlScript = getAllSqlWhere(table, false, true, WRAPPER_ENTITY_DOT); diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java index e47eb17..e3c6f5f 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java @@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.baomidou.mybatisplus.core.toolkit.*; -import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.query.interfaces.MPJJoin; import com.github.yulichang.toolkit.Constant; import com.github.yulichang.toolkit.MPJWrappers; @@ -64,7 +63,7 @@ public class MPJQueryWrapper extends AbstractWrapper wrapper = new MPJLambdaWrapper() - .disableSubLogicDel() - .disableLogicDel() +// .disableSubLogicDel() +// .disableLogicDel() .selectAll(UserDO.class) .selectCollection(UserDO.class, UserDO::getChildren) .leftJoin(UserDO.class, UserDO::getPid, UserDO::getId); diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/QueryWrapperTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/QueryWrapperTest.java index 2e02e1c..8a62eba 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/QueryWrapperTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/QueryWrapperTest.java @@ -23,8 +23,16 @@ class QueryWrapperTest { */ @Test void test1() { - UserDO userDO = userMapper.selectJoinOne(UserDO.class, new MPJQueryWrapper() - .selectAll(UserDO.class).last("LIMIT 1")); + MPJQueryWrapper last = new MPJQueryWrapper() + .disableLogicDel() + .selectAll(UserDO.class) + .eq("t.id", 1) + .last("LIMIT 1"); + System.out.println(last.getSqlSegment()); + System.out.println(last.isEmptyOfNormal()); + System.out.println(last.nonEmptyOfNormal()); + UserDO userDO = userMapper.selectJoinOne(UserDO.class, last); + System.out.println(userDO); UserDTO dto = userMapper.selectJoinOne(UserDTO.class, new MPJQueryWrapper()