diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java index 23f7bfd..c1fad5e 100644 --- a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java +++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java @@ -94,7 +94,7 @@ public class MybatisPlusJoinAutoConfiguration { } /** - * springboot content 工具类 + * springboot context 工具类 */ @Bean @Order(Ordered.HIGHEST_PRECEDENCE) diff --git a/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 9c7186d..05f30f3 100644 --- a/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -3,7 +3,8 @@ { "sourceType": "com.github.yulichang.autoconfigure.MybatisPlusJoinProperties", "name": "mybatis-plus-join", - "type": "com.github.yulichang.autoconfigure.MybatisPlusJoinProperties" + "type": "com.github.yulichang.autoconfigure.MybatisPlusJoinProperties", + "description": "mybatis-plus-join configure." } ], "properties": [ @@ -43,5 +44,20 @@ "type": "java.lang.String", "description": "逻辑删除的位置支持where和on两个." } + ], + "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." + } + ] + } ] } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Chain.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Chain.java index 8875483..7b312a6 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Chain.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Chain.java @@ -10,7 +10,7 @@ import java.util.List; /** * 链式调用 - * 构造方法不须传 class 或 entity 否则会报错 + * 构造方法必须传 class 或 entity 否则会报错 * new MPJLambdaWrapper(User.class) * new MPJQueryWrapper(User.class) * MPJWrappers.\lambdaJoin(User.class) @@ -27,7 +27,7 @@ public interface Chain { /** * 链式调用 等效于 selectOne *

- * 构造方法不须传 class 或 entity 否则会报错 + * 构造方法必须传 class 或 entity 否则会报错 * new MPJLambdaWrapper(User.class) * new MPJQueryWrapper(User.class) * MPJWrappers.\lambdaJoin(User.class) @@ -40,7 +40,7 @@ public interface Chain { /** * 链式调用 等效于 selectJoinOne *

- * 构造方法不须传 class 或 entity 否则会报错 + * 构造方法必须传 class 或 entity 否则会报错 * new MPJLambdaWrapper(User.class) * new MPJQueryWrapper(User.class) * MPJWrappers.\lambdaJoin(User.class) @@ -53,7 +53,7 @@ public interface Chain { /** * 链式调用 查询列表第一个 匹配多个不会抛异常 *

- * 构造方法不须传 class 或 entity 否则会报错 + * 构造方法必须传 class 或 entity 否则会报错 * new MPJLambdaWrapper(User.class) * new MPJQueryWrapper(User.class) * MPJWrappers.\lambdaJoin(User.class) @@ -67,7 +67,7 @@ public interface Chain { /** * 链式调用 查询列表第一个 匹配多个不会抛异常 *

- * 构造方法不须传 class 或 entity 否则会报错 + * 构造方法必须传 class 或 entity 否则会报错 * new MPJLambdaWrapper(User.class) * new MPJQueryWrapper(User.class) * MPJWrappers.\lambdaJoin(User.class) @@ -80,7 +80,7 @@ public interface Chain { /** * 链式调用 - * 构造方法不须传 class 或 entity 否则会报错 + * 构造方法必须传 class 或 entity 否则会报错 * new MPJLambdaWrapper(User.class) * new MPJQueryWrapper(User.class) * MPJWrappers.\lambdaJoin(User.class) @@ -92,7 +92,7 @@ public interface Chain { /** * 链式调用 - * 构造方法不须传 class 或 entity 否则会报错 + * 构造方法必须传 class 或 entity 否则会报错 * new MPJLambdaWrapper(User.class) * new MPJQueryWrapper(User.class) * MPJWrappers.\lambdaJoin(User.class) @@ -104,7 +104,7 @@ public interface Chain { /** * 链式调用 - * 构造方法不须传 class 或 entity 否则会报错 + * 构造方法必须传 class 或 entity 否则会报错 * new MPJLambdaWrapper(User.class) * new MPJQueryWrapper(User.class) * MPJWrappers.\lambdaJoin(User.class) @@ -116,7 +116,7 @@ public interface Chain { /** * 链式调用 - * 构造方法不须传 class 或 entity 否则会报错 + * 构造方法必须传 class 或 entity 否则会报错 * new MPJLambdaWrapper(User.class) * new MPJQueryWrapper(User.class) * MPJWrappers.\lambdaJoin(User.class) diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Label.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Label.java index df09c74..1ff86a0 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Label.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Label.java @@ -2,6 +2,12 @@ package com.github.yulichang.wrapper.resultmap; import java.util.List; +/** + * 映射标签 + * + * @author yulichang + * @since 2023/3/17 11:35 + */ public interface Label { String getProperty(); diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabelFree.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabelFree.java index 49bfeff..671a631 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabelFree.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabelFree.java @@ -1,9 +1,12 @@ package com.github.yulichang.wrapper.resultmap; +import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.toolkit.Assert; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.MPJReflectionKit; +import com.github.yulichang.toolkit.TableHelper; import com.github.yulichang.toolkit.support.ColumnCache; import com.github.yulichang.wrapper.segments.SelectCache; import lombok.Getter; @@ -222,6 +225,13 @@ public class MybatisLabelFree implements Label { } public MybatisLabelFree build() { + if (CollectionUtils.isEmpty(mybatisLabel.resultList)) { + TableInfo tableInfo = TableHelper.get(mybatisLabel.ofType); + Assert.notNull(tableInfo, + "无法自动映射, 找不到 <%s> 对应的表, 请使用 .all(xxx.class), id()或者result() 手动映射", + mybatisLabel.ofType.getSimpleName()); + all(mybatisLabel.ofType); + } return mybatisLabel; } diff --git a/mybatis-plus-join-test/test-collection/src/test/java/com/github/yulichang/test/collection/CollectionTest.java b/mybatis-plus-join-test/test-collection/src/test/java/com/github/yulichang/test/collection/CollectionTest.java index 86e9fb2..bb2560b 100644 --- a/mybatis-plus-join-test/test-collection/src/test/java/com/github/yulichang/test/collection/CollectionTest.java +++ b/mybatis-plus-join-test/test-collection/src/test/java/com/github/yulichang/test/collection/CollectionTest.java @@ -11,6 +11,7 @@ import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; import java.util.List; +import java.util.Objects; /** * 连表测试类 @@ -80,7 +81,7 @@ class CollectionTest { .leftJoin(TableE.class, TableE::getDid, TableD::getId) .last("LIMIT 1"); List dtos1 = tableAMapper.selectJoinList(TableADTO.class, wrapper1); - System.out.println(1); + assert dtos1.get(0).getB().getC().getD().getE().getId() != null; } /** @@ -97,4 +98,42 @@ class CollectionTest { List dtos = tableMapper.selectJoinList(TableDTO.class, wrapper); System.out.println(1); } + + @Test + void testFree(){ + MPJLambdaWrapper wrapper1 = new MPJLambdaWrapper() + .selectAll(TableA.class) + .selectAssociation(TableADTO::getB, b -> b + .all(TableB.class) + .association(TableC.class, TableBDTO::getC, c -> c + .association(TableD.class, TableCDTO::getD, d -> d + .association(TableE.class, TableDDTO::getE, e -> e + .id(TableE::getId))))) + .leftJoin(TableB.class, TableB::getAid, TableA::getId) + .leftJoin(TableC.class, TableC::getBid, TableB::getId) + .leftJoin(TableD.class, TableD::getCid, TableC::getId) + .leftJoin(TableE.class, TableE::getDid, TableD::getId) + .last("LIMIT 1"); + List dtos1 = tableAMapper.selectJoinList(TableADTO.class, wrapper1); + assert dtos1.get(0).getB().getC().getD().getE().getId() != null; + + + MPJLambdaWrapper wrapper2 = new MPJLambdaWrapper() + .selectAll(TableA.class) + .selectAssociation(TableADTO::getB, b -> b + .id(TableB::getId) + .result(TableD::getName,TableBDTO::getName) + .association(TableC.class, TableBDTO::getC, c -> c + .association(TableD.class, TableCDTO::getD, d -> d + .association(TableE.class, TableDDTO::getE, e -> e + .id(TableE::getId))))) + .leftJoin(TableB.class, TableB::getAid, TableA::getId) + .leftJoin(TableC.class, TableC::getBid, TableB::getId) + .leftJoin(TableD.class, TableD::getCid, TableC::getId) + .leftJoin(TableE.class, TableE::getDid, TableD::getId) + .last("LIMIT 1"); + List dtos2 = tableAMapper.selectJoinList(TableADTO.class, wrapper2); + assert dtos2.get(0).getB().getC().getD().getE().getId() != null; + assert Objects.equals(dtos2.get(0).getB().getName(), "tableD1"); + } } diff --git a/mybatis-plus-join-test/test-join/src/main/resources/application.yml b/mybatis-plus-join-test/test-join/src/main/resources/application.yml index e877eb1..e45e0cd 100644 --- a/mybatis-plus-join-test/test-join/src/main/resources/application.yml +++ b/mybatis-plus-join-test/test-join/src/main/resources/application.yml @@ -20,8 +20,9 @@ mybatis-plus: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl -# 打印 mybatis plus join banner mybatis-plus-join: + # 打印 mybatis plus join banner banner: true sub-table-logic: true - ms-cache: true \ No newline at end of file + ms-cache: true + logic-del-type: where \ No newline at end of file