From ba617e7c82822333dc6e1426aa267b6959f596ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Mon, 31 Jul 2023 15:00:19 +0800 Subject: [PATCH] doc: update docs --- docs/zh/core/logic-delete.md | 6 +++--- .../java/com/mybatisflex/test/AccountTester.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/zh/core/logic-delete.md b/docs/zh/core/logic-delete.md index 6994d313..9b243248 100644 --- a/docs/zh/core/logic-delete.md +++ b/docs/zh/core/logic-delete.md @@ -70,12 +70,12 @@ QueryWrapper query1 = QueryWrapper.create() ```sql SELECT * FROM `tb_account` - LEFT JOIN `tb_article` AS `a` ON `tb_account`.`id` = `a`.`account_id` + LEFT JOIN `tb_article` AS `a` + ON `a`.`is_delete` = 0 and `tb_account`.`id` = `a`.`account_id` WHERE `tb_account`.`age` >= 10 AND `tb_account`.`is_delete` = 0 - AND `a`.`is_delete` = 0 ``` -自动添加上 `tb_account.is_delete = 0 AND a.is_delete = 0` 条件。 +在 `left join on` 条件自动添加:`a.is_delete = 0`,并在 where 条件添加上 `tb_account.is_delete = 0`。 示例 2: diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java index 5c5601eb..0987ddae 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java @@ -25,6 +25,7 @@ import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.DbChain; import com.mybatisflex.core.update.UpdateWrapper; import com.mybatisflex.core.util.UpdateEntity; +import com.mybatisflex.mapper.ArticleMapper; import org.apache.ibatis.logging.stdout.StdOutImpl; import org.junit.BeforeClass; import org.junit.Test; @@ -35,11 +36,13 @@ import javax.sql.DataSource; import java.util.List; import static com.mybatisflex.test.table.AccountTableDef.ACCOUNT; +import static com.mybatisflex.test.table.ArticleTableDef.ARTICLE; public class AccountTester { static AccountMapper accountMapper; + static ArticleMapper articleMapper; @BeforeClass public static void init() { @@ -53,6 +56,7 @@ public class AccountTester { .setDataSource(dataSource) .setLogImpl(StdOutImpl.class) .addMapper(AccountMapper.class) + .addMapper(ArticleMapper.class) .start(); //开启审计功能 @@ -64,6 +68,7 @@ public class AccountTester { accountMapper = bootstrap.getMapper(AccountMapper.class); + articleMapper = bootstrap.getMapper(ArticleMapper.class); } @Test @@ -101,6 +106,16 @@ public class AccountTester { System.out.println(accounts); } + @Test + public void testLeftJoinForLogicDelete() { + QueryWrapper queryWrapper = QueryWrapper.create(); + queryWrapper.from(ARTICLE) + .leftJoin(ACCOUNT).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID)) + .where(ARTICLE.ID.ge(1)); + List
accounts = articleMapper.selectListByQuery(queryWrapper); + System.out.println(accounts); + } + @Test public void testSelectAsToDTO() {