From 629101a774da71e2846984e875c61700c6df75d2 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Fri, 31 May 2024 08:52:15 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/yulichang/test/util/EnabledIf.java | 15 +++ .../com/github/yulichang/test/util/Reset.java | 1 + .../com/github/yulichang/test/util/Throw.java | 38 ------ .../test/join/LambdaWrapperTest.java | 122 +++--------------- .../yulichang/test/join/QueryWrapperTest.java | 46 ++----- .../test/join/mysql/DeleteJoinTest.java | 56 ++++++++ .../MysqlTest.java} | 31 ++++- .../UpdateJoinTest.java} | 43 ++++-- .../test/join/{m => unit}/ApplyFuncTest.java | 2 +- .../test/join/{m => unit}/AroundTest.java | 2 +- .../join/{m => unit}/ChineseFieldTest.java | 2 +- .../join/{m => unit}/CustomWrapperTest.java | 2 +- .../test/join/{m => unit}/EqSqlTest.java | 10 +- .../test/join/{m => unit}/FieldAliasTest.java | 2 +- .../test/join/{m => unit}/FieldNameTest.java | 2 +- .../test/join/{m => unit}/IfExistsTest.java | 5 +- .../{m => unit}/NotLikeLeftRightTest.java | 2 +- .../test/join/{m => unit}/OrderByTest.java | 4 +- .../test/join/{m => unit}/SelectSubTest.java | 4 +- .../join/{m => unit}/StringColumTest.java | 7 +- .../test/join/{m => unit}/TableAliasTest.java | 4 +- .../test/join/{m => unit}/UnionTest.java | 2 +- 22 files changed, 187 insertions(+), 215 deletions(-) create mode 100644 mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/EnabledIf.java delete mode 100644 mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/Throw.java create mode 100644 mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/DeleteJoinTest.java rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m/FuncAliasTest.java => mysql/MysqlTest.java} (67%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m/UpdateIncTest.java => mysql/UpdateJoinTest.java} (54%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/ApplyFuncTest.java (97%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/AroundTest.java (95%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/ChineseFieldTest.java (91%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/CustomWrapperTest.java (98%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/EqSqlTest.java (86%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/FieldAliasTest.java (97%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/FieldNameTest.java (96%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/IfExistsTest.java (94%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/NotLikeLeftRightTest.java (97%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/OrderByTest.java (93%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/SelectSubTest.java (94%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/StringColumTest.java (94%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/TableAliasTest.java (96%) rename mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/{m => unit}/UnionTest.java (98%) diff --git a/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/EnabledIf.java b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/EnabledIf.java new file mode 100644 index 0000000..bfddbbf --- /dev/null +++ b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/EnabledIf.java @@ -0,0 +1,15 @@ +package com.github.yulichang.test.util; + +import com.baomidou.mybatisplus.annotation.DbType; + +@SuppressWarnings("unused") +public class EnabledIf { + + public static boolean runWithMysql() { + return DbTypeUtil.getDbType() == DbType.MYSQL; + } + + public static boolean runWithExcludingOracle() { + return DbTypeUtil.getDbType() != DbType.ORACLE; + } +} diff --git a/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/Reset.java b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/Reset.java index ee798d1..cbc9219 100644 --- a/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/Reset.java +++ b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/Reset.java @@ -16,6 +16,7 @@ public class Reset { @SuppressWarnings({"DataFlowIssue"}) public static void reset() { + ThreadLocalUtils.set(""); SqlSession session = SpringContentUtils.getBean(SqlSessionTemplate.class) .getSqlSessionFactory().openSession(true); Connection connection = session.getConnection(); diff --git a/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/Throw.java b/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/Throw.java deleted file mode 100644 index e125712..0000000 --- a/mybatis-plus-join-test/test-base/src/main/java/com/github/yulichang/test/util/Throw.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.yulichang.test.util; - -import com.baomidou.mybatisplus.annotation.DbType; -import com.github.yulichang.wrapper.interfaces.DoSomething; -import org.springframework.jdbc.BadSqlGrammarException; - -import java.util.Arrays; - -public class Throw { - - - public static void tryDo(DoSomething doSomething) { - try { - doSomething.doIt(); - } catch (BadSqlGrammarException e) { - if (DbTypeUtil.getDbType() != DbType.H2) { - throw e; - } - } - } - - public static void tryDo(DoSomething doSomething, DbType... ignore) { - try { - doSomething.doIt(); - } catch (BadSqlGrammarException e) { - if (DbTypeUtil.getDbType() != DbType.H2 && Arrays.stream(ignore).noneMatch(n -> n == DbTypeUtil.getDbType())) { - throw e; - } - } - } - - public static void tryDoIgnore(DoSomething doSomething) { - try { - doSomething.doIt(); - } catch (BadSqlGrammarException ignore) { - } - } -} diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java index 17a68ab..e6038c6 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java @@ -1,6 +1,5 @@ package com.github.yulichang.test.join; -import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.MybatisPlusVersion; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -15,18 +14,16 @@ import com.github.yulichang.test.join.entity.*; import com.github.yulichang.test.join.mapper.*; import com.github.yulichang.test.util.Reset; import com.github.yulichang.test.util.ThreadLocalUtils; -import com.github.yulichang.test.util.Throw; import com.github.yulichang.toolkit.JoinWrappers; -import com.github.yulichang.wrapper.DeleteJoinWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; -import com.github.yulichang.wrapper.UpdateJoinWrapper; +import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.BadSqlGrammarException; import java.sql.Timestamp; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -656,7 +653,11 @@ class LambdaWrapperTest { "WHERE t.del = false\n" + " AND t1.del = false\n" + " AND (t.id = ? AND (t.head_img = ? OR t1.user_id = ?) AND t.id = ?)\n" + - "LIMIT ?"); + "LIMIT ?", + "SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( 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, t1.address FROM `user` t " + + "LEFT JOIN address t1 ON (t.id = t1.user_id AND t.id = t1.user_id) WHERE t.del = false AND t1.del = false AND " + + "(t.id = ? AND (t.head_img = ? OR t1.user_id = ?) AND t.id = ?) ) TMP WHERE ROWNUM <=?) WHERE ROW_ID > ?"); IPage page = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class, JoinWrappers.lambda() .selectAll(UserDO.class) @@ -684,38 +685,17 @@ class LambdaWrapperTest { System.out.println(one); } - /** * 忽略个别查询字段 */ @Test - void test6() { - MPJLambdaWrapper wrapper = new MPJLambdaWrapper() - .selectAll(UserDO.class) - .selectFilter(AddressDO.class, p -> true) - .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) - .eq(UserDO::getId, 1); - IPage page = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class, wrapper); - assert page.getRecords().get(0).getAddress() != null; - page.getRecords().forEach(System.out::println); - } - - /** - * 忽略个别查询字段 - */ - @Test - void test8() { + @SneakyThrows + void test8() throws BadSqlGrammarException { ThreadLocalUtils.set("SELECT t.`name` FROM `user` t WHERE t.del=false AND (t.`name` = ?)"); MPJLambdaWrapper wrapper = new MPJLambdaWrapper() .select(UserDO::getName) .eq(UserDO::getName, "ref"); userMapper.selectList(wrapper); - Throw.tryDo(() -> { - userMapper.insertBatchSomeColumn(new ArrayList() {{ - add(new UserDO()); - }}); - }); - } @@ -752,21 +732,6 @@ class LambdaWrapperTest { assert dos1.size() == 4; } - /** - * 函数测试 - */ - @Test - void testFunc() { - ThreadLocalUtils.set("SELECT if(t1.user_id < 5,t1.user_id,t1.user_id + 100) AS id FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del=false AND t1.del=false"); - MPJLambdaWrapper wrapper = new MPJLambdaWrapper() - .selectFunc("if(%s < 5,%s,%s + 100)", arg -> arg.accept(AddressDO::getUserId, AddressDO::getUserId, AddressDO::getUserId), UserDO::getId) - .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId); - - Throw.tryDo(() -> { - List dos = userMapper.selectJoinList(UserDO.class, wrapper); - },DbType.ORACLE); - } - /** * 泛型测试 */ @@ -808,20 +773,20 @@ class LambdaWrapperTest { */ @Test void testTable() { - ThreadLocalUtils.set("SELECT t.id FROM bbbbbbb t LEFT JOIN addressaaaaaaaaaa t1 ON (t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) WHERE t.del=false AND t1.del=false AND t2.del=false AND (t.id <= ?) ORDER BY t.id DESC"); + ThreadLocalUtils.set("SELECT t.id FROM (SELECT * FROM `user`) t LEFT JOIN (SELECT * FROM address) t1 ON " + + "(t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) WHERE t.del = false AND t1.del = false " + + "AND t2.del = false AND (t.id <= ?) ORDER BY t.id DESC"); MPJLambdaWrapper wrapper = new MPJLambdaWrapper() .select(UserDO::getId) .leftJoin(AddressDO.class, on -> on .eq(AddressDO::getUserId, UserDO::getId) - .setTableName(name -> name + "aaaaaaaaaa")) + .setTableName(name -> String.format("(select * from %s)", name))) .leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId) .le(UserDO::getId, 10000) .orderByDesc(UserDO::getId) - .setTableName(name -> "bbbbbbb"); + .setTableName(name -> String.format("(select * from %s)", name)); - Throw.tryDoIgnore(() -> { - List list = userMapper.selectJoinList(UserDTO.class, wrapper); - }); + List list = userMapper.selectJoinList(UserDTO.class, wrapper); } @@ -1020,63 +985,6 @@ class LambdaWrapperTest { List l = w.list(); } - /** - * 同一个类字段比较 - */ - @Test - void delete() { - //物理删除 - ThreadLocalUtils.set("DELETE t FROM order_t t LEFT JOIN user_dto t1 ON (t1.id = t.user_id) WHERE (t.id = ?)"); - DeleteJoinWrapper w = JoinWrappers.delete(OrderDO.class) - .leftJoin(UserDto.class, UserDto::getId, OrderDO::getUserId) - .eq(OrderDO::getId, 1); - Throw.tryDo(() -> { - int i = orderMapper.deleteJoin(w); - }); - //忽略异常 h2不支持连表删除 - //逻辑删除 - ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) SET t.del=true ,t1.del=true,t2.del=true WHERE t.del=false AND t1.del=false AND t2.del=false AND (t.id = ?)"); - DeleteJoinWrapper wrapper = JoinWrappers.delete(UserDO.class) - .deleteAll() - .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) - .leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId) - .eq(OrderDO::getId, 1); - Throw.tryDo(() -> { - DeleteJoinWrapper wrapper1 = new DeleteJoinWrapper<>(UserDO.class); - int i = userMapper.deleteJoin(wrapper); - }); - //忽略异常 h2不支持连表删除 - } - - @Test - void update() { - ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.update_by=?, t.`name`=?,t1.address=?,t1.tel=?,t1.address=?,t.`name`=?,t.update_by=?,t1.user_id=?,t1.area_id=?,t1.tel=?,t1.address=? WHERE t.del=false AND t1.del=false AND (t.id = ?)"); - UpdateJoinWrapper update = JoinWrappers.update(UserDO.class) - .set(UserDO::getName, "aaaaaa") - .set(AddressDO::getAddress, "bbbbb") - .setUpdateEntity(new AddressDO().setAddress("sadf").setTel("qqqqqqqq"), - new UserDO().setName("nnnnnnnnnnnn").setUpdateBy(1)) - .setUpdateEntityAndNull(new AddressDO()) - .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) - .eq(OrderDO::getId, 1); - System.out.println(update.getSqlSet()); - Throw.tryDo(() -> { - int i = userMapper.updateJoin(new UserDO().setUpdateBy(123123), update); - }); - //忽略异常 h2不支持连表删除 - - ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.pid=?, " + - "t.`name`=?, t.`json`=?, t.sex=?, t.head_img=?, t.create_time=?, t.address_id=?, t.address_id2=?, " + - "t.create_by=?, t.update_by=? WHERE t.del=false AND t1.del=false AND (t.id = ?)"); - - UpdateJoinWrapper up = JoinWrappers.update(UserDO.class) - .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) - .eq(OrderDO::getId, 1); - Throw.tryDo(() -> { - int i = userMapper.updateJoinAndNull(new UserDO(), up); - }); - } - /** * select 子查询 */ 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 262a789..f4487a0 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 @@ -8,9 +8,9 @@ import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.join.entity.UserTenantDO; import com.github.yulichang.test.join.mapper.UserMapper; import com.github.yulichang.test.join.mapper.UserTenantMapper; +import com.github.yulichang.test.util.Reset; import com.github.yulichang.test.util.ThreadLocalUtils; -import com.github.yulichang.test.util.Throw; -import com.github.yulichang.toolkit.JoinWrappers; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -27,26 +27,9 @@ class QueryWrapperTest { private UserTenantMapper userTenantMapper; - /** - * 链表查询 - */ - @Test - void test1() { - UserDTO dto = userMapper.selectJoinOne(UserDTO.class, new MPJQueryWrapper() - .selectAll(UserDO.class) - .select("name AS nameName") - .last("LIMIT 1")); - System.out.println(dto); - - - IPage iPage1 = userTenantMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class, - JoinWrappers.query(UserTenantDO.class) - .selectAll(UserTenantDO.class) - .select("t1.name as PName") - .leftJoin("(select * from `user` where id <> -1) t1 on t1.id = t.user_id") - .apply("t.id <> -1")); - - iPage1.getRecords().forEach(System.out::println); + @BeforeEach + void setUp() { + Reset.reset(); } /** @@ -54,17 +37,16 @@ class QueryWrapperTest { */ @Test void table() { - 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,name AS nameName FROM fwear t WHERE t.del=false LIMIT 1", - "SELECT t.id,t.pid,t.`name`,t.`json`,t.sex,t.head_img AS img,t.create_time,t.address_id,t.address_id2,t.del,t.create_by,t.update_by,name AS nameName FROM fwear t WHERE t.del=false LIMIT 1"); + 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, `name` AS nameName FROM (SELECT * FROM `user`) t " + + "WHERE t.del = false AND t.id = 1"); MPJQueryWrapper wrapper = new MPJQueryWrapper() .selectAll(UserDO.class) - .setTableName(name -> "fwear") - .select("name AS nameName") - .last("LIMIT 1"); + .setTableName(name -> String.format("(select * from %s)", name)) + .select("`name` AS nameName") + .last("AND t.id = 1"); - Throw.tryDoIgnore(() -> { - userMapper.selectJoinOne(UserDTO.class, wrapper); - }); + userMapper.selectJoinOne(UserDTO.class, wrapper); } @Test @@ -72,14 +54,14 @@ class QueryWrapperTest { List userDO = userMapper.selectJoinList(UserDO.class, new MPJQueryWrapper() .selectAll(UserDO.class) .leftJoin("address t2 on t2.user_id = t.id") - .le("t.id ", 10)); + .le("t.id", 10)); System.out.println(userDO); List dto = userMapper.selectJoinList(UserDTO.class, new MPJQueryWrapper() .selectAll(UserDO.class) .select("t2.address AS userAddress") .leftJoin("address t2 on t2.user_id = t.id") - .le("t.id ", 10)); + .le("t.id", 10)); System.out.println(dto); } diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/DeleteJoinTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/DeleteJoinTest.java new file mode 100644 index 0000000..1953dc2 --- /dev/null +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/DeleteJoinTest.java @@ -0,0 +1,56 @@ +package com.github.yulichang.test.join.mysql; + +import com.github.yulichang.test.join.entity.*; +import com.github.yulichang.test.join.mapper.OrderMapper; +import com.github.yulichang.test.join.mapper.UserMapper; +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.DeleteJoinWrapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIf; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +/** + * 连表删除没有同意语法语法,不同数据库差别较大 + * MPJ 连表更新 目前只支持 mysql + */ +@SpringBootTest +@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithMysql") +public class DeleteJoinTest { + + @Autowired + private UserMapper userMapper; + @Autowired + private OrderMapper orderMapper; + + @BeforeEach + void setUp() { + Reset.reset(); + } + + /** + * 同一个类字段比较 + */ + @Test + void delete() { + //物理删除 + ThreadLocalUtils.set("DELETE t FROM order_t t LEFT JOIN user_dto t1 ON (t1.id = t.user_id) WHERE (t.id = ?)"); + DeleteJoinWrapper w = JoinWrappers.delete(OrderDO.class) + .leftJoin(UserDto.class, UserDto::getId, OrderDO::getUserId) + .eq(OrderDO::getId, 1); + + orderMapper.deleteJoin(w); + + //逻辑删除 + ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) LEFT JOIN area t2 ON (t2.id = t1.area_id) SET t.del=true ,t1.del=true,t2.del=true WHERE t.del=false AND t1.del=false AND t2.del=false AND (t.id = ?)"); + DeleteJoinWrapper wrapper = JoinWrappers.delete(UserDO.class) + .deleteAll() + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) + .leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId) + .eq(OrderDO::getId, 1); + userMapper.deleteJoin(wrapper); + } +} diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FuncAliasTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/MysqlTest.java similarity index 67% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FuncAliasTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/MysqlTest.java index e79749d..62c6b4c 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FuncAliasTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/MysqlTest.java @@ -1,21 +1,26 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.mysql; -import com.baomidou.mybatisplus.annotation.DbType; import com.github.yulichang.test.join.entity.AddressDO; import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.join.mapper.UserMapper; import com.github.yulichang.test.util.Reset; import com.github.yulichang.test.util.ThreadLocalUtils; -import com.github.yulichang.test.util.Throw; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.segments.Fun; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIf; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +/** + * 由于不同数据库函数支持情况不同 + * 此类用于测试 mysql 专属语法或函数 + */ @SpringBootTest -public class FuncAliasTest { +@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithMysql") +public class MysqlTest { + @Autowired private UserMapper userMapper; @@ -24,6 +29,19 @@ public class FuncAliasTest { Reset.reset(); } + + /** + * 函数测试 + */ + @Test + void testFunc() { + ThreadLocalUtils.set("SELECT if(t1.user_id < 5,t1.user_id,t1.user_id + 100) AS id FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del=false AND t1.del=false"); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + .selectFunc("if(%s < 5,%s,%s + 100)", arg -> arg.accept(AddressDO::getUserId, AddressDO::getUserId, AddressDO::getUserId), UserDO::getId) + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId); + userMapper.selectJoinList(UserDO.class, wrapper); + } + @Test void funcAlias() { ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " + @@ -43,8 +61,7 @@ public class FuncAliasTest { .leftJoin(AddressDO.class, "addr", AddressDO::getUserId, UserDO::getId) .groupBy(UserDO::getId); - Throw.tryDo(() -> { - userMapper.selectJoinList(UserDO.class, wrapper); - }, DbType.POSTGRE_SQL, DbType.ORACLE); + userMapper.selectJoinList(UserDO.class, wrapper); } + } diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/UpdateIncTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/UpdateJoinTest.java similarity index 54% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/UpdateIncTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/UpdateJoinTest.java index f12d8f4..3901428 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/UpdateIncTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/mysql/UpdateJoinTest.java @@ -1,25 +1,31 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.mysql; import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy; import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper; import com.github.yulichang.test.join.entity.AddressDO; +import com.github.yulichang.test.join.entity.OrderDO; import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.join.mapper.UserMapper; import com.github.yulichang.test.util.Reset; import com.github.yulichang.test.util.ThreadLocalUtils; -import com.github.yulichang.test.util.Throw; import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.wrapper.UpdateJoinWrapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIf; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.util.HashMap; import java.util.List; +/** + * 连表更新没有同意语法语法,不同数据库差别较大 + * MPJ 连表更新 目前只支持 mysql + */ @SpringBootTest -public class UpdateIncTest { +@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithMysql") +public class UpdateJoinTest { @Autowired private UserMapper userMapper; @@ -29,7 +35,6 @@ public class UpdateIncTest { Reset.reset(); } - @Test void updateInc() { ThreadLocalUtils.set("UPDATE `user` t SET t.id = t.id + 100 WHERE t.del = false"); @@ -47,10 +52,8 @@ public class UpdateIncTest { @Test void updateInc1() { ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t1.address = t.head_img WHERE t.del = false AND t1.del = false"); - Throw.tryDo(() -> { - JoinWrappers.update(UserDO.class).set(AddressDO::getAddress, UserDO::getImg) - .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).update(); - }); + JoinWrappers.update(UserDO.class).set(AddressDO::getAddress, UserDO::getImg) + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId).update(); JoinWrappers.lambda(UserDO.class).list().forEach(System.out::println); } @@ -78,4 +81,28 @@ public class UpdateIncTest { }); } + + @Test + void update() { + ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.update_by=?, t.`name`=?,t1.address=?,t1.tel=?,t1.address=?,t.`name`=?,t.update_by=?,t1.user_id=?,t1.area_id=?,t1.tel=?,t1.address=? WHERE t.del=false AND t1.del=false AND (t.id = ?)"); + UpdateJoinWrapper update = JoinWrappers.update(UserDO.class) + .set(UserDO::getName, "aaaaaa") + .set(AddressDO::getAddress, "bbbbb") + .setUpdateEntity(new AddressDO().setAddress("sadf").setTel("qqqqqqqq"), + new UserDO().setName("nnnnnnnnnnnn").setUpdateBy(1)) + .setUpdateEntityAndNull(new AddressDO()) + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) + .eq(OrderDO::getId, 1); + System.out.println(update.getSqlSet()); + userMapper.updateJoin(new UserDO().setUpdateBy(123123), update); + + ThreadLocalUtils.set("UPDATE `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) SET t.pid=?, " + + "t.`name`=?, t.`json`=?, t.sex=?, t.head_img=?, t.create_time=?, t.address_id=?, t.address_id2=?, " + + "t.create_by=?, t.update_by=? WHERE t.del=false AND t1.del=false AND (t.id = ?)"); + + UpdateJoinWrapper up = JoinWrappers.update(UserDO.class) + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) + .eq(OrderDO::getId, 1); + userMapper.updateJoinAndNull(new UserDO(), up); + } } diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/ApplyFuncTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ApplyFuncTest.java similarity index 97% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/ApplyFuncTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ApplyFuncTest.java index cfdb4bc..1b02ca2 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/ApplyFuncTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ApplyFuncTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.entity.AddressDO; import com.github.yulichang.test.join.entity.UserDO; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/AroundTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/AroundTest.java similarity index 95% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/AroundTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/AroundTest.java index 32ac2f8..96e273c 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/AroundTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/AroundTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.util.Reset; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/ChineseFieldTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ChineseFieldTest.java similarity index 91% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/ChineseFieldTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ChineseFieldTest.java index f3265ad..d8b329f 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/ChineseFieldTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ChineseFieldTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.entity.UserTenantaDO; import com.github.yulichang.toolkit.JoinWrappers; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/CustomWrapperTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/CustomWrapperTest.java similarity index 98% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/CustomWrapperTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/CustomWrapperTest.java index 6a313b1..e853857 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/CustomWrapperTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/CustomWrapperTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.github.yulichang.test.join.entity.UserDO; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/EqSqlTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/EqSqlTest.java similarity index 86% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/EqSqlTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/EqSqlTest.java index eec0b25..242edec 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/EqSqlTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/EqSqlTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.util.Reset; @@ -20,12 +20,12 @@ public class EqSqlTest { @Test void eqSql() { 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 = (SELECT id FROM `user` LIMIT 1))"); - JoinWrappers.lambda(UserDO.class).eqSql(UserDO::getId, "select id from `user` limit 1").list(); + "t.address_id2, t.del, t.create_by, t.update_by FROM `user` t WHERE t.del = false AND (t.id = (SELECT id FROM `user` WHERE id = 1))"); + JoinWrappers.lambda(UserDO.class).eqSql(UserDO::getId, "select id from `user` where id = 1").list(); 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 = (SELECT id FROM `user` LIMIT 1))"); - JoinWrappers.lambda(UserDO.class).eqSql("t.id", "select id from `user` limit 1").list(); + "t.address_id2, t.del, t.create_by, t.update_by FROM `user` t WHERE t.del = false AND (t.id = (SELECT id FROM `user` WHERE id = 1))"); + JoinWrappers.lambda(UserDO.class).eqSql("t.id", "select id from `user` where id = 1").list(); } } diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FieldAliasTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/FieldAliasTest.java similarity index 97% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FieldAliasTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/FieldAliasTest.java index 515f366..561dedb 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FieldAliasTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/FieldAliasTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.github.yulichang.test.join.entity.AddressDO; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FieldNameTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/FieldNameTest.java similarity index 96% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FieldNameTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/FieldNameTest.java index 1ac9467..0bf9edb 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FieldNameTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/FieldNameTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.dto.AreaDTO; import com.github.yulichang.test.join.entity.AreaDO; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/IfExistsTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/IfExistsTest.java similarity index 94% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/IfExistsTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/IfExistsTest.java index 0c1d97b..358d4af 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/IfExistsTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/IfExistsTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.config.enums.IfExistsEnum; import com.github.yulichang.test.join.entity.UserDO; @@ -69,12 +69,11 @@ public class IfExistsTest { 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` = ?)"); + "WHERE t.del = false AND (t.id = ? AND t.`name` = ? AND t.head_img = ? AND t.`name` = ?)"); MPJLambdaWrapper wrapper2 = JoinWrappers.lambda(UserDO.class) .selectAll(UserDO.class) .setIfExists(o -> true) .eqIfExists(UserDO::getId, 1) - .eqIfExists(UserDO::getPid, null) .eqIfExists(UserDO::getName, "") .eqIfExists(UserDO::getImg, "\t") .eqIfExists(UserDO::getName, "张三 1"); diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/NotLikeLeftRightTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/NotLikeLeftRightTest.java similarity index 97% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/NotLikeLeftRightTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/NotLikeLeftRightTest.java index a396366..9416b50 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/NotLikeLeftRightTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/NotLikeLeftRightTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.util.Reset; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/OrderByTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/OrderByTest.java similarity index 93% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/OrderByTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/OrderByTest.java index 4cfbeb9..035dd05 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/OrderByTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/OrderByTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.github.yulichang.test.join.dto.UserDTO; @@ -10,12 +10,14 @@ 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.junit.jupiter.api.condition.EnabledIf; import org.springframework.boot.test.context.SpringBootTest; import java.util.Arrays; import java.util.List; @SpringBootTest +@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithExcludingOracle") public class OrderByTest { @BeforeEach diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/SelectSubTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/SelectSubTest.java similarity index 94% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/SelectSubTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/SelectSubTest.java index 2563629..6b5fe4f 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/SelectSubTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/SelectSubTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.entity.AddressDO; import com.github.yulichang.test.join.entity.AreaDO; @@ -9,9 +9,11 @@ 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.junit.jupiter.api.condition.EnabledIf; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest +@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithExcludingOracle") public class SelectSubTest { @BeforeEach diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/StringColumTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/StringColumTest.java similarity index 94% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/StringColumTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/StringColumTest.java index aa00c34..2fa54ca 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/StringColumTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/StringColumTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.dto.UserDTO; import com.github.yulichang.test.join.entity.AddressDO; @@ -32,7 +32,7 @@ public class StringColumTest { void stringColum() { ThreadLocalUtils.set("SELECT (SELECT id FROM `user` u WHERE u.id = t.id) id, t.`name` AS PName, t.`name` PName, t.`name`," + " (SELECT id FROM `user` u WHERE u.id = t.id), t1.id AS joina_id, t1.user_id, t1.area_id, t1.tel, " + - "t1.address, t1.del FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del = false AND t1.del = false LIMIT 1"); + "t1.address, t1.del FROM `user` t LEFT JOIN address t1 ON (t1.user_id = t.id) WHERE t.del = false AND t1.del = false"); List l3 = userMapper.selectJoinList(UserDTO.class, new MPJLambdaWrapper() .select("(select id from `user` u where u.id = t.id) id") .select("t.`name` as PName") @@ -40,8 +40,7 @@ public class StringColumTest { .select("t.`name`") .select("(select id from `user` u where u.id = t.id) ") .selectAssociation(AddressDO.class, UserDTO::getAddressDTO) - .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) - .last("limit 1")); + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)); assert l3.get(0).getPName() != null; l3.forEach(System.out::println); } diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/TableAliasTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/TableAliasTest.java similarity index 96% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/TableAliasTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/TableAliasTest.java index a14d5e1..3a09d6e 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/TableAliasTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/TableAliasTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.entity.AddressDO; import com.github.yulichang.test.join.entity.AreaDO; @@ -10,12 +10,14 @@ 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.junit.jupiter.api.condition.EnabledIf; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.util.List; @SpringBootTest +@EnabledIf("com.github.yulichang.test.util.EnabledIf#runWithExcludingOracle") public class TableAliasTest { @Autowired private UserMapper userMapper; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/UnionTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/UnionTest.java similarity index 98% rename from mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/UnionTest.java rename to mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/UnionTest.java index cc968aa..7991c37 100644 --- a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/UnionTest.java +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/UnionTest.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.join.m; +package com.github.yulichang.test.join.unit; import com.github.yulichang.test.join.entity.AddressDO; import com.github.yulichang.test.join.entity.AreaDO;