From 86c33d152d4fca29075e3bfad25b7f9fac65c6c2 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Tue, 8 Nov 2022 20:05:31 +0800 Subject: [PATCH 01/23] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8C=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mybatis-plus-join-annotation/pom.xml | 41 ++++++++++ .../yulichang/annotation/EntityMapping.java | 1 + .../yulichang/annotation/FieldMapping.java | 1 + .../yulichang/annotation/MPJMappingApply.java | 1 + .../annotation/MPJMappingCondition.java | 1 + mybatis-plus-join-boot-starter/pom.xml | 49 +++++++++++ .../MybatisPlusJoinAutoConfiguration.java | 82 +++++++++++++++++++ .../MybatisPlusJoinProperties.java | 19 +++++ .../main/resources/META-INF/spring.factories | 2 + mybatis-plus-join-core/pom.xml | 49 +++++++++++ .../core/metadata/MPJTableInfoHelper.java | 0 .../github/yulichang/base/MPJBaseMapper.java | 0 .../github/yulichang/base/MPJBaseService.java | 0 .../yulichang/base/MPJBaseServiceImpl.java | 0 .../yulichang/base/mapper/MPJDeepMapper.java | 0 .../yulichang/base/mapper/MPJJoinMapper.java | 0 .../base/mapper/wrapper/MappingQuery.java | 0 .../base/service/MPJDeepService.java | 0 .../base/service/MPJJoinService.java | 0 .../yulichang/config/InterceptorConfig.java | 8 +- .../yulichang/config/MappingConfig.java | 6 +- .../yulichang/exception/MPJException.java | 0 .../yulichang/injector/MPJSqlInjector.java | 27 ++---- .../yulichang/interceptor/MPJInterceptor.java | 4 +- .../yulichang/interfaces/MPJBaseJoin.java | 0 .../yulichang/mapper/MPJMappingWrapper.java | 0 .../yulichang/mapper/MPJTableFieldInfo.java | 0 .../github/yulichang/mapper/MPJTableInfo.java | 0 .../mapper/MPJTableMapperHelper.java | 0 .../yulichang/method/MPJAbstractMethod.java | 0 .../yulichang/method/MPJBaseMethod.java | 0 .../yulichang/method/MPJResultType.java | 0 .../yulichang/method/SelectJoinCount.java | 0 .../yulichang/method/SelectJoinList.java | 0 .../yulichang/method/SelectJoinMap.java | 0 .../yulichang/method/SelectJoinMaps.java | 0 .../yulichang/method/SelectJoinMapsPage.java | 0 .../yulichang/method/SelectJoinOne.java | 0 .../yulichang/method/SelectJoinPage.java | 0 .../github/yulichang/method/SqlMethod.java | 0 .../yulichang/method/mp/SelectCount.java | 0 .../yulichang/method/mp/SelectList.java | 0 .../yulichang/method/mp/SelectMaps.java | 0 .../yulichang/method/mp/SelectMapsPage.java | 0 .../yulichang/method/mp/SelectObjs.java | 0 .../github/yulichang/method/mp/SelectOne.java | 0 .../yulichang/method/mp/SelectPage.java | 0 .../yulichang/method/mp/TableAlias.java | 0 .../query/MPJLambdaQueryWrapper.java | 0 .../yulichang/query/MPJQueryWrapper.java | 0 .../yulichang/query/interfaces/MPJJoin.java | 0 .../github/yulichang/toolkit/Constant.java | 0 .../yulichang/toolkit/InterceptorList.java | 0 .../github/yulichang/toolkit/LambdaUtils.java | 0 .../github/yulichang/toolkit/MPJWrappers.java | 0 .../yulichang/toolkit/ReflectionKit.java | 0 .../yulichang/toolkit/SpringContentUtils.java | 0 .../yulichang/toolkit/sql/SqlScriptUtils.java | 0 .../toolkit/support/ColumnCache.java | 0 .../toolkit/support/SelectColumn.java | 0 .../toolkit/support/SerializedLambda.java | 0 .../wrapper/MPJAbstractLambdaWrapper.java | 0 .../yulichang/wrapper/MPJAbstractWrapper.java | 0 .../yulichang/wrapper/MPJLambdaWrapper.java | 0 .../yulichang/wrapper/enums/BaseFuncEnum.java | 0 .../wrapper/enums/DefaultFuncEnum.java | 0 .../yulichang/wrapper/interfaces/Compare.java | 0 .../yulichang/wrapper/interfaces/Func.java | 0 .../yulichang/wrapper/interfaces/Join.java | 0 .../wrapper/interfaces/LambdaJoin.java | 0 .../yulichang/wrapper/interfaces/Query.java | 0 .../wrapper/interfaces/on/OnCompare.java | 0 .../wrapper/interfaces/on/OnFunction.java | 0 .../wrapper/resultmap/LabelType.java | 0 .../yulichang/wrapper/resultmap/MFunc.java | 0 .../wrapper/resultmap/MybatisLabel.java | 0 .../yulichang/wrapper/resultmap/Result.java | 0 mybatis-plus-join-test/pom.xml | 41 ++++++++++ .../main/java/com/github/yulichang/Main.java | 7 ++ pom.xml | 14 +++- src/main/resources/META-INF/spring.factories | 6 -- 81 files changed, 321 insertions(+), 38 deletions(-) create mode 100644 mybatis-plus-join-annotation/pom.xml rename {src => mybatis-plus-join-annotation/src}/main/java/com/github/yulichang/annotation/EntityMapping.java (99%) rename {src => mybatis-plus-join-annotation/src}/main/java/com/github/yulichang/annotation/FieldMapping.java (98%) rename {src => mybatis-plus-join-annotation/src}/main/java/com/github/yulichang/annotation/MPJMappingApply.java (92%) rename {src => mybatis-plus-join-annotation/src}/main/java/com/github/yulichang/annotation/MPJMappingCondition.java (95%) create mode 100644 mybatis-plus-join-boot-starter/pom.xml create mode 100644 mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java create mode 100644 mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java create mode 100644 mybatis-plus-join-boot-starter/src/main/resources/META-INF/spring.factories create mode 100644 mybatis-plus-join-core/pom.xml rename {src => mybatis-plus-join-core/src}/main/java/com/baomidou/mybatisplus/core/metadata/MPJTableInfoHelper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/base/MPJBaseMapper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/base/MPJBaseService.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/base/MPJBaseServiceImpl.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/base/mapper/MPJDeepMapper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/base/mapper/MPJJoinMapper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/base/mapper/wrapper/MappingQuery.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/base/service/MPJDeepService.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/base/service/MPJJoinService.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/config/InterceptorConfig.java (90%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/config/MappingConfig.java (86%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/exception/MPJException.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/injector/MPJSqlInjector.java (82%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/interceptor/MPJInterceptor.java (98%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/interfaces/MPJBaseJoin.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/mapper/MPJMappingWrapper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/mapper/MPJTableFieldInfo.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/mapper/MPJTableInfo.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/mapper/MPJTableMapperHelper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/MPJAbstractMethod.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/MPJBaseMethod.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/MPJResultType.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/SelectJoinCount.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/SelectJoinList.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/SelectJoinMap.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/SelectJoinMaps.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/SelectJoinMapsPage.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/SelectJoinOne.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/SelectJoinPage.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/SqlMethod.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/mp/SelectCount.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/mp/SelectList.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/mp/SelectMaps.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/mp/SelectMapsPage.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/mp/SelectObjs.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/mp/SelectOne.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/mp/SelectPage.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/method/mp/TableAlias.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/query/MPJLambdaQueryWrapper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/query/MPJQueryWrapper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/query/interfaces/MPJJoin.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/Constant.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/InterceptorList.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/LambdaUtils.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/MPJWrappers.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/ReflectionKit.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/SpringContentUtils.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/sql/SqlScriptUtils.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/support/ColumnCache.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/support/SelectColumn.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/toolkit/support/SerializedLambda.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/MPJAbstractLambdaWrapper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/MPJAbstractWrapper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/enums/BaseFuncEnum.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/enums/DefaultFuncEnum.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/interfaces/Compare.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/interfaces/Func.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/interfaces/Join.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/interfaces/LambdaJoin.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/interfaces/Query.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/interfaces/on/OnCompare.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/interfaces/on/OnFunction.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/resultmap/LabelType.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/resultmap/MFunc.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java (100%) rename {src => mybatis-plus-join-core/src}/main/java/com/github/yulichang/wrapper/resultmap/Result.java (100%) create mode 100644 mybatis-plus-join-test/pom.xml create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/Main.java delete mode 100644 src/main/resources/META-INF/spring.factories diff --git a/mybatis-plus-join-annotation/pom.xml b/mybatis-plus-join-annotation/pom.xml new file mode 100644 index 0000000..fe7ac02 --- /dev/null +++ b/mybatis-plus-join-annotation/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + com.github.yulichang + mybatis-plus-join-root + 1.3.0 + + mybatis-plus-join-annotation + mybatis-plus-join-annotation + + An enhanced toolkit of Mybatis-Plus to simplify development. + https://github.com/yulichang/mybatis-plus-join + + + The Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + mybatis-plus-join + yulichang + yu_lichang@qq.com + + + + scm:git:https://github.com/yulichang/mybatis-plus-join.git + scm:git:https://github.com/yulichang/mybatis-plus-join.git + https://github.com/yulichang/mybatis-plus-join + + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/src/main/java/com/github/yulichang/annotation/EntityMapping.java b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/EntityMapping.java similarity index 99% rename from src/main/java/com/github/yulichang/annotation/EntityMapping.java rename to mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/EntityMapping.java index 5d6ffdd..847cee2 100644 --- a/src/main/java/com/github/yulichang/annotation/EntityMapping.java +++ b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/EntityMapping.java @@ -10,6 +10,7 @@ import java.lang.annotation.*; * @since 1.2.0 */ @Documented +@SuppressWarnings("unused") @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) public @interface EntityMapping { diff --git a/src/main/java/com/github/yulichang/annotation/FieldMapping.java b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/FieldMapping.java similarity index 98% rename from src/main/java/com/github/yulichang/annotation/FieldMapping.java rename to mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/FieldMapping.java index a61c7db..5f310a0 100644 --- a/src/main/java/com/github/yulichang/annotation/FieldMapping.java +++ b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/FieldMapping.java @@ -10,6 +10,7 @@ import java.lang.annotation.*; * @since 1.2.0 */ @Documented +@SuppressWarnings("unused") @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) public @interface FieldMapping { diff --git a/src/main/java/com/github/yulichang/annotation/MPJMappingApply.java b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingApply.java similarity index 92% rename from src/main/java/com/github/yulichang/annotation/MPJMappingApply.java rename to mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingApply.java index 8784957..ded2e61 100644 --- a/src/main/java/com/github/yulichang/annotation/MPJMappingApply.java +++ b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingApply.java @@ -7,6 +7,7 @@ package com.github.yulichang.annotation; * @author yulichang * @since 1.2.0 */ +@SuppressWarnings("unused") public @interface MPJMappingApply { /** diff --git a/src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java similarity index 95% rename from src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java rename to mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java index da024a5..8c09726 100644 --- a/src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java +++ b/mybatis-plus-join-annotation/src/main/java/com/github/yulichang/annotation/MPJMappingCondition.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.enums.SqlKeyword; * @author yulichang * @since 1.2.0 */ +@SuppressWarnings("unused") public @interface MPJMappingCondition { /** diff --git a/mybatis-plus-join-boot-starter/pom.xml b/mybatis-plus-join-boot-starter/pom.xml new file mode 100644 index 0000000..50c222f --- /dev/null +++ b/mybatis-plus-join-boot-starter/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + com.github.yulichang + mybatis-plus-join-root + 1.3.0 + + mybatis-plus-join-boot-starter + mybatis-plus-join-boot-starter + + An enhanced toolkit of Mybatis-Plus to simplify development. + https://github.com/yulichang/mybatis-plus-join + + + The Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + mybatis-plus-join + yulichang + yu_lichang@qq.com + + + + scm:git:https://github.com/yulichang/mybatis-plus-join.git + scm:git:https://github.com/yulichang/mybatis-plus-join.git + https://github.com/yulichang/mybatis-plus-join + + + + 8 + 8 + UTF-8 + + + + + com.github.yulichang + mybatis-plus-join-core + 1.3.0 + + + + \ No newline at end of file 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 new file mode 100644 index 0000000..08f3a60 --- /dev/null +++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java @@ -0,0 +1,82 @@ +package com.github.yulichang.autoconfigure; + +import com.baomidou.mybatisplus.autoconfigure.MybatisPlusLanguageDriverAutoConfiguration; +import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector; +import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; +import com.baomidou.mybatisplus.core.injector.ISqlInjector; +import com.github.yulichang.config.InterceptorConfig; +import com.github.yulichang.config.MappingConfig; +import com.github.yulichang.injector.MPJSqlInjector; +import com.github.yulichang.interceptor.MPJInterceptor; +import com.github.yulichang.toolkit.SpringContentUtils; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; + +import javax.sql.DataSource; +import java.util.List; + +@SuppressWarnings("unused") +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class}) +@ConditionalOnSingleCandidate(DataSource.class) +@EnableConfigurationProperties(MybatisPlusJoinProperties.class) +@AutoConfigureAfter({DataSourceAutoConfiguration.class, MybatisPlusLanguageDriverAutoConfiguration.class}) +public class MybatisPlusJoinAutoConfiguration { + + private static final Logger logger = LoggerFactory.getLogger(MybatisPlusJoinAutoConfiguration.class); + + + @SuppressWarnings("FieldCanBeLocal") + private final MybatisPlusJoinProperties properties; + + + public MybatisPlusJoinAutoConfiguration(MybatisPlusJoinProperties properties) { + this.properties = properties; + } + + @Bean + @Order(Ordered.HIGHEST_PRECEDENCE) + public MPJInterceptor mpjInterceptor() { + return new MPJInterceptor(); + } + + + @Bean + @ConditionalOnBean(SqlSessionFactory.class) + public InterceptorConfig interceptorConfig(List sqlSessionFactoryList) { + return new InterceptorConfig(sqlSessionFactoryList); + } + + @Bean + @Order(Ordered.HIGHEST_PRECEDENCE) + @ConditionalOnMissingBean({DefaultSqlInjector.class, AbstractSqlInjector.class, ISqlInjector.class}) + public MPJSqlInjector mpjSqlInjector() { + return new MPJSqlInjector(); + } + + @Bean + @Order(Ordered.HIGHEST_PRECEDENCE) + public MappingConfig mappingConfig() { + return new MappingConfig(); + } + + @Bean + @Order(Ordered.HIGHEST_PRECEDENCE) + public SpringContentUtils springContentUtils() { + return new SpringContentUtils(); + } + +} diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java new file mode 100644 index 0000000..97df694 --- /dev/null +++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java @@ -0,0 +1,19 @@ +package com.github.yulichang.autoconfigure; + +import lombok.Data; +import lombok.experimental.Accessors; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Configuration properties for MyBatis. + * + * @author Eddú Meléndez + * @author Kazuki Shimizu + */ +@Data +@Accessors(chain = true) +@ConfigurationProperties(prefix = "mybatis-plus-join") +public class MybatisPlusJoinProperties { + + private Boolean banner = false; +} diff --git a/mybatis-plus-join-boot-starter/src/main/resources/META-INF/spring.factories b/mybatis-plus-join-boot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..f08fa4e --- /dev/null +++ b/mybatis-plus-join-boot-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.github.yulichang.autoconfigure.MybatisPlusJoinAutoConfiguration diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml new file mode 100644 index 0000000..cc6a216 --- /dev/null +++ b/mybatis-plus-join-core/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + com.github.yulichang + mybatis-plus-join-root + 1.3.0 + + mybatis-plus-join-core + mybatis-plus-join-core + + An enhanced toolkit of Mybatis-Plus to simplify development. + https://github.com/yulichang/mybatis-plus-join + + + The Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + mybatis-plus-join + yulichang + yu_lichang@qq.com + + + + scm:git:https://github.com/yulichang/mybatis-plus-join.git + scm:git:https://github.com/yulichang/mybatis-plus-join.git + https://github.com/yulichang/mybatis-plus-join + + + + + 8 + 8 + UTF-8 + + + + + com.github.yulichang + mybatis-plus-join-annotation + 1.3.0 + + + \ No newline at end of file diff --git a/src/main/java/com/baomidou/mybatisplus/core/metadata/MPJTableInfoHelper.java b/mybatis-plus-join-core/src/main/java/com/baomidou/mybatisplus/core/metadata/MPJTableInfoHelper.java similarity index 100% rename from src/main/java/com/baomidou/mybatisplus/core/metadata/MPJTableInfoHelper.java rename to mybatis-plus-join-core/src/main/java/com/baomidou/mybatisplus/core/metadata/MPJTableInfoHelper.java diff --git a/src/main/java/com/github/yulichang/base/MPJBaseMapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseMapper.java similarity index 100% rename from src/main/java/com/github/yulichang/base/MPJBaseMapper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseMapper.java diff --git a/src/main/java/com/github/yulichang/base/MPJBaseService.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseService.java similarity index 100% rename from src/main/java/com/github/yulichang/base/MPJBaseService.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseService.java diff --git a/src/main/java/com/github/yulichang/base/MPJBaseServiceImpl.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseServiceImpl.java similarity index 100% rename from src/main/java/com/github/yulichang/base/MPJBaseServiceImpl.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/base/MPJBaseServiceImpl.java diff --git a/src/main/java/com/github/yulichang/base/mapper/MPJDeepMapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/mapper/MPJDeepMapper.java similarity index 100% rename from src/main/java/com/github/yulichang/base/mapper/MPJDeepMapper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/base/mapper/MPJDeepMapper.java diff --git a/src/main/java/com/github/yulichang/base/mapper/MPJJoinMapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/mapper/MPJJoinMapper.java similarity index 100% rename from src/main/java/com/github/yulichang/base/mapper/MPJJoinMapper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/base/mapper/MPJJoinMapper.java diff --git a/src/main/java/com/github/yulichang/base/mapper/wrapper/MappingQuery.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/mapper/wrapper/MappingQuery.java similarity index 100% rename from src/main/java/com/github/yulichang/base/mapper/wrapper/MappingQuery.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/base/mapper/wrapper/MappingQuery.java diff --git a/src/main/java/com/github/yulichang/base/service/MPJDeepService.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/service/MPJDeepService.java similarity index 100% rename from src/main/java/com/github/yulichang/base/service/MPJDeepService.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/base/service/MPJDeepService.java diff --git a/src/main/java/com/github/yulichang/base/service/MPJJoinService.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/base/service/MPJJoinService.java similarity index 100% rename from src/main/java/com/github/yulichang/base/service/MPJJoinService.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/base/service/MPJJoinService.java diff --git a/src/main/java/com/github/yulichang/config/InterceptorConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java similarity index 90% rename from src/main/java/com/github/yulichang/config/InterceptorConfig.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java index 7d0292b..2b632df 100644 --- a/src/main/java/com/github/yulichang/config/InterceptorConfig.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java @@ -8,8 +8,6 @@ import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.plugin.Interceptor; import org.apache.ibatis.plugin.InterceptorChain; import org.apache.ibatis.session.SqlSessionFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.context.annotation.Configuration; import java.lang.reflect.Field; import java.util.List; @@ -19,9 +17,9 @@ import java.util.List; * * @author yulichang */ -@Configuration -@ConditionalOnBean(SqlSessionFactory.class) -@SuppressWarnings("unused") +//@Configuration +//@ConditionalOnBean(SqlSessionFactory.class) +//@SuppressWarnings("unused") public class InterceptorConfig { diff --git a/src/main/java/com/github/yulichang/config/MappingConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java similarity index 86% rename from src/main/java/com/github/yulichang/config/MappingConfig.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java index ee07913..ee742b5 100644 --- a/src/main/java/com/github/yulichang/config/MappingConfig.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java @@ -1,12 +1,10 @@ package com.github.yulichang.config; import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper; -import com.github.yulichang.mapper.MPJTableMapperHelper; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; +import com.github.yulichang.mapper.MPJTableMapperHelper; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; -import org.springframework.core.Ordered; -import org.springframework.core.annotation.Order; /** * 关系映射配置 @@ -14,7 +12,7 @@ import org.springframework.core.annotation.Order; * @author yulichang * @since 1.2.0 */ -@Order(Ordered.HIGHEST_PRECEDENCE) +//@Order(Ordered.HIGHEST_PRECEDENCE) public class MappingConfig implements ApplicationListener { @Override diff --git a/src/main/java/com/github/yulichang/exception/MPJException.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/exception/MPJException.java similarity index 100% rename from src/main/java/com/github/yulichang/exception/MPJException.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/exception/MPJException.java diff --git a/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java similarity index 82% rename from src/main/java/com/github/yulichang/injector/MPJSqlInjector.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java index e0ac705..4850462 100644 --- a/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java @@ -2,27 +2,16 @@ package com.github.yulichang.injector; import com.baomidou.mybatisplus.core.MybatisPlusVersion; import com.baomidou.mybatisplus.core.injector.AbstractMethod; -import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector; import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; -import com.baomidou.mybatisplus.core.injector.ISqlInjector; import com.baomidou.mybatisplus.core.injector.methods.*; import com.baomidou.mybatisplus.core.mapper.Mapper; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.toolkit.ClassUtils; import com.github.yulichang.mapper.MPJTableMapperHelper; import com.github.yulichang.method.*; -import com.github.yulichang.method.mp.SelectCount; -import com.github.yulichang.method.mp.SelectList; -import com.github.yulichang.method.mp.SelectMaps; -import com.github.yulichang.method.mp.SelectMapsPage; -import com.github.yulichang.method.mp.SelectObjs; import com.github.yulichang.method.mp.SelectOne; -import com.github.yulichang.method.mp.SelectPage; import org.apache.ibatis.builder.MapperBuilderAssistant; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.core.GenericTypeResolver; -import org.springframework.core.Ordered; -import org.springframework.core.annotation.Order; import java.util.ArrayList; import java.util.Arrays; @@ -37,8 +26,8 @@ import static java.util.stream.Collectors.toList; * @author yulichang * @see DefaultSqlInjector */ -@Order(Ordered.HIGHEST_PRECEDENCE) -@ConditionalOnMissingBean({DefaultSqlInjector.class, AbstractSqlInjector.class, ISqlInjector.class}) +//@Order(Ordered.HIGHEST_PRECEDENCE) +//@ConditionalOnMissingBean({DefaultSqlInjector.class, AbstractSqlInjector.class, ISqlInjector.class}) public class MPJSqlInjector extends DefaultSqlInjector { private static final List METHOD_LIST = Arrays.asList("SelectOne", "SelectCount", @@ -109,12 +98,12 @@ public class MPJSqlInjector extends DefaultSqlInjector { private List getSelectMethod() { List list = new ArrayList<>(); list.add(new SelectOne()); - list.add(new SelectCount()); - list.add(new SelectMaps()); - list.add(new SelectMapsPage()); - list.add(new SelectObjs()); - list.add(new SelectList()); - list.add(new SelectPage()); + list.add(new com.github.yulichang.method.mp.SelectCount()); + list.add(new com.github.yulichang.method.mp.SelectMaps()); + list.add(new com.github.yulichang.method.mp.SelectMapsPage()); + list.add(new com.github.yulichang.method.mp.SelectObjs()); + list.add(new com.github.yulichang.method.mp.SelectList()); + list.add(new com.github.yulichang.method.mp.SelectPage()); return list; } diff --git a/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java similarity index 98% rename from src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java index 7184c9f..d2f5363 100644 --- a/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java @@ -150,13 +150,13 @@ public class MPJInterceptor implements Interceptor { TableInfo tableInfo = TableInfoHelper.getTableInfo(resultType); String id = ms.getId() + StringPool.DOT + Constants.MYBATIS_PLUS + StringPool.UNDERSCORE + resultType.getName(); if (!(obj instanceof MPJLambdaWrapper) || Map.class.isAssignableFrom(resultType) || - ReflectionKit.isPrimitiveOrWrapper(resultType) || + com.github.yulichang.toolkit.ReflectionKit.isPrimitiveOrWrapper(resultType) || Collection.class.isAssignableFrom(resultType)) { result.add(getDefaultResultMap(tableInfo, ms, resultType, id)); return result; } MPJLambdaWrapper wrapper = (MPJLambdaWrapper) obj; - Map fieldMap = ReflectionKit.getFieldMap(resultType); + Map fieldMap = com.github.yulichang.toolkit.ReflectionKit.getFieldMap(resultType); List columnList = wrapper.getSelectColumns(); //移除对多查询列,为了可重复使用wrapper columnList.removeIf(SelectColumn::isLabel); diff --git a/src/main/java/com/github/yulichang/interfaces/MPJBaseJoin.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interfaces/MPJBaseJoin.java similarity index 100% rename from src/main/java/com/github/yulichang/interfaces/MPJBaseJoin.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/interfaces/MPJBaseJoin.java diff --git a/src/main/java/com/github/yulichang/mapper/MPJMappingWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJMappingWrapper.java similarity index 100% rename from src/main/java/com/github/yulichang/mapper/MPJMappingWrapper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJMappingWrapper.java diff --git a/src/main/java/com/github/yulichang/mapper/MPJTableFieldInfo.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableFieldInfo.java similarity index 100% rename from src/main/java/com/github/yulichang/mapper/MPJTableFieldInfo.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableFieldInfo.java diff --git a/src/main/java/com/github/yulichang/mapper/MPJTableInfo.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableInfo.java similarity index 100% rename from src/main/java/com/github/yulichang/mapper/MPJTableInfo.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableInfo.java diff --git a/src/main/java/com/github/yulichang/mapper/MPJTableMapperHelper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableMapperHelper.java similarity index 100% rename from src/main/java/com/github/yulichang/mapper/MPJTableMapperHelper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableMapperHelper.java diff --git a/src/main/java/com/github/yulichang/method/MPJAbstractMethod.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJAbstractMethod.java similarity index 100% rename from src/main/java/com/github/yulichang/method/MPJAbstractMethod.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJAbstractMethod.java diff --git a/src/main/java/com/github/yulichang/method/MPJBaseMethod.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJBaseMethod.java similarity index 100% rename from src/main/java/com/github/yulichang/method/MPJBaseMethod.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJBaseMethod.java diff --git a/src/main/java/com/github/yulichang/method/MPJResultType.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJResultType.java similarity index 100% rename from src/main/java/com/github/yulichang/method/MPJResultType.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/MPJResultType.java diff --git a/src/main/java/com/github/yulichang/method/SelectJoinCount.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinCount.java similarity index 100% rename from src/main/java/com/github/yulichang/method/SelectJoinCount.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinCount.java diff --git a/src/main/java/com/github/yulichang/method/SelectJoinList.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinList.java similarity index 100% rename from src/main/java/com/github/yulichang/method/SelectJoinList.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinList.java diff --git a/src/main/java/com/github/yulichang/method/SelectJoinMap.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMap.java similarity index 100% rename from src/main/java/com/github/yulichang/method/SelectJoinMap.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMap.java diff --git a/src/main/java/com/github/yulichang/method/SelectJoinMaps.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMaps.java similarity index 100% rename from src/main/java/com/github/yulichang/method/SelectJoinMaps.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMaps.java diff --git a/src/main/java/com/github/yulichang/method/SelectJoinMapsPage.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMapsPage.java similarity index 100% rename from src/main/java/com/github/yulichang/method/SelectJoinMapsPage.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinMapsPage.java diff --git a/src/main/java/com/github/yulichang/method/SelectJoinOne.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinOne.java similarity index 100% rename from src/main/java/com/github/yulichang/method/SelectJoinOne.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinOne.java diff --git a/src/main/java/com/github/yulichang/method/SelectJoinPage.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinPage.java similarity index 100% rename from src/main/java/com/github/yulichang/method/SelectJoinPage.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SelectJoinPage.java diff --git a/src/main/java/com/github/yulichang/method/SqlMethod.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SqlMethod.java similarity index 100% rename from src/main/java/com/github/yulichang/method/SqlMethod.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/SqlMethod.java diff --git a/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 similarity index 100% rename from src/main/java/com/github/yulichang/method/mp/SelectCount.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectCount.java diff --git a/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 similarity index 100% rename from src/main/java/com/github/yulichang/method/mp/SelectList.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectList.java diff --git a/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 similarity index 100% rename from src/main/java/com/github/yulichang/method/mp/SelectMaps.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMaps.java diff --git a/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 similarity index 100% rename from src/main/java/com/github/yulichang/method/mp/SelectMapsPage.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectMapsPage.java diff --git a/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 similarity index 100% rename from src/main/java/com/github/yulichang/method/mp/SelectObjs.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectObjs.java diff --git a/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 similarity index 100% rename from src/main/java/com/github/yulichang/method/mp/SelectOne.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectOne.java diff --git a/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 similarity index 100% rename from src/main/java/com/github/yulichang/method/mp/SelectPage.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/SelectPage.java diff --git a/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 similarity index 100% rename from src/main/java/com/github/yulichang/method/mp/TableAlias.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/method/mp/TableAlias.java diff --git a/src/main/java/com/github/yulichang/query/MPJLambdaQueryWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJLambdaQueryWrapper.java similarity index 100% rename from src/main/java/com/github/yulichang/query/MPJLambdaQueryWrapper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJLambdaQueryWrapper.java diff --git a/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java similarity index 100% rename from src/main/java/com/github/yulichang/query/MPJQueryWrapper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java diff --git a/src/main/java/com/github/yulichang/query/interfaces/MPJJoin.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/interfaces/MPJJoin.java similarity index 100% rename from src/main/java/com/github/yulichang/query/interfaces/MPJJoin.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/query/interfaces/MPJJoin.java diff --git a/src/main/java/com/github/yulichang/toolkit/Constant.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/Constant.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/Constant.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/Constant.java diff --git a/src/main/java/com/github/yulichang/toolkit/InterceptorList.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/InterceptorList.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/InterceptorList.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/InterceptorList.java diff --git a/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/LambdaUtils.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java diff --git a/src/main/java/com/github/yulichang/toolkit/MPJWrappers.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJWrappers.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/MPJWrappers.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJWrappers.java diff --git a/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/ReflectionKit.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java diff --git a/src/main/java/com/github/yulichang/toolkit/SpringContentUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/SpringContentUtils.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/SpringContentUtils.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/SpringContentUtils.java diff --git a/src/main/java/com/github/yulichang/toolkit/sql/SqlScriptUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/sql/SqlScriptUtils.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/sql/SqlScriptUtils.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/sql/SqlScriptUtils.java diff --git a/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java diff --git a/src/main/java/com/github/yulichang/toolkit/support/SelectColumn.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SelectColumn.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/support/SelectColumn.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SelectColumn.java diff --git a/src/main/java/com/github/yulichang/toolkit/support/SerializedLambda.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SerializedLambda.java similarity index 100% rename from src/main/java/com/github/yulichang/toolkit/support/SerializedLambda.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SerializedLambda.java diff --git a/src/main/java/com/github/yulichang/wrapper/MPJAbstractLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJAbstractLambdaWrapper.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/MPJAbstractLambdaWrapper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJAbstractLambdaWrapper.java diff --git a/src/main/java/com/github/yulichang/wrapper/MPJAbstractWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJAbstractWrapper.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/MPJAbstractWrapper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJAbstractWrapper.java diff --git a/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java diff --git a/src/main/java/com/github/yulichang/wrapper/enums/BaseFuncEnum.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/enums/BaseFuncEnum.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/enums/BaseFuncEnum.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/enums/BaseFuncEnum.java diff --git a/src/main/java/com/github/yulichang/wrapper/enums/DefaultFuncEnum.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/enums/DefaultFuncEnum.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/enums/DefaultFuncEnum.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/enums/DefaultFuncEnum.java diff --git a/src/main/java/com/github/yulichang/wrapper/interfaces/Compare.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Compare.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/interfaces/Compare.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Compare.java diff --git a/src/main/java/com/github/yulichang/wrapper/interfaces/Func.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Func.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/interfaces/Func.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Func.java diff --git a/src/main/java/com/github/yulichang/wrapper/interfaces/Join.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Join.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/interfaces/Join.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Join.java diff --git a/src/main/java/com/github/yulichang/wrapper/interfaces/LambdaJoin.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/LambdaJoin.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/interfaces/LambdaJoin.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/LambdaJoin.java diff --git a/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/interfaces/Query.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java diff --git a/src/main/java/com/github/yulichang/wrapper/interfaces/on/OnCompare.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/on/OnCompare.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/interfaces/on/OnCompare.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/on/OnCompare.java diff --git a/src/main/java/com/github/yulichang/wrapper/interfaces/on/OnFunction.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/on/OnFunction.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/interfaces/on/OnFunction.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/on/OnFunction.java diff --git a/src/main/java/com/github/yulichang/wrapper/resultmap/LabelType.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/LabelType.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/resultmap/LabelType.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/LabelType.java diff --git a/src/main/java/com/github/yulichang/wrapper/resultmap/MFunc.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MFunc.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/resultmap/MFunc.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MFunc.java diff --git a/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java diff --git a/src/main/java/com/github/yulichang/wrapper/resultmap/Result.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Result.java similarity index 100% rename from src/main/java/com/github/yulichang/wrapper/resultmap/Result.java rename to mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Result.java diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml new file mode 100644 index 0000000..9eaf596 --- /dev/null +++ b/mybatis-plus-join-test/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + com.github.yulichang + mybatis-plus-join-root + 1.3.0 + + mybatis-plus-join-test + mybatis-plus-join-test + + An enhanced toolkit of Mybatis-Plus to simplify development. + https://github.com/yulichang/mybatis-plus-join + + + The Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + mybatis-plus-join + yulichang + yu_lichang@qq.com + + + + scm:git:https://github.com/yulichang/mybatis-plus-join.git + scm:git:https://github.com/yulichang/mybatis-plus-join.git + https://github.com/yulichang/mybatis-plus-join + + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/Main.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/Main.java new file mode 100644 index 0000000..a2a33f2 --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/Main.java @@ -0,0 +1,7 @@ +package com.github.yulichang; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index f434148..41cc966 100644 --- a/pom.xml +++ b/pom.xml @@ -3,9 +3,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.github.yulichang - mybatis-plus-join + mybatis-plus-join-root + pom 1.3.0 - mybatis-plus-join + mybatis-plus-join-root + An enhanced toolkit of Mybatis-Plus to simplify development. https://github.com/yulichang/mybatis-plus-join @@ -26,6 +28,14 @@ scm:git:https://github.com/yulichang/mybatis-plus-join.git https://github.com/yulichang/mybatis-plus-join + + + mybatis-plus-join-boot-starter + mybatis-plus-join-core + mybatis-plus-join-annotation + mybatis-plus-join-test + + UTF-8 github diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 327caa0..0000000 --- a/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,6 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.github.yulichang.interceptor.MPJInterceptor,\ - com.github.yulichang.injector.MPJSqlInjector,\ - com.github.yulichang.config.InterceptorConfig,\ - com.github.yulichang.config.MappingConfig,\ - com.github.yulichang.toolkit.SpringContentUtils From 1a35efff82ed0d505c7d9333894aa6142025c4eb Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Tue, 8 Nov 2022 20:05:43 +0800 Subject: [PATCH 02/23] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8C=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yulichang/wrapper/resultmap/MPJResultMap.java | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/main/java/com/github/yulichang/wrapper/resultmap/MPJResultMap.java diff --git a/src/main/java/com/github/yulichang/wrapper/resultmap/MPJResultMap.java b/src/main/java/com/github/yulichang/wrapper/resultmap/MPJResultMap.java deleted file mode 100644 index e792eb8..0000000 --- a/src/main/java/com/github/yulichang/wrapper/resultmap/MPJResultMap.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.yulichang.wrapper.resultmap; - -import lombok.Getter; -import org.apache.ibatis.mapping.ResultMap; - -public class MPJResultMap { - - @Getter - private ResultMap resultMap; - - -} From 3326a1b81d69a0fd6c7e5a295fe0518334d4ef04 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 9 Nov 2022 11:14:20 +0800 Subject: [PATCH 03/23] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8C=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mybatis-plus-join-boot-starter/pom.xml | 8 ++ .../MybatisPlusJoinAutoConfiguration.java | 24 +++- .../MybatisPlusJoinProperties.java | 9 +- ...itional-spring-configuration-metadata.json | 17 +++ .../yulichang/config/InterceptorConfig.java | 11 +- .../yulichang/config/MappingConfig.java | 1 - .../yulichang/injector/MPJSqlInjector.java | 2 - mybatis-plus-join-test/pom.xml | 38 ++++++ .../main/java/com/github/yulichang/Main.java | 7 - .../github/yulichang/test/Application.java | 13 ++ .../github/yulichang/test/ListenerEvent.java | 31 +++++ .../test/config/MybatisPlusConfig.java | 25 ++++ .../github/yulichang/test/dto/UserDTO.java | 41 ++++++ .../yulichang/test/entity/AddressDO.java | 31 +++++ .../github/yulichang/test/entity/AreaDO.java | 31 +++++ .../github/yulichang/test/entity/UserDO.java | 34 +++++ .../com/github/yulichang/test/enums/Sex.java | 24 ++++ .../yulichang/test/mapper/AddressMapper.java | 10 ++ .../yulichang/test/mapper/AreaMapper.java | 10 ++ .../yulichang/test/mapper/UserMapper.java | 10 ++ .../src/main/resources/application.yml | 22 +++ .../src/main/resources/db/data.sql | 79 +++++++++++ .../src/main/resources/db/schema.sql | 42 ++++++ .../com/github/yulichang/test/JoinTest.java | 126 ++++++++++++++++++ .../com/github/yulichang/test/MPJ131Test.java | 37 +++++ .../yulichang/test/QueryWrapperTest.java | 85 ++++++++++++ 26 files changed, 748 insertions(+), 20 deletions(-) create mode 100644 mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json delete mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/Main.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/Application.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AddressDO.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AreaDO.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/enums/Sex.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AddressMapper.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AreaMapper.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/UserMapper.java create mode 100644 mybatis-plus-join-test/src/main/resources/application.yml create mode 100644 mybatis-plus-join-test/src/main/resources/db/data.sql create mode 100644 mybatis-plus-join-test/src/main/resources/db/schema.sql create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/MPJ131Test.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/QueryWrapperTest.java diff --git a/mybatis-plus-join-boot-starter/pom.xml b/mybatis-plus-join-boot-starter/pom.xml index 50c222f..f5de497 100644 --- a/mybatis-plus-join-boot-starter/pom.xml +++ b/mybatis-plus-join-boot-starter/pom.xml @@ -44,6 +44,14 @@ mybatis-plus-join-core 1.3.0 + + + org.springframework.boot + spring-boot-configuration-processor + true + 2.7.5 + + \ No newline at end of file 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 08f3a60..c15d33d 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 @@ -28,6 +28,10 @@ import org.springframework.core.annotation.Order; import javax.sql.DataSource; import java.util.List; +/** + * @author yulichang + * @since 1.3.2 + */ @SuppressWarnings("unused") @Configuration(proxyBeanMethods = false) @ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class}) @@ -47,19 +51,27 @@ public class MybatisPlusJoinAutoConfiguration { this.properties = properties; } + /** + * mybatis plus join 拦截器 + */ @Bean @Order(Ordered.HIGHEST_PRECEDENCE) public MPJInterceptor mpjInterceptor() { return new MPJInterceptor(); } - + /** + * mybatis plus 拦截器配置 + */ @Bean @ConditionalOnBean(SqlSessionFactory.class) public InterceptorConfig interceptorConfig(List sqlSessionFactoryList) { - return new InterceptorConfig(sqlSessionFactoryList); + return new InterceptorConfig(sqlSessionFactoryList, properties.getBanner()); } + /** + * mybatis plus join 自定义方法 + */ @Bean @Order(Ordered.HIGHEST_PRECEDENCE) @ConditionalOnMissingBean({DefaultSqlInjector.class, AbstractSqlInjector.class, ISqlInjector.class}) @@ -67,12 +79,20 @@ public class MybatisPlusJoinAutoConfiguration { return new MPJSqlInjector(); } + /** + * 多表查询注解 + * + * @deprecated + */ @Bean @Order(Ordered.HIGHEST_PRECEDENCE) public MappingConfig mappingConfig() { return new MappingConfig(); } + /** + * springboot content 工具类 + */ @Bean @Order(Ordered.HIGHEST_PRECEDENCE) public SpringContentUtils springContentUtils() { diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java index 97df694..054835a 100644 --- a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java +++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java @@ -5,15 +5,16 @@ import lombok.experimental.Accessors; import org.springframework.boot.context.properties.ConfigurationProperties; /** - * Configuration properties for MyBatis. - * - * @author Eddú Meléndez - * @author Kazuki Shimizu + * @author yulichang + * @since 1.3.2 */ @Data @Accessors(chain = true) @ConfigurationProperties(prefix = "mybatis-plus-join") public class MybatisPlusJoinProperties { + /** + * 打印banner + */ private Boolean banner = false; } 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 new file mode 100644 index 0000000..aa9ddcb --- /dev/null +++ b/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,17 @@ +{ + "groups": [ + { + "sourceType": "com.github.yulichang.autoconfigure.MybatisPlusJoinProperties", + "name": "mybatis-plus-join", + "type": "com.github.yulichang.autoconfigure.MybatisPlusJoinProperties" + } + ], + "properties": [ + { + "name": "mybatis-plus-join.banner", + "defaultValue": true, + "type": "java.lang.Boolean", + "description": "打印 banner." + } + ] +} \ No newline at end of file diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java index 2b632df..6bb41b1 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java @@ -17,16 +17,19 @@ import java.util.List; * * @author yulichang */ -//@Configuration -//@ConditionalOnBean(SqlSessionFactory.class) -//@SuppressWarnings("unused") public class InterceptorConfig { private static final Log logger = LogFactory.getLog(InterceptorConfig.class); - public InterceptorConfig(List sqlSessionFactoryList) { + public InterceptorConfig(List sqlSessionFactoryList, Boolean banner) { replaceInterceptorChain(sqlSessionFactoryList); + if (banner) { + //打印banner + System.out.println(" _ _ |_ _ _|_. ___ _ | _ . _ . _ \n" + + "| | |\\/|_)(_| | |_\\ |_)||_|_\\ | (_) | | | \n" + + " / | / 1.3.0"); + } } @SuppressWarnings("unchecked") diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java index ee742b5..0012a1a 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java @@ -12,7 +12,6 @@ import org.springframework.context.ApplicationListener; * @author yulichang * @since 1.2.0 */ -//@Order(Ordered.HIGHEST_PRECEDENCE) public class MappingConfig implements ApplicationListener { @Override diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java index 4850462..1ff8425 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java @@ -26,8 +26,6 @@ import static java.util.stream.Collectors.toList; * @author yulichang * @see DefaultSqlInjector */ -//@Order(Ordered.HIGHEST_PRECEDENCE) -//@ConditionalOnMissingBean({DefaultSqlInjector.class, AbstractSqlInjector.class, ISqlInjector.class}) public class MPJSqlInjector extends DefaultSqlInjector { private static final List METHOD_LIST = Arrays.asList("SelectOne", "SelectCount", diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml index 9eaf596..c4b642e 100644 --- a/mybatis-plus-join-test/pom.xml +++ b/mybatis-plus-join-test/pom.xml @@ -1,4 +1,5 @@ + @@ -33,9 +34,46 @@ + 2.5.4 + 8 8 UTF-8 + + + org.springframework.boot + spring-boot-starter + ${springboot.version} + + + org.springframework.boot + spring-boot-starter-test + ${springboot.version} + test + + + com.h2database + h2 + 2.1.214 + runtime + + + org.projectlombok + lombok + 1.18.24 + + + com.github.yulichang + mybatis-plus-join-boot-starter + 1.3.0 + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.5 + + + \ No newline at end of file diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/Main.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/Main.java deleted file mode 100644 index a2a33f2..0000000 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.yulichang; - -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/Application.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/Application.java new file mode 100644 index 0000000..ee0e144 --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/Application.java @@ -0,0 +1,13 @@ +package com.github.yulichang.test; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java new file mode 100644 index 0000000..c07dd89 --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java @@ -0,0 +1,31 @@ +package com.github.yulichang.test; + +import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; +import com.github.yulichang.test.mapper.UserMapper; +import org.jetbrains.annotations.NotNull; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ApplicationContextEvent; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.List; + +@Component +@SuppressWarnings("unused") +public class ListenerEvent implements ApplicationListener { + + @Resource + private UserMapper userMapper; + + @PostConstruct + public void init() { + List infos = TableInfoHelper.getTableInfos(); + } + + @Override + public void onApplicationEvent(@NotNull ApplicationContextEvent applicationContextEvent) { + + } +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java new file mode 100644 index 0000000..73dd24d --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java @@ -0,0 +1,25 @@ +package com.github.yulichang.test.config; + +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * mybatis-plus配置 + */ +@Configuration +public class MybatisPlusConfig { + + /** + * 分页插件 + */ + @Bean + public MybatisPlusInterceptor paginationInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + PaginationInnerInterceptor page = new PaginationInnerInterceptor(); + page.setOptimizeJoin(false); + interceptor.addInnerInterceptor(page); + return interceptor; + } +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java new file mode 100644 index 0000000..67a3ef9 --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java @@ -0,0 +1,41 @@ +package com.github.yulichang.test.dto; + +import com.github.yulichang.test.entity.AddressDO; +import com.github.yulichang.test.enums.Sex; +import lombok.Data; +import lombok.ToString; + +import java.util.List; + + +/** + * userDTO + */ +@Data +@ToString +public class UserDTO { + /** user */ + private Integer id; + /** user */ + private String nameName; + /** user */ + private Sex sex; + /** user */ + private String headImg; + /** user */ + private String userHeadImg;//同 headImg 别名测试 + /** user_address */ + private String tel; + /** user_address */ + private String address; + /** user_address */ + private String userAddress; + /** area */ + private String province; + /** area */ + private String city; + /** area */ + private String area; + + private List addressList; +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AddressDO.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AddressDO.java new file mode 100644 index 0000000..218fd9e --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AddressDO.java @@ -0,0 +1,31 @@ +package com.github.yulichang.test.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@Data +@ToString +@Accessors(chain = true) +@EqualsAndHashCode +@TableName("address") +public class AddressDO { + + @TableId + private Integer id; + + private Integer userId; + + private Integer areaId; + + private String tel; + + private String address; + + @TableLogic + private Boolean del; +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AreaDO.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AreaDO.java new file mode 100644 index 0000000..c58c89f --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AreaDO.java @@ -0,0 +1,31 @@ +package com.github.yulichang.test.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@Data +@ToString +@Accessors(chain = true) +@EqualsAndHashCode +@TableName("area") +public class AreaDO { + + @TableId + private Integer id; + + private String province; + + private String city; + + private String area; + + private String postcode; + + @TableLogic + private Boolean del; +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java new file mode 100644 index 0000000..ecb05a3 --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java @@ -0,0 +1,34 @@ +package com.github.yulichang.test.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import com.github.yulichang.test.enums.Sex; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@Data +@ToString +@Accessors(chain = true) +@EqualsAndHashCode +@TableName("`user`") +public class UserDO { + + @TableId + private Integer id; + + @TableField("name") + private String sdafrrvnbioiure; + + private Sex sex; + + private String headImg; + + private Integer addressId; + + @TableLogic + private Boolean del; +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/enums/Sex.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/enums/Sex.java new file mode 100644 index 0000000..7ab9f24 --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/enums/Sex.java @@ -0,0 +1,24 @@ +package com.github.yulichang.test.enums; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +public enum Sex { + + MAN(0, "男"), + + WOMAN(1, "女"); + + @EnumValue + private final int code; + private final String des; + + Sex(int code, String des) { + this.code = code; + this.des = des; + } + +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AddressMapper.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AddressMapper.java new file mode 100644 index 0000000..bbde4a3 --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AddressMapper.java @@ -0,0 +1,10 @@ +package com.github.yulichang.test.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.entity.AddressDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface AddressMapper extends MPJBaseMapper { +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AreaMapper.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AreaMapper.java new file mode 100644 index 0000000..7a3314c --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AreaMapper.java @@ -0,0 +1,10 @@ +package com.github.yulichang.test.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.entity.AreaDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface AreaMapper extends MPJBaseMapper { +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/UserMapper.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/UserMapper.java new file mode 100644 index 0000000..4088f5b --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/UserMapper.java @@ -0,0 +1,10 @@ +package com.github.yulichang.test.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.entity.UserDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface UserMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/main/resources/application.yml b/mybatis-plus-join-test/src/main/resources/application.yml new file mode 100644 index 0000000..ce7f946 --- /dev/null +++ b/mybatis-plus-join-test/src/main/resources/application.yml @@ -0,0 +1,22 @@ +spring: + datasource: + driver-class-name: org.h2.Driver + url: jdbc:h2:mem:test + username: root + password: test + sql: + init: + schema-locations: classpath:db/schema.sql + data-locations: classpath:db/data.sql +mybatis-plus: + global-config: + db-config: + logic-delete-field: del + logic-delete-value: true + logic-not-delete-value: false + banner: true +# configuration: +# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +mybatis-plus-join: + banner: false \ No newline at end of file diff --git a/mybatis-plus-join-test/src/main/resources/db/data.sql b/mybatis-plus-join-test/src/main/resources/db/data.sql new file mode 100644 index 0000000..19f1926 --- /dev/null +++ b/mybatis-plus-join-test/src/main/resources/db/data.sql @@ -0,0 +1,79 @@ +-- noinspection SqlDialectInspectionForFile + +-- noinspection SqlNoDataSourceInspectionForFile + +DELETE FROM area; + +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10001, '北京市01', '北京01', '朝阳01', '80001', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10002, '北京市02', '北京02', '朝阳02', '80002', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10003, '北京市03', '北京03', '朝阳03', '80003', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10004, '北京市04', '北京04', '朝阳04', '80004', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10005, '北京市05', '北京05', '朝阳05', '80005', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10006, '北京市06', '北京06', '朝阳06', '80006', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10007, '北京市07', '北京07', '朝阳07', '80007', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10008, '北京市08', '北京08', '朝阳08', '80008', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10009, '北京市09', '北京09', '朝阳09', '80009', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10010, '北京市10', '北京10', '朝阳10', '80010', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10011, '北京市11', '北京11', '朝阳11', '80011', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10012, '北京市12', '北京12', '朝阳12', '80012', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10013, '北京市13', '北京13', '朝阳13', '80013', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10014, '北京市14', '北京14', '朝阳14', '80014', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10015, '北京市15', '北京15', '朝阳15', '80015', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10016, '北京市16', '北京16', '朝阳16', '80016', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10017, '北京市17', '北京17', '朝阳17', '80017', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10018, '北京市18', '北京18', '朝阳18', '80018', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10019, '北京市19', '北京19', '朝阳19', '80019', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10020, '北京市20', '北京20', '朝阳20', '80020', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10021, '北京市21', '北京21', '朝阳21', '80021', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10022, '北京市22', '北京22', '朝阳22', '80022', false); + +DELETE FROM `user`; + +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 1, '张三01', 1, 1, 'https://url-01', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 2, '李四02', 1, 0, 'https://url-02', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 3, '李四02', 1, 0, 'https://url-03', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 4, '李四04', 1, 0, 'https://url-04', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 5, '李四05', 1, 0, 'https://url-05', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 6, '李四06', 1, 0, 'https://url-06', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 7, '李四07', 1, 0, 'https://url-07', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 8, '李四08', 1, 0, 'https://url-08', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 9, '李四09', 1, 0, 'https://url-09', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (10, '李四10', 1, 0, 'https://url-10', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (11, '李四11', 1, 0, 'https://url-11', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (12, '李四12', 1, 0, 'https://url-12', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (13, '李四13', 1, 0, 'https://url-13', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (14, '李四14', 1, 0, 'https://url-14', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (15, '李四15', 1, 0, 'https://url-15', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (16, '李四16', 1, 0, 'https://url-16', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (17, '李四17', 1, 0, 'https://url-17', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (18, '李四18', 1, 0, 'https://url-18', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (19, '李四19', 1, 0, 'https://url-19', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (20, '李四20', 1, 0, 'https://url-20', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (21, '李四21', 1, 0, 'https://url-21', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (22, '李四22', 1, 0, 'https://url-22', false); + + +DELETE FROM address; + +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 1, 1, 10001, '10000000001', '曹县01', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 2, 1, 10002, '10000000002', '曹县02', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 3, 1, 10003, '10000000003', '曹县03', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 4, 1, 10004, '10000000004', '曹县04', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 5, 1, 10005, '10000000005', '曹县05', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 6, 1, 10006, '10000000006', '曹县06', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 7, 1, 10007, '10000000007', '曹县07', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 8, 1, 10008, '10000000008', '曹县08', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 9, 1, 10009, '10000000009', '曹县09', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (10,10, 10010, '10000000010', '曹县10', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (11,11, 10011, '10000000011', '曹县11', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (12,12, 10012, '10000000012', '曹县12', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (13,13, 10013, '10000000013', '曹县13', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (14,14, 10014, '10000000014', '曹县14', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (15,15, 10015, '10000000015', '曹县15', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (16,16, 10016, '10000000016', '曹县16', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (17,17, 10017, '10000000017', '曹县17', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (18,18, 10018, '10000000018', '曹县18', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (19,19, 10019, '10000000019', '曹县19', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (20,20, 10020, '10000000020', '曹县20', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (21,21, 10021, '10000000021', '曹县21', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (22,22, 10022, '10000000022', '曹县22', false); \ No newline at end of file diff --git a/mybatis-plus-join-test/src/main/resources/db/schema.sql b/mybatis-plus-join-test/src/main/resources/db/schema.sql new file mode 100644 index 0000000..264b2ea --- /dev/null +++ b/mybatis-plus-join-test/src/main/resources/db/schema.sql @@ -0,0 +1,42 @@ +-- noinspection SqlDialectInspectionForFile + +-- noinspection SqlNoDataSourceInspectionForFile + +DROP TABLE IF EXISTS area; + +create table area +( + id int auto_increment + primary key, + province varchar(255) null, + city varchar(255) null, + area varchar(255) null, + postcode varchar(255) null, + del bit +); + +DROP TABLE IF EXISTS `user`; + +create table `user` +( + id int auto_increment + primary key, + `name` varchar(255) not null, + `address_id` int not null, + sex tinyint not null, + head_img varchar(255) not null, + del bit +); + +DROP TABLE IF EXISTS address; + +create table address +( + id int auto_increment + primary key, + user_id int null, + area_id int null, + tel varchar(255) null, + address varchar(255) null, + del bit +); \ No newline at end of file diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java new file mode 100644 index 0000000..85bd43d --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java @@ -0,0 +1,126 @@ +package com.github.yulichang.test; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.test.dto.UserDTO; +import com.github.yulichang.test.entity.AddressDO; +import com.github.yulichang.test.entity.AreaDO; +import com.github.yulichang.test.entity.UserDO; +import com.github.yulichang.test.mapper.UserMapper; +import com.github.yulichang.toolkit.MPJWrappers; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * 连表测试类 + *

+ * 支持mybatis-plus 查询枚举字段 + * 支持mybatis-plus typeHandle功能 + *

+ * 移除了mybatis-plus 逻辑删除支持,逻辑删除需要在连表查询时自己添加对应的条件 + */ +@SpringBootTest +class JoinTest { + @Resource + private UserMapper userMapper; + + /** + * 一对多 + */ + @Test + void testJoin() { + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + .selectAll(UserDO.class) + .selectCollection(AddressDO.class, UserDTO::getAddressList) + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) + .orderByDesc(UserDO::getId); + + List list = userMapper.selectJoinList(UserDTO.class, wrapper); + list.forEach(System.out::println); + } + + + /** + * 简单的分页关联查询 lambda + */ + @Test + void test1() { + IPage iPage = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class, + MPJWrappers.lambdaJoin() + .selectAll(UserDO.class) + .select(AddressDO::getAddress) + .select(AreaDO::getProvince) + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) + .leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)); + iPage.getRecords().forEach(System.out::println); + } + + /** + * 简单的分页关联查询 lambda + * ON语句多条件 + */ + @Test + void test3() { + IPage page = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class, + MPJWrappers.lambdaJoin() + .selectAll(UserDO.class) + .select(AddressDO::getAddress) + .leftJoin(AddressDO.class, on -> on + .eq(UserDO::getId, AddressDO::getUserId) + .eq(UserDO::getId, AddressDO::getUserId)) + .eq(UserDO::getId, 1) + .and(i -> i.eq(UserDO::getHeadImg, "er") + .or() + .eq(AddressDO::getUserId, 1)) + .eq(UserDO::getId, 1)); + page.getRecords().forEach(System.out::println); + } + + /** + * 简单的函数使用 + */ + @Test + void test4() { + UserDTO one = userMapper.selectJoinOne(UserDTO.class, MPJWrappers.lambdaJoin() + .selectSum(UserDO::getId) + .selectMax(UserDO::getId, UserDTO::getHeadImg) + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) + .eq(UserDO::getId, 1)); + System.out.println(one); + } + + + /** + * 忽略个别查询字段 + */ + @Test + void test6() { + IPage page = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class, + MPJWrappers.lambdaJoin() + .selectAll(UserDO.class) + .select(AddressDO.class, p -> true) + .select(AddressDO::getAddress) + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) + .eq(UserDO::getId, 1)); + page.getRecords().forEach(System.out::println); + } + + + /** + * 关联查询返回map + */ + @Test + void test7() { + List> list = userMapper.selectJoinMaps(MPJWrappers.lambdaJoin() + .selectAll(UserDO.class) + .select(AddressDO::getAddress) + .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) + .eq(UserDO::getId, 1)); + list.forEach(System.out::println); + } +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/MPJ131Test.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/MPJ131Test.java new file mode 100644 index 0000000..f273116 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/MPJ131Test.java @@ -0,0 +1,37 @@ +package com.github.yulichang.test; + +import com.github.yulichang.test.mapper.UserMapper; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; + +/** + * 测试 + */ +@SpringBootTest +@SuppressWarnings("unused") +class MPJ131Test { + @Resource + private UserMapper userMapper; + + /** + * 先明确 你要干啥? + * 在mapper中定义lambda形式的resultMap? + * 要解决问题 + * 1、只初始化了部分数据库实体类? NPE + *

+ * stater + * core + * anntion + * test + *

+ * 超高自由度的sql拼接器? + * 解决了自连接和子查询和各种函数 + * 如果底层调用MPJLambdaWrapper那样还有什么意义 + */ + @Test + void testJoin() { + System.out.println(1); + } +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/QueryWrapperTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/QueryWrapperTest.java new file mode 100644 index 0000000..6777132 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/QueryWrapperTest.java @@ -0,0 +1,85 @@ +package com.github.yulichang.test; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.query.MPJQueryWrapper; +import com.github.yulichang.test.dto.UserDTO; +import com.github.yulichang.test.entity.UserDO; +import com.github.yulichang.test.mapper.UserMapper; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +@SpringBootTest +class QueryWrapperTest { + @Resource + private UserMapper userMapper; + + /** + * 链表查询 + */ + @Test + void test1() { + UserDO userDO = userMapper.selectJoinOne(UserDO.class, new MPJQueryWrapper() + .selectAll(UserDO.class).last("LIMIT 1")); + System.out.println(userDO); + + UserDTO dto = userMapper.selectJoinOne(UserDTO.class, new MPJQueryWrapper() + .selectAll(UserDO.class) + .select("name AS nameName") + .last("LIMIT 1")); + System.out.println(dto); + } + + @Test + void test2() { + List userDO = userMapper.selectJoinList(UserDO.class, new MPJQueryWrapper() + .selectAll(UserDO.class) + .leftJoin("address t2 on t2.user_id = t.id") + .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)); + System.out.println(dto); + } + + @Test + void test3() { + IPage userDO = userMapper.selectJoinPage(new Page<>(1, 10), UserDO.class, new MPJQueryWrapper() + .selectAll(UserDO.class) + .leftJoin("address t2 on t2.user_id = t.id") + .lt("t.id ", 5)); + System.out.println(userDO); + + IPage dto = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class, new MPJQueryWrapper() + .selectAll(UserDO.class) + .select("t2.address AS userAddress") + .leftJoin("address t2 on t2.user_id = t.id") + .lt("t.id ", 5)); + System.out.println(dto); + } + + @Test + void test4() { + List> maps = userMapper.selectJoinMaps(new MPJQueryWrapper() + .selectAll(UserDO.class) + .leftJoin("address t2 on t2.user_id = t.id") + .lt("t.id ", 5)); + System.out.println(maps); + + List> joinMaps = userMapper.selectJoinMaps(new MPJQueryWrapper() + .selectAll(UserDO.class) + .select("t2.address AS userAddress") + .leftJoin("address t2 on t2.user_id = t.id") + .lt("t.id ", 5)); + System.out.println(joinMaps); + } + +} From f29655c2067c7509a12bbc176753f20e7d48034e Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 9 Nov 2022 13:21:07 +0800 Subject: [PATCH 04/23] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8C=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MybatisPlusJoinAutoConfiguration.java | 1 - mybatis-plus-join-test/pom.xml | 1 + .../java/com/github/yulichang/test/ListenerEvent.java | 11 ++++++----- .../src/main/resources/application.yml | 9 ++++++--- .../test/java/com/github/yulichang/test/JoinTest.java | 4 ++++ 5 files changed, 17 insertions(+), 9 deletions(-) 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 c15d33d..f1f52a2 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 @@ -55,7 +55,6 @@ public class MybatisPlusJoinAutoConfiguration { * mybatis plus join 拦截器 */ @Bean - @Order(Ordered.HIGHEST_PRECEDENCE) public MPJInterceptor mpjInterceptor() { return new MPJInterceptor(); } diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml index c4b642e..5342ae9 100644 --- a/mybatis-plus-join-test/pom.xml +++ b/mybatis-plus-join-test/pom.xml @@ -69,6 +69,7 @@ mybatis-plus-join-boot-starter 1.3.0 + com.github.pagehelper pagehelper-spring-boot-starter diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java index c07dd89..f161569 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java @@ -1,8 +1,8 @@ package com.github.yulichang.test; -import com.baomidou.mybatisplus.core.metadata.TableInfo; -import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.github.yulichang.test.mapper.UserMapper; +import com.zaxxer.hikari.HikariDataSource; +import org.apache.ibatis.session.SqlSessionFactory; import org.jetbrains.annotations.NotNull; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ApplicationContextEvent; @@ -10,18 +10,19 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.util.List; @Component @SuppressWarnings("unused") public class ListenerEvent implements ApplicationListener { - + @Resource + private HikariDataSource hikariDataSource; @Resource private UserMapper userMapper; + private SqlSessionFactory sqlSessionFactory; @PostConstruct public void init() { - List infos = TableInfoHelper.getTableInfos(); + System.out.println("1"); } @Override diff --git a/mybatis-plus-join-test/src/main/resources/application.yml b/mybatis-plus-join-test/src/main/resources/application.yml index ce7f946..2c33924 100644 --- a/mybatis-plus-join-test/src/main/resources/application.yml +++ b/mybatis-plus-join-test/src/main/resources/application.yml @@ -8,6 +8,8 @@ spring: init: schema-locations: classpath:db/schema.sql data-locations: classpath:db/data.sql + + mybatis-plus: global-config: db-config: @@ -15,8 +17,9 @@ mybatis-plus: logic-delete-value: true logic-not-delete-value: false banner: true -# configuration: -# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +# 打印 mybatis plus join banner mybatis-plus-join: - banner: false \ No newline at end of file + banner: true \ No newline at end of file diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java index 85bd43d..bde0395 100644 --- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java @@ -9,6 +9,7 @@ import com.github.yulichang.test.entity.UserDO; import com.github.yulichang.test.mapper.UserMapper; import com.github.yulichang.toolkit.MPJWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import org.apache.ibatis.session.SqlSessionFactory; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -25,9 +26,12 @@ import java.util.Map; * 移除了mybatis-plus 逻辑删除支持,逻辑删除需要在连表查询时自己添加对应的条件 */ @SpringBootTest +@SuppressWarnings("unused") class JoinTest { @Resource private UserMapper userMapper; + @Resource + private SqlSessionFactory sqlSessionFactory; /** * 一对多 From c2e9435744d07316ff5ea47900708d5857b15fbc Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 9 Nov 2022 22:44:56 +0800 Subject: [PATCH 05/23] 1.3.0 --- .../yulichang/query/MPJLambdaQueryWrapper.java | 6 +----- .../github/yulichang/toolkit/ReflectionKit.java | 17 ----------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJLambdaQueryWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJLambdaQueryWrapper.java index 6915ab1..f1d2ad7 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJLambdaQueryWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJLambdaQueryWrapper.java @@ -7,14 +7,10 @@ import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments; 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.ArrayUtils; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.*; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.github.yulichang.query.interfaces.MPJJoin; import com.github.yulichang.toolkit.Constant; -import org.springframework.util.Assert; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java index e7b663d..c681018 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java @@ -16,12 +16,10 @@ package com.github.yulichang.toolkit; import com.baomidou.mybatisplus.core.toolkit.Assert; -import com.baomidou.mybatisplus.core.toolkit.ClassUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils; import org.apache.ibatis.logging.Log; import org.apache.ibatis.logging.LogFactory; -import org.springframework.core.GenericTypeResolver; import java.lang.reflect.*; import java.util.*; @@ -85,21 +83,6 @@ public final class ReflectionKit { } } - /** - *

- * 反射对象获取泛型 - *

- * - * @param clazz 对象 - * @param genericIfc 所属泛型父类 - * @param index 泛型所在位置 - * @return Class - */ - public static Class getSuperClassGenericType(final Class clazz, final Class genericIfc, final int index) { - Class[] typeArguments = GenericTypeResolver.resolveTypeArguments(ClassUtils.getUserClass(clazz), genericIfc); - return null == typeArguments ? null : typeArguments[index]; - } - /** * Collection字段的泛型 From 2af3e6b7ba3fcca698d8b726e0abf7a35ab8e086 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Thu, 10 Nov 2022 18:11:18 +0800 Subject: [PATCH 06/23] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8C=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mybatis-plus-join-boot-starter/pom.xml | 2 +- mybatis-plus-join-core/pom.xml | 2 +- .../yulichang/interceptor/MPJInterceptor.java | 21 ++++++++++++------- pom.xml | 4 +++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/mybatis-plus-join-boot-starter/pom.xml b/mybatis-plus-join-boot-starter/pom.xml index f5de497..d4fbc88 100644 --- a/mybatis-plus-join-boot-starter/pom.xml +++ b/mybatis-plus-join-boot-starter/pom.xml @@ -42,7 +42,7 @@ com.github.yulichang mybatis-plus-join-core - 1.3.0 + ${mybaits-plus-join.version} diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml index cc6a216..164d398 100644 --- a/mybatis-plus-join-core/pom.xml +++ b/mybatis-plus-join-core/pom.xml @@ -43,7 +43,7 @@ com.github.yulichang mybatis-plus-join-annotation - 1.3.0 + ${mybaits-plus-join.version} \ No newline at end of file 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 d2f5363..18c4e81 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 @@ -161,7 +161,7 @@ public class MPJInterceptor implements Interceptor { //移除对多查询列,为了可重复使用wrapper columnList.removeIf(SelectColumn::isLabel); List resultMappings = new ArrayList<>(columnList.size()); - columnList.forEach(i -> { + for (SelectColumn i : columnList) { TableFieldInfo info = i.getTableFieldInfo(); if (StringUtils.isNotBlank(i.getAlias())) { //优先别名查询 selectFunc selectAs @@ -180,23 +180,27 @@ public class MPJInterceptor implements Interceptor { // select selectAll selectAsClass if (i.getFuncEnum() == null || StringUtils.isBlank(i.getFuncEnum().getSql())) { ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), info.getProperty(), - info.getColumn(), info.getPropertyType()); + StringUtils.getTargetColumn(info.getColumn()), info.getPropertyType()); if (info.getTypeHandler() != null && info.getTypeHandler() != UnknownTypeHandler.class) { Field f = fieldMap.get(info.getProperty()); - if (f != null && f.getType() == info.getField().getType()) { + if (f == null) { + continue; + } + if (f.getType() == info.getField().getType()) { builder.typeHandler(getTypeHandler(ms, info)); } } resultMappings.add(builder.build()); } else { - resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), info.getProperty(), info.getColumn(), info.getPropertyType()).build()); + resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), info.getProperty(), + StringUtils.getTargetColumn(info.getColumn()), info.getPropertyType()).build()); } } else { // 主键列 - resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), i.getTagProperty(), i.getColumnName(), - i.getKeyType()).build()); + resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), i.getTagProperty(), + StringUtils.getTargetColumn(i.getColumnName()), i.getKeyType()).build()); } - }); + } Set columnSet = resultMappings.stream().map(ResultMapping::getColumn).collect(Collectors.toSet()); //移除result中不存在的标签 resultMappings.removeIf(i -> !fieldMap.containsKey(i.getProperty())); @@ -214,7 +218,8 @@ public class MPJInterceptor implements Interceptor { columnName = getColumn(columnSet, columnName); columnList.add(SelectColumn.of(mpjColl.getEntityClass(), r.getColumn(), null, Objects.equals(columnName, r.getColumn()) ? null : columnName, null, null, true, null)); - ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), columnName, r.getJavaType()); + ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), + StringUtils.getTargetColumn(columnName), r.getJavaType()); if (r.isId()) {//主键标记为id标签 builder.flags(Collections.singletonList(ResultFlag.ID)); } diff --git a/pom.xml b/pom.xml index 41cc966..c76f495 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.yulichang mybatis-plus-join-root pom - 1.3.0 + ${mybaits-plus-join.version} mybatis-plus-join-root An enhanced toolkit of Mybatis-Plus to simplify development. @@ -37,6 +37,8 @@ + 1.3.0 + UTF-8 github 1.8 From 8812da14ee891b688324f9e254a8945876dbd134 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Sat, 12 Nov 2022 01:51:49 +0800 Subject: [PATCH 07/23] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=8C=96=202.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +-- mybatis-plus-join-annotation/pom.xml | 17 +++++-- mybatis-plus-join-boot-starter/pom.xml | 24 ++++++--- .../MybatisPlusJoinAutoConfiguration.java | 51 ++++++++++++++----- mybatis-plus-join-core/pom.xml | 28 ++++++++-- .../yulichang/config/InterceptorConfig.java | 2 +- .../yulichang/config/MappingConfig.java | 9 ++-- .../yulichang/injector/MPJSqlInjector.java | 7 ++- .../yulichang/mapper/MPJTableFieldInfo.java | 2 +- .../yulichang/toolkit/SpringContentUtils.java | 22 ++++---- mybatis-plus-join-test/pom.xml | 18 +++++-- pom.xml | 24 +++------ 12 files changed, 134 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index a2eb8e4..2931923 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,13 @@ QQ群:1022221898 ```xml com.github.yulichang - mybatis-plus-join - 1.3.0 + mybatis-plus-join-boot-starter + 2.0.0 ``` - Gradle ``` - implementation 'com.github.yulichang:mybatis-plus-join:1.3.0' + implementation 'com.github.yulichang:mybatis-plus-join-boot-starter:2.0.0' ``` 或者clone代码到本地执行 mvn install, 再引入以上依赖
diff --git a/mybatis-plus-join-annotation/pom.xml b/mybatis-plus-join-annotation/pom.xml index fe7ac02..d662729 100644 --- a/mybatis-plus-join-annotation/pom.xml +++ b/mybatis-plus-join-annotation/pom.xml @@ -6,7 +6,7 @@ com.github.yulichang mybatis-plus-join-root - 1.3.0 + 2.0.0 mybatis-plus-join-annotation mybatis-plus-join-annotation @@ -33,9 +33,20 @@ - 8 - 8 + 1.8 + 1.8 + 1.8 + 1.8 + github UTF-8 + + + com.baomidou + mybatis-plus-core + ${mybatis-plus.version} + provided + + \ No newline at end of file diff --git a/mybatis-plus-join-boot-starter/pom.xml b/mybatis-plus-join-boot-starter/pom.xml index d4fbc88..a5eb38b 100644 --- a/mybatis-plus-join-boot-starter/pom.xml +++ b/mybatis-plus-join-boot-starter/pom.xml @@ -6,7 +6,7 @@ com.github.yulichang mybatis-plus-join-root - 1.3.0 + 2.0.0 mybatis-plus-join-boot-starter mybatis-plus-join-boot-starter @@ -33,8 +33,11 @@ - 8 - 8 + 1.8 + 1.8 + 1.8 + 1.8 + github UTF-8 @@ -44,14 +47,23 @@ mybatis-plus-join-core ${mybaits-plus-join.version}
- org.springframework.boot spring-boot-configuration-processor true 2.7.5 + + com.baomidou + mybatis-plus-boot-starter + ${mybatis-plus.version} + provided + + + org.projectlombok + lombok + ${lombok.version} + provided + - - \ No newline at end of file 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 f1f52a2..6940776 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 @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector; import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; import com.baomidou.mybatisplus.core.injector.ISqlInjector; import com.github.yulichang.config.InterceptorConfig; -import com.github.yulichang.config.MappingConfig; import com.github.yulichang.injector.MPJSqlInjector; import com.github.yulichang.interceptor.MPJInterceptor; import com.github.yulichang.toolkit.SpringContentUtils; @@ -13,13 +12,18 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; @@ -78,24 +82,43 @@ public class MybatisPlusJoinAutoConfiguration { return new MPJSqlInjector(); } - /** - * 多表查询注解 - * - * @deprecated - */ - @Bean - @Order(Ordered.HIGHEST_PRECEDENCE) - public MappingConfig mappingConfig() { - return new MappingConfig(); - } - /** * springboot content 工具类 */ @Bean @Order(Ordered.HIGHEST_PRECEDENCE) - public SpringContentUtils springContentUtils() { - return new SpringContentUtils(); + @SuppressWarnings("InstantiationOfUtilityClass") + public SpringContentUtils springContentUtils(SpringContext springContext) { + return new SpringContentUtils(springContext); + } + + @Configuration + @Order(Ordered.HIGHEST_PRECEDENCE) + @ConditionalOnBean(SqlSessionFactory.class) + public static class MappingConfig implements ApplicationListener { + @Override + @SuppressWarnings("NullableProblems") + public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) { + new com.github.yulichang.config.MappingConfig(); + } + } + + @Configuration + @ConditionalOnBean(SqlSessionFactory.class) + public static class SpringContext implements SpringContentUtils.SpringContext, ApplicationContextAware { + + private ApplicationContext applicationContext; + + @Override + public T getBean(Class clazz) { + return this.applicationContext.getBean(clazz); + } + + @Override + @SuppressWarnings("NullableProblems") + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } } } diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml index 164d398..cbf88f2 100644 --- a/mybatis-plus-join-core/pom.xml +++ b/mybatis-plus-join-core/pom.xml @@ -6,7 +6,7 @@ com.github.yulichang mybatis-plus-join-root - 1.3.0 + 2.0.0 mybatis-plus-join-core mybatis-plus-join-core @@ -32,10 +32,12 @@ https://github.com/yulichang/mybatis-plus-join - - 8 - 8 + 1.8 + 1.8 + 1.8 + 1.8 + github UTF-8 @@ -45,5 +47,23 @@ mybatis-plus-join-annotation ${mybaits-plus-join.version} + + com.baomidou + mybatis-plus-extension + ${mybatis-plus.version} + provided + + + org.projectlombok + lombok + ${lombok.version} + provided + + + org.springframework + spring-aop + 5.3.23 + provided + \ No newline at end of file diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java index 6bb41b1..ad1b06b 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java @@ -28,7 +28,7 @@ public class InterceptorConfig { //打印banner System.out.println(" _ _ |_ _ _|_. ___ _ | _ . _ . _ \n" + "| | |\\/|_)(_| | |_\\ |_)||_|_\\ | (_) | | | \n" + - " / | / 1.3.0"); + " / | / 2.0.0"); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java index 0012a1a..3d8d63e 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MappingConfig.java @@ -3,8 +3,6 @@ package com.github.yulichang.config; import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.github.yulichang.mapper.MPJTableMapperHelper; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.ApplicationListener; /** * 关系映射配置 @@ -12,12 +10,11 @@ import org.springframework.context.ApplicationListener; * @author yulichang * @since 1.2.0 */ -public class MappingConfig implements ApplicationListener { +public class MappingConfig { - @Override - @SuppressWarnings("NullableProblems") - public void onApplicationEvent(ApplicationReadyEvent event) { + public MappingConfig() { TableInfoHelper.getTableInfos().forEach(i -> MPJTableInfoHelper.initTableInfo(i.getEntityType(), MPJTableMapperHelper.get(i.getEntityType()))); } + } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java index 58e7ee8..9056174 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/injector/MPJSqlInjector.java @@ -28,9 +28,6 @@ import static java.util.stream.Collectors.toList; */ public class MPJSqlInjector extends DefaultSqlInjector { - private static final List METHOD_LIST = Arrays.asList("SelectOne", "SelectCount", - "SelectMaps", "SelectMapsPage", "SelectObjs", "SelectList", "SelectPage"); - /** * 升级到 mybatis plus 3.4.3.2 后对之前的版本兼容 @@ -59,8 +56,10 @@ public class MPJSqlInjector extends DefaultSqlInjector { */ @Override public List getMethodList(Class mapperClass, TableInfo tableInfo) { + List methodList = Arrays.asList("SelectOne", "SelectCount", + "SelectMaps", "SelectMapsPage", "SelectObjs", "SelectList", "SelectPage"); List list = super.getMethodList(mapperClass, tableInfo); - list.removeIf(i -> METHOD_LIST.contains(i.getClass().getSimpleName())); + list.removeIf(i -> methodList.contains(i.getClass().getSimpleName())); list.addAll(getSelectMethod()); list.addAll(getJoinMethod()); return list; diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableFieldInfo.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableFieldInfo.java index dfef2dd..5d0b036 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableFieldInfo.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/mapper/MPJTableFieldInfo.java @@ -279,7 +279,7 @@ public class MPJTableFieldInfo { if (joinTableInfo == null) { throw new MPJException("未注册 mapper " + this.joinClass.getName()); } - this.joinMapper = (BaseMapper) SpringContentUtils.getApplicationContext().getBean(joinTableInfo.getMapperClass()); + this.joinMapper = (BaseMapper) SpringContentUtils.getBean(joinTableInfo.getMapperClass()); } return this.joinMapper; } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/SpringContentUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/SpringContentUtils.java index a66a235..7067b9b 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/SpringContentUtils.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/SpringContentUtils.java @@ -1,8 +1,5 @@ package com.github.yulichang.toolkit; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; /** * spring容器工具类 @@ -10,17 +7,20 @@ import org.springframework.context.ApplicationContextAware; * @author yulichang * @since 1.2.0 */ -public class SpringContentUtils implements ApplicationContextAware { +public class SpringContentUtils { - private static ApplicationContext context; + private static SpringContext springContext; - @Override - @SuppressWarnings("NullableProblems") - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - context = applicationContext; + public SpringContentUtils(SpringContext springContext) { + SpringContentUtils.springContext = springContext; } - public static ApplicationContext getApplicationContext() { - return context; + public static T getBean(Class clazz) { + return SpringContentUtils.springContext.getBean(clazz); + } + + public interface SpringContext { + + T getBean(Class clazz); } } diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml index 5342ae9..fc888f6 100644 --- a/mybatis-plus-join-test/pom.xml +++ b/mybatis-plus-join-test/pom.xml @@ -7,7 +7,7 @@ com.github.yulichang mybatis-plus-join-root - 1.3.0 + 2.0.0 mybatis-plus-join-test mybatis-plus-join-test @@ -36,8 +36,11 @@ 2.5.4 - 8 - 8 + 1.8 + 1.8 + 1.8 + 1.8 + github UTF-8 @@ -62,12 +65,17 @@ org.projectlombok lombok - 1.18.24 + ${lombok.version} + + + com.baomidou + mybatis-plus-boot-starter + ${mybatis-plus.version} com.github.yulichang mybatis-plus-join-boot-starter - 1.3.0 + ${mybaits-plus-join.version} diff --git a/pom.xml b/pom.xml index c76f495..f7a7274 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.yulichang mybatis-plus-join-root pom - ${mybaits-plus-join.version} + 2.0.0 mybatis-plus-join-root An enhanced toolkit of Mybatis-Plus to simplify development. @@ -37,31 +37,19 @@ - 1.3.0 + 2.0.0 + 3.5.2 + 1.18.24 - UTF-8 - github 1.8 1.8 - 1.8 1.8 + github + UTF-8 - - - com.baomidou - mybatis-plus-boot-starter - 3.5.2 - provided - - - org.projectlombok - lombok - 1.18.24 - provided - From 4426d1787b56edacc945a60d0aae4c7d1a23f2e3 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Tue, 15 Nov 2022 10:11:57 +0800 Subject: [PATCH 08/23] =?UTF-8?q?=E5=AF=B9=E4=B8=80=E5=92=8C=E5=AF=B9?= =?UTF-8?q?=E5=A4=9A=E6=94=AF=E6=8C=81=E5=B5=8C=E5=A5=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MybatisPlusJoinAutoConfiguration.java | 4 +- .../MybatisPlusJoinProperties.java | 4 +- mybatis-plus-join-core/pom.xml | 1 + .../yulichang/interceptor/MPJInterceptor.java | 91 +++++++++------- .../yulichang/wrapper/MPJLambdaWrapper.java | 16 +-- .../wrapper/resultmap/LabelType.java | 5 - .../wrapper/resultmap/MybatisLabel.java | 102 ++++++++++++++++-- mybatis-plus-join-test/pom.xml | 5 + .../github/yulichang/test/dto/AddressDTO.java | 26 +++++ .../github/yulichang/test/dto/AreaDTO.java | 27 +++++ .../github/yulichang/test/dto/UserDTO.java | 6 +- .../github/yulichang/test/entity/UserDO.java | 9 +- .../src/main/resources/db/data.sql | 44 ++++---- .../{JoinTest.java => LambdaWrapperTest.java} | 8 +- .../com/github/yulichang/test/MPJ131Test.java | 37 ------- 15 files changed, 255 insertions(+), 130 deletions(-) delete mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/LabelType.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AddressDTO.java create mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AreaDTO.java rename mybatis-plus-join-test/src/test/java/com/github/yulichang/test/{JoinTest.java => LambdaWrapperTest.java} (94%) delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/MPJ131Test.java 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 6940776..e203d8b 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 @@ -33,8 +33,10 @@ import javax.sql.DataSource; import java.util.List; /** + * springboot 自动配置类 + * * @author yulichang - * @since 1.3.2 + * @since 2.0.0 */ @SuppressWarnings("unused") @Configuration(proxyBeanMethods = false) diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java index 054835a..bb23df8 100644 --- a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java +++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java @@ -5,8 +5,10 @@ import lombok.experimental.Accessors; import org.springframework.boot.context.properties.ConfigurationProperties; /** + * 配置类 + * * @author yulichang - * @since 1.3.2 + * @since 2.0.0 */ @Data @Accessors(chain = true) diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml index cbf88f2..d202a4e 100644 --- a/mybatis-plus-join-core/pom.xml +++ b/mybatis-plus-join-core/pom.xml @@ -1,4 +1,5 @@ + 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 94a860d..067353d 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 @@ -209,45 +209,57 @@ public class MPJInterceptor implements Interceptor { //移除result中不存在的标签 resultMappings.removeIf(i -> !fieldMap.containsKey(i.getProperty())); if (wrapper.isResultMap()) { - List> mybatisLabel = wrapper.getResultMapMybatisLabel(); - for (MybatisLabel mpjColl : mybatisLabel) { - List list = mpjColl.getResultList(); - if (CollectionUtils.isEmpty(list)) { - continue; - } - List childMapping = new ArrayList<>(list.size()); - for (Result r : list) { - String columnName = r.getColumn(); - //列名去重 - columnName = getColumn(columnSet, columnName); - columnList.add(SelectColumn.of(mpjColl.getEntityClass(), r.getColumn(), null, - Objects.equals(columnName, r.getColumn()) ? null : columnName, null, null, true, null)); - ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), - StringUtils.getTargetColumn(columnName), r.getJavaType()); - if (r.isId()) {//主键标记为id标签 - builder.flags(Collections.singletonList(ResultFlag.ID)); - } - childMapping.add(builder.build()); - } - String childId = id + StringPool.UNDERSCORE + mpjColl.getEntityClass().getName() + StringPool.UNDERSCORE + - mpjColl.getOfType().getName() + StringPool.UNDERSCORE + mpjColl.getLabelType() + StringPool.UNDERSCORE + - childMapping.stream().map(i -> (CollectionUtils.isEmpty(i.getFlags()) ? ResultFlag.CONSTRUCTOR : - i.getFlags().get(0)) + i.getProperty() + i.getColumn()).collect(Collectors.joining(StringPool.DASH)); - resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), mpjColl.getProperty()) - .javaType(mpjColl.getJavaType()) - .nestedResultMapId(childId) - .build()); - //双检 - if (!ms.getConfiguration().getResultMapNames().contains(childId)) { - ResultMap build = new ResultMap.Builder(ms.getConfiguration(), childId, mpjColl.getOfType(), childMapping).build(); - MPJInterceptor.addResultMap(ms, childId, build); - } - } + buildResult(ms, wrapper.getResultMapMybatisLabel(), columnSet, resultMappings, columnList); } result.add(new ResultMap.Builder(ms.getConfiguration(), id, resultType, resultMappings).build()); return result; } + private void buildResult(MappedStatement ms, List> mybatisLabel, Set columnSet, + List parentMappings, List columnList) { + for (MybatisLabel mpjColl : mybatisLabel) { + List list = mpjColl.getResultList(); + if (CollectionUtils.isEmpty(list)) { + continue; + } + List childMapping = new ArrayList<>(list.size()); + for (Result r : list) { + String columnName = r.getColumn(); + //列名去重 + columnName = getColumn(columnSet, columnName); + columnList.add(SelectColumn.of(mpjColl.getEntityClass(), r.getColumn(), null, + Objects.equals(columnName, r.getColumn()) ? null : columnName, null, null, true, null)); + ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), + StringUtils.getTargetColumn(columnName), r.getJavaType()); + if (r.isId()) {//主键标记为id标签 + builder.flags(Collections.singletonList(ResultFlag.ID)); + } + //TypeHandle + TableFieldInfo info = r.getTableFieldInfo(); + if (info != null && info.getTypeHandler() != null && info.getTypeHandler() != UnknownTypeHandler.class) { + builder.typeHandler(getTypeHandler(ms, info)); + } + childMapping.add(builder.build()); + } + //嵌套处理 + if (CollectionUtils.isNotEmpty(mpjColl.getMybatisLabels())) { + this.buildResult(ms, mpjColl.getMybatisLabels(), columnSet, childMapping, columnList); + } + String childId = "MPJ_" + mpjColl.getEntityClass().getName() + StringPool.UNDERSCORE + mpjColl.getOfType().getName() + + StringPool.UNDERSCORE + childMapping.stream().map(i -> (CollectionUtils.isEmpty(i.getFlags()) ? + ResultFlag.CONSTRUCTOR : i.getFlags().get(0)) + i.getProperty() + i.getColumn()).collect(Collectors.joining(StringPool.DASH)); + parentMappings.add(new ResultMapping.Builder(ms.getConfiguration(), mpjColl.getProperty()) + .javaType(mpjColl.getJavaType()) + .nestedResultMapId(childId) + .build()); + //双检 + if (!ms.getConfiguration().getResultMapNames().contains(childId)) { + ResultMap build = new ResultMap.Builder(ms.getConfiguration(), childId, mpjColl.getOfType(), childMapping).build(); + MPJInterceptor.addResultMap(ms, childId, build); + } + } + } + /** * 获取字段typeHandle */ @@ -268,12 +280,13 @@ public class MPJInterceptor implements Interceptor { * @return 唯一列名 */ private String getColumn(Set pool, String columnName) { - if (!pool.contains(columnName)) { - pool.add(columnName); - return columnName; + String tagName = StringUtils.getTargetColumn(columnName); + if (!pool.contains(tagName)) { + pool.add(tagName); + return tagName; } - columnName = "mpj_" + StringUtils.getTargetColumn(columnName); - return getColumn(pool, columnName); + tagName = "mpj_" + tagName; + return getColumn(pool, tagName); } /** diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java index 1fba22e..bbadbb7 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java @@ -11,14 +11,16 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.github.yulichang.exception.MPJException; -import com.github.yulichang.toolkit.*; +import com.github.yulichang.toolkit.Constant; +import com.github.yulichang.toolkit.LambdaUtils; +import com.github.yulichang.toolkit.MPJWrappers; +import com.github.yulichang.toolkit.ReflectionKit; import com.github.yulichang.toolkit.support.ColumnCache; import com.github.yulichang.toolkit.support.SelectColumn; import com.github.yulichang.wrapper.enums.BaseFuncEnum; import com.github.yulichang.wrapper.interfaces.LambdaJoin; import com.github.yulichang.wrapper.interfaces.Query; import com.github.yulichang.wrapper.interfaces.on.OnFunction; -import com.github.yulichang.wrapper.resultmap.LabelType; import com.github.yulichang.wrapper.resultmap.MFunc; import com.github.yulichang.wrapper.resultmap.MybatisLabel; import lombok.Getter; @@ -182,13 +184,13 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper builder; if (genericType == null || genericType.isAssignableFrom(child)) { //找不到集合泛型 List List List , 直接查询数据库实体 - builder = new MybatisLabel.Builder<>(LabelType.COLLECTION, dtoFieldName, child, field.getType()); + builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType()); } else { Class ofType = (Class) genericType; if (ReflectionKit.isPrimitiveOrWrapper(ofType)) { throw new MPJException("collection 不支持基本数据类型"); } - builder = new MybatisLabel.Builder<>(LabelType.COLLECTION, dtoFieldName, child, field.getType(), ofType, true); + builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), ofType, true); } this.resultMapMybatisLabel.add(builder.build()); return typedThis; @@ -231,7 +233,7 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper genericType = ReflectionKit.getGenericType(field); Class ofType = (Class) genericType; - MybatisLabel.Builder builder = new MybatisLabel.Builder<>(LabelType.COLLECTION, dtoFieldName, child, field.getType(), ofType, false); + MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), ofType, false); this.resultMapMybatisLabel.add(collection.apply(builder).build()); return typedThis; } @@ -252,7 +254,7 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper builder; - builder = new MybatisLabel.Builder<>(LabelType.ASSOCIATION, dtoFieldName, child, field.getType(), (Class) field.getType(), true); + builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) field.getType(), true); this.resultMapMybatisLabel.add(builder.build()); return typedThis; } @@ -272,7 +274,7 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper builder = new MybatisLabel.Builder<>(LabelType.ASSOCIATION, dtoFieldName, child, field.getType(), (Class) child, false); + MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) child, false); this.resultMapMybatisLabel.add(collection.apply(builder).build()); return typedThis; } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/LabelType.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/LabelType.java deleted file mode 100644 index 6d33b2a..0000000 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/LabelType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.yulichang.wrapper.resultmap; - -public enum LabelType { - COLLECTION, ASSOCIATION -} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java index f8de60e..59d2093 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java @@ -3,12 +3,17 @@ package com.github.yulichang.wrapper.resultmap; 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.Assert; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.github.yulichang.exception.MPJException; +import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.ReflectionKit; import lombok.Getter; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -23,8 +28,6 @@ import java.util.stream.Collectors; @Getter public class MybatisLabel { - private LabelType labelType; - private String property; private Class entityClass; @@ -35,13 +38,15 @@ public class MybatisLabel { private List resultList; - //collection嵌套 - // private List collectionList; + /** + * wrapper里面的引用 + */ + private List> mybatisLabels; private MybatisLabel() { } - @SuppressWarnings("unused") + @SuppressWarnings({"unused", "unchecked"}) public static class Builder { private final MybatisLabel mybatisLabel; @@ -50,14 +55,14 @@ public class MybatisLabel { * 自动构建 */ @SuppressWarnings("unchecked") - public Builder(LabelType labelType, String property, Class entityClass, Class javaType) { + public Builder(String property, Class entityClass, Class javaType) { this.mybatisLabel = new MybatisLabel<>(); - mybatisLabel.labelType = labelType; mybatisLabel.property = property; mybatisLabel.entityClass = entityClass; mybatisLabel.javaType = javaType; mybatisLabel.ofType = (Class) entityClass; mybatisLabel.resultList = new ArrayList<>(); + mybatisLabel.mybatisLabels = new ArrayList<>(); autoBuild(true, entityClass, (Class) entityClass); } @@ -70,14 +75,14 @@ public class MybatisLabel { * @param ofType 映射类 * @param auto 自动映射数据库实体对应的字段 */ - public Builder(LabelType labelType, String property, Class entityClass, Class javaType, Class ofType, boolean auto) { + public Builder(String property, Class entityClass, Class javaType, Class ofType, boolean auto) { this.mybatisLabel = new MybatisLabel<>(); - mybatisLabel.labelType = labelType; mybatisLabel.property = property; mybatisLabel.entityClass = entityClass; mybatisLabel.javaType = javaType; mybatisLabel.ofType = ofType; mybatisLabel.resultList = new ArrayList<>(); + mybatisLabel.mybatisLabels = new ArrayList<>(); autoBuild(auto, entityClass, ofType); } @@ -109,7 +114,85 @@ public class MybatisLabel { return this; } + /** + * 嵌套 + */ + public > Builder collection(Class entityClass, SFunction func) { + String dtoFieldName = LambdaUtils.getName(func); + Class dtoClass = LambdaUtils.getEntityClass(func); + Map fieldMap = ReflectionKit.getFieldMap(dtoClass); + Field field = fieldMap.get(dtoFieldName); + Class genericType = ReflectionKit.getGenericType(field); + MybatisLabel.Builder builder; + if (genericType == null || genericType.isAssignableFrom(entityClass)) { + //找不到集合泛型 List List List , 直接查询数据库实体 + builder = new Builder<>(dtoFieldName, entityClass, field.getType()); + } else { + Class ofType = (Class) genericType; + if (ReflectionKit.isPrimitiveOrWrapper(ofType)) { + throw new MPJException("collection 不支持基本数据类型"); + } + builder = new Builder<>(dtoFieldName, entityClass, field.getType(), ofType, true); + } + mybatisLabel.mybatisLabels.add(builder.build()); + return this; + } + + /** + * 嵌套 + */ + public > Builder collection(Class entityClass, SFunction func, MFunc> mFunc) { + String dtoFieldName = LambdaUtils.getName(func); + Class dtoClass = LambdaUtils.getEntityClass(func); + Field field = ReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); + //获取集合泛型 + Class genericType = ReflectionKit.getGenericType(field); + Class ofType = (Class) genericType; + MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, entityClass, field.getType(), ofType, false); + mybatisLabel.mybatisLabels.add(mFunc.apply(builder).build()); + return this; + } + + /** + * 嵌套 + */ + public Builder association(Class child, SFunction dtoField) { + Class dtoClass = LambdaUtils.getEntityClass(dtoField); + Map fieldMap = ReflectionKit.getFieldMap(dtoClass); + String dtoFieldName = LambdaUtils.getName(dtoField); + Field field = fieldMap.get(dtoFieldName); + Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); + if (ReflectionKit.isPrimitiveOrWrapper(field.getType())) { + throw new MPJException("association 不支持基本数据类型"); + } + MybatisLabel.Builder builder; + builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) field.getType(), true); + mybatisLabel.mybatisLabels.add(builder.build()); + return this; + } + + /** + * 嵌套 + */ + public Builder selectAssociation(Class child, SFunction dtoField, + MFunc> collection) { + String dtoFieldName = LambdaUtils.getName(dtoField); + Class dtoClass = LambdaUtils.getEntityClass(dtoField); + Field field = ReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); + Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); + if (ReflectionKit.isPrimitiveOrWrapper(field.getType())) { + throw new MPJException("association 不支持基本数据类型"); + } + MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) child, false); + mybatisLabel.mybatisLabels.add(collection.apply(builder).build()); + return this; + } + + public MybatisLabel build() { + if (CollectionUtils.isEmpty(mybatisLabel.resultList)) { + autoBuild(true, mybatisLabel.entityClass, mybatisLabel.ofType); + } return mybatisLabel; } @@ -120,6 +203,7 @@ public class MybatisLabel { Function build = field -> { Result result = new Result(); result.setId(false); + result.setTableFieldInfo(field); result.setColumn(field.getColumn()); result.setProperty(field.getProperty()); result.setJavaType(field.getField().getType()); diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml index fc888f6..3317236 100644 --- a/mybatis-plus-join-test/pom.xml +++ b/mybatis-plus-join-test/pom.xml @@ -83,6 +83,11 @@ pagehelper-spring-boot-starter 1.4.5 + + com.fasterxml.jackson.core + jackson-databind + 2.14.0 + \ No newline at end of file diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AddressDTO.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AddressDTO.java new file mode 100644 index 0000000..e516ebf --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AddressDTO.java @@ -0,0 +1,26 @@ +package com.github.yulichang.test.dto; + +import com.github.yulichang.test.entity.AreaDO; +import lombok.Data; + +import java.util.List; + +@Data +public class AddressDTO { + + private Integer id; + + private Integer userId; + + private Integer areaId; + + private String tel; + + private String address; + + private Boolean del; + + private List areaList; + + private AreaDO area; +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AreaDTO.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AreaDTO.java new file mode 100644 index 0000000..ba2ad34 --- /dev/null +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AreaDTO.java @@ -0,0 +1,27 @@ +package com.github.yulichang.test.dto; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@Data +@ToString +@Accessors(chain = true) +@EqualsAndHashCode +@TableName("area") +public class AreaDTO { + + private Integer id; + + private String province; + + private String city; + + private String area; + + private String postcode; + + private Boolean del; +} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java index 67a3ef9..82b5d62 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java @@ -1,11 +1,11 @@ package com.github.yulichang.test.dto; -import com.github.yulichang.test.entity.AddressDO; import com.github.yulichang.test.enums.Sex; import lombok.Data; import lombok.ToString; import java.util.List; +import java.util.Map; /** @@ -17,7 +17,7 @@ public class UserDTO { /** user */ private Integer id; /** user */ - private String nameName; + private Map name; /** user */ private Sex sex; /** user */ @@ -37,5 +37,5 @@ public class UserDTO { /** area */ private String area; - private List addressList; + private List addressList; } diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java index ecb05a3..309b873 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java +++ b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java @@ -4,24 +4,27 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import com.github.yulichang.test.enums.Sex; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.experimental.Accessors; +import java.util.Map; + @Data @ToString @Accessors(chain = true) @EqualsAndHashCode -@TableName("`user`") +@TableName(value = "`user`",autoResultMap = true) public class UserDO { @TableId private Integer id; - @TableField("name") - private String sdafrrvnbioiure; + @TableField(value = "`name`", typeHandler = JacksonTypeHandler.class) + private Map name; private Sex sex; diff --git a/mybatis-plus-join-test/src/main/resources/db/data.sql b/mybatis-plus-join-test/src/main/resources/db/data.sql index 19f1926..2f8baa0 100644 --- a/mybatis-plus-join-test/src/main/resources/db/data.sql +++ b/mybatis-plus-join-test/src/main/resources/db/data.sql @@ -29,28 +29,28 @@ INSERT INTO area (id, province, city, area, postcode, del) VALUES (10022, '北 DELETE FROM `user`; -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 1, '张三01', 1, 1, 'https://url-01', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 2, '李四02', 1, 0, 'https://url-02', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 3, '李四02', 1, 0, 'https://url-03', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 4, '李四04', 1, 0, 'https://url-04', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 5, '李四05', 1, 0, 'https://url-05', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 6, '李四06', 1, 0, 'https://url-06', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 7, '李四07', 1, 0, 'https://url-07', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 8, '李四08', 1, 0, 'https://url-08', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 9, '李四09', 1, 0, 'https://url-09', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (10, '李四10', 1, 0, 'https://url-10', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (11, '李四11', 1, 0, 'https://url-11', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (12, '李四12', 1, 0, 'https://url-12', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (13, '李四13', 1, 0, 'https://url-13', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (14, '李四14', 1, 0, 'https://url-14', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (15, '李四15', 1, 0, 'https://url-15', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (16, '李四16', 1, 0, 'https://url-16', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (17, '李四17', 1, 0, 'https://url-17', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (18, '李四18', 1, 0, 'https://url-18', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (19, '李四19', 1, 0, 'https://url-19', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (20, '李四20', 1, 0, 'https://url-20', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (21, '李四21', 1, 0, 'https://url-21', false); -INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (22, '李四22', 1, 0, 'https://url-22', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 1, '{"aa":"aaa","bb":"bbb"}', 1, 1, 'https://url-01', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 2, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-02', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 3, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-03', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 4, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-04', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 5, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-05', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 6, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-06', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 7, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-07', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 8, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-08', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES ( 9, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-09', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (10, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-10', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (11, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-11', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (12, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-12', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (13, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-13', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (14, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-14', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (15, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-15', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (16, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-16', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (17, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-17', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (18, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-18', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (19, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-19', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (20, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-20', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (21, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-21', false); +INSERT INTO `user` (id, `name`, `address_id`, sex, head_img, del) VALUES (22, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-22', false); DELETE FROM address; diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/LambdaWrapperTest.java similarity index 94% rename from mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/LambdaWrapperTest.java index bde0395..798c61a 100644 --- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/JoinTest.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/LambdaWrapperTest.java @@ -2,6 +2,7 @@ package com.github.yulichang.test; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.test.dto.AddressDTO; import com.github.yulichang.test.dto.UserDTO; import com.github.yulichang.test.entity.AddressDO; import com.github.yulichang.test.entity.AreaDO; @@ -27,7 +28,7 @@ import java.util.Map; */ @SpringBootTest @SuppressWarnings("unused") -class JoinTest { +class LambdaWrapperTest { @Resource private UserMapper userMapper; @Resource @@ -40,10 +41,11 @@ class JoinTest { void testJoin() { MPJLambdaWrapper wrapper = new MPJLambdaWrapper() .selectAll(UserDO.class) - .selectCollection(AddressDO.class, UserDTO::getAddressList) + .selectCollection(AddressDO.class, UserDTO::getAddressList, addr -> addr + .association(AreaDO.class, AddressDTO::getArea)) .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId) + .leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId) .orderByDesc(UserDO::getId); - List list = userMapper.selectJoinList(UserDTO.class, wrapper); list.forEach(System.out::println); } diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/MPJ131Test.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/MPJ131Test.java deleted file mode 100644 index f273116..0000000 --- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/MPJ131Test.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.yulichang.test; - -import com.github.yulichang.test.mapper.UserMapper; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -import javax.annotation.Resource; - -/** - * 测试 - */ -@SpringBootTest -@SuppressWarnings("unused") -class MPJ131Test { - @Resource - private UserMapper userMapper; - - /** - * 先明确 你要干啥? - * 在mapper中定义lambda形式的resultMap? - * 要解决问题 - * 1、只初始化了部分数据库实体类? NPE - *

- * stater - * core - * anntion - * test - *

- * 超高自由度的sql拼接器? - * 解决了自连接和子查询和各种函数 - * 如果底层调用MPJLambdaWrapper那样还有什么意义 - */ - @Test - void testJoin() { - System.out.println(1); - } -} From 42131fe52d666a4a13343423480d038c112a0081 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Tue, 15 Nov 2022 17:15:44 +0800 Subject: [PATCH 09/23] test --- .../github/yulichang/test/Application.java | 13 --- .../github/yulichang/test/ListenerEvent.java | 32 -------- .../yulichang/test/join/Application.java | 9 +++ .../test/{ => join}/LambdaWrapperTest.java | 19 +++-- .../test/{ => join}/QueryWrapperTest.java | 10 +-- .../test/join}/config/MybatisPlusConfig.java | 2 +- .../yulichang/test/join}/dto/AddressDTO.java | 4 +- .../yulichang/test/join}/dto/AreaDTO.java | 2 +- .../yulichang/test/join}/dto/UserDTO.java | 4 +- .../test/join}/entity/AddressDO.java | 2 +- .../yulichang/test/join}/entity/AreaDO.java | 2 +- .../yulichang/test/join}/entity/UserDO.java | 4 +- .../yulichang/test/join}/enums/Sex.java | 2 +- .../test/join}/mapper/AddressMapper.java | 4 +- .../test/join}/mapper/AreaMapper.java | 4 +- .../test/join}/mapper/UserMapper.java | 4 +- .../yulichang/test/mapping/Application.java | 8 ++ .../yulichang/test/mapping/MappingTest.java | 27 +++++++ .../mapping/config/MybatisPlusConfig.java | 25 ++++++ .../test/mapping/entity/AddressDO.java | 31 ++++++++ .../yulichang/test/mapping/entity/AreaDO.java | 31 ++++++++ .../yulichang/test/mapping/entity/UserDO.java | 49 ++++++++++++ .../yulichang/test/mapping/enums/Sex.java | 24 ++++++ .../test/mapping/mapper/AddressMapper.java | 10 +++ .../test/mapping/mapper/AreaMapper.java | 10 +++ .../test/mapping/mapper/UserMapper.java | 10 +++ .../src/test/resources/application-join.yml | 5 ++ .../test/resources/application-mapping.yml | 5 ++ .../{main => test}/resources/application.yml | 5 -- .../db => test/resources/db/join}/data.sql | 0 .../db => test/resources/db/join}/schema.sql | 0 .../src/test/resources/db/mapping/data.sql | 79 +++++++++++++++++++ .../src/test/resources/db/mapping/schema.sql | 43 ++++++++++ 33 files changed, 399 insertions(+), 80 deletions(-) delete mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/Application.java delete mode 100644 mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/Application.java rename mybatis-plus-join-test/src/test/java/com/github/yulichang/test/{ => join}/LambdaWrapperTest.java (89%) rename mybatis-plus-join-test/src/test/java/com/github/yulichang/test/{ => join}/QueryWrapperTest.java (91%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/config/MybatisPlusConfig.java (93%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/dto/AddressDTO.java (75%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/dto/AreaDTO.java (90%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/dto/UserDTO.java (88%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/entity/AddressDO.java (92%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/entity/AreaDO.java (92%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/entity/UserDO.java (89%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/enums/Sex.java (88%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/mapper/AddressMapper.java (65%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/mapper/AreaMapper.java (65%) rename mybatis-plus-join-test/src/{main/java/com/github/yulichang/test => test/java/com/github/yulichang/test/join}/mapper/UserMapper.java (62%) create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/Application.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/MappingTest.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/AddressDO.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/AreaDO.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/UserDO.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/enums/Sex.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/AddressMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/AreaMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/UserMapper.java create mode 100644 mybatis-plus-join-test/src/test/resources/application-join.yml create mode 100644 mybatis-plus-join-test/src/test/resources/application-mapping.yml rename mybatis-plus-join-test/src/{main => test}/resources/application.yml (79%) rename mybatis-plus-join-test/src/{main/resources/db => test/resources/db/join}/data.sql (100%) rename mybatis-plus-join-test/src/{main/resources/db => test/resources/db/join}/schema.sql (100%) create mode 100644 mybatis-plus-join-test/src/test/resources/db/mapping/data.sql create mode 100644 mybatis-plus-join-test/src/test/resources/db/mapping/schema.sql diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/Application.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/Application.java deleted file mode 100644 index ee0e144..0000000 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.yulichang.test; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java b/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java deleted file mode 100644 index f161569..0000000 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/ListenerEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.yulichang.test; - -import com.github.yulichang.test.mapper.UserMapper; -import com.zaxxer.hikari.HikariDataSource; -import org.apache.ibatis.session.SqlSessionFactory; -import org.jetbrains.annotations.NotNull; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ApplicationContextEvent; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import javax.annotation.Resource; - -@Component -@SuppressWarnings("unused") -public class ListenerEvent implements ApplicationListener { - @Resource - private HikariDataSource hikariDataSource; - @Resource - private UserMapper userMapper; - private SqlSessionFactory sqlSessionFactory; - - @PostConstruct - public void init() { - System.out.println("1"); - } - - @Override - public void onApplicationEvent(@NotNull ApplicationContextEvent applicationContextEvent) { - - } -} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/Application.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/Application.java new file mode 100644 index 0000000..84473d9 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/Application.java @@ -0,0 +1,9 @@ +package com.github.yulichang.test.join; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication +public class Application { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/LambdaWrapperTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java similarity index 89% rename from mybatis-plus-join-test/src/test/java/com/github/yulichang/test/LambdaWrapperTest.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java index 798c61a..a1b9593 100644 --- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/LambdaWrapperTest.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java @@ -1,13 +1,14 @@ -package com.github.yulichang.test; +package com.github.yulichang.test.join; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.github.yulichang.test.dto.AddressDTO; -import com.github.yulichang.test.dto.UserDTO; -import com.github.yulichang.test.entity.AddressDO; -import com.github.yulichang.test.entity.AreaDO; -import com.github.yulichang.test.entity.UserDO; -import com.github.yulichang.test.mapper.UserMapper; +import com.github.yulichang.test.join.dto.AddressDTO; +import com.github.yulichang.test.join.dto.UserDTO; +import com.github.yulichang.test.join.entity.AddressDO; +import com.github.yulichang.test.join.entity.AreaDO; +import com.github.yulichang.test.join.entity.UserDO; +import com.github.yulichang.test.join.mapper.UserMapper; import com.github.yulichang.toolkit.MPJWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.ibatis.session.SqlSessionFactory; @@ -26,8 +27,8 @@ import java.util.Map; *

* 移除了mybatis-plus 逻辑删除支持,逻辑删除需要在连表查询时自己添加对应的条件 */ -@SpringBootTest @SuppressWarnings("unused") +@SpringBootTest(properties = "spring.profiles.active=join") class LambdaWrapperTest { @Resource private UserMapper userMapper; @@ -39,6 +40,8 @@ class LambdaWrapperTest { */ @Test void testJoin() { + userMapper.selectListDeep(new QueryWrapper<>()); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() .selectAll(UserDO.class) .selectCollection(AddressDO.class, UserDTO::getAddressList, addr -> addr diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/QueryWrapperTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/QueryWrapperTest.java similarity index 91% rename from mybatis-plus-join-test/src/test/java/com/github/yulichang/test/QueryWrapperTest.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/QueryWrapperTest.java index 6777132..a6c6c37 100644 --- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/QueryWrapperTest.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/QueryWrapperTest.java @@ -1,11 +1,11 @@ -package com.github.yulichang.test; +package com.github.yulichang.test.join; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.query.MPJQueryWrapper; -import com.github.yulichang.test.dto.UserDTO; -import com.github.yulichang.test.entity.UserDO; -import com.github.yulichang.test.mapper.UserMapper; +import com.github.yulichang.test.join.dto.UserDTO; +import com.github.yulichang.test.join.entity.UserDO; +import com.github.yulichang.test.join.mapper.UserMapper; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -13,7 +13,7 @@ import javax.annotation.Resource; import java.util.List; import java.util.Map; -@SpringBootTest +@SpringBootTest(properties = "spring.profiles.active=join") class QueryWrapperTest { @Resource private UserMapper userMapper; diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/config/MybatisPlusConfig.java similarity index 93% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/config/MybatisPlusConfig.java index 73dd24d..caf861c 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/config/MybatisPlusConfig.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/config/MybatisPlusConfig.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.config; +package com.github.yulichang.test.join.config; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AddressDTO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/AddressDTO.java similarity index 75% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AddressDTO.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/AddressDTO.java index e516ebf..94daed2 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AddressDTO.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/AddressDTO.java @@ -1,6 +1,6 @@ -package com.github.yulichang.test.dto; +package com.github.yulichang.test.join.dto; -import com.github.yulichang.test.entity.AreaDO; +import com.github.yulichang.test.join.entity.AreaDO; import lombok.Data; import java.util.List; diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AreaDTO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/AreaDTO.java similarity index 90% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AreaDTO.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/AreaDTO.java index ba2ad34..a78b7a8 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/AreaDTO.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/AreaDTO.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.dto; +package com.github.yulichang.test.join.dto; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/UserDTO.java similarity index 88% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/UserDTO.java index 82b5d62..382a830 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/dto/UserDTO.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/UserDTO.java @@ -1,6 +1,6 @@ -package com.github.yulichang.test.dto; +package com.github.yulichang.test.join.dto; -import com.github.yulichang.test.enums.Sex; +import com.github.yulichang.test.join.enums.Sex; import lombok.Data; import lombok.ToString; diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AddressDO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/AddressDO.java similarity index 92% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AddressDO.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/AddressDO.java index 218fd9e..b5c8ec1 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AddressDO.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/AddressDO.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.entity; +package com.github.yulichang.test.join.entity; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AreaDO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/AreaDO.java similarity index 92% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AreaDO.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/AreaDO.java index c58c89f..d2c00d0 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/AreaDO.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/AreaDO.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.entity; +package com.github.yulichang.test.join.entity; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/UserDO.java similarity index 89% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/UserDO.java index 309b873..edcd8df 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/entity/UserDO.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/UserDO.java @@ -1,11 +1,11 @@ -package com.github.yulichang.test.entity; +package com.github.yulichang.test.join.entity; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; -import com.github.yulichang.test.enums.Sex; +import com.github.yulichang.test.join.enums.Sex; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/enums/Sex.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/enums/Sex.java similarity index 88% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/enums/Sex.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/enums/Sex.java index 7ab9f24..d6dc1cc 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/enums/Sex.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/enums/Sex.java @@ -1,4 +1,4 @@ -package com.github.yulichang.test.enums; +package com.github.yulichang.test.join.enums; import com.baomidou.mybatisplus.annotation.EnumValue; import lombok.Getter; diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AddressMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/AddressMapper.java similarity index 65% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AddressMapper.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/AddressMapper.java index bbde4a3..246de25 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AddressMapper.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/AddressMapper.java @@ -1,7 +1,7 @@ -package com.github.yulichang.test.mapper; +package com.github.yulichang.test.join.mapper; import com.github.yulichang.base.MPJBaseMapper; -import com.github.yulichang.test.entity.AddressDO; +import com.github.yulichang.test.join.entity.AddressDO; import org.apache.ibatis.annotations.Mapper; @Mapper diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AreaMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/AreaMapper.java similarity index 65% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AreaMapper.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/AreaMapper.java index 7a3314c..2eb72d7 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/AreaMapper.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/AreaMapper.java @@ -1,7 +1,7 @@ -package com.github.yulichang.test.mapper; +package com.github.yulichang.test.join.mapper; import com.github.yulichang.base.MPJBaseMapper; -import com.github.yulichang.test.entity.AreaDO; +import com.github.yulichang.test.join.entity.AreaDO; import org.apache.ibatis.annotations.Mapper; @Mapper diff --git a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/UserMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/UserMapper.java similarity index 62% rename from mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/UserMapper.java rename to mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/UserMapper.java index 4088f5b..acbbdfa 100644 --- a/mybatis-plus-join-test/src/main/java/com/github/yulichang/test/mapper/UserMapper.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/UserMapper.java @@ -1,7 +1,7 @@ -package com.github.yulichang.test.mapper; +package com.github.yulichang.test.join.mapper; import com.github.yulichang.base.MPJBaseMapper; -import com.github.yulichang.test.entity.UserDO; +import com.github.yulichang.test.join.entity.UserDO; import org.apache.ibatis.annotations.Mapper; @Mapper diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/Application.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/Application.java new file mode 100644 index 0000000..ade9a3a --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/Application.java @@ -0,0 +1,8 @@ +package com.github.yulichang.test.mapping; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/MappingTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/MappingTest.java new file mode 100644 index 0000000..e59c1a6 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/MappingTest.java @@ -0,0 +1,27 @@ +package com.github.yulichang.test.mapping; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.github.yulichang.test.mapping.entity.UserDO; +import com.github.yulichang.test.mapping.mapper.UserMapper; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 注解一对一,一对多查询 + */ +@SpringBootTest(properties = "spring.profiles.active=mapping") +@SuppressWarnings("unused") +class MappingTest { + + @Resource + private UserMapper userMapper; + + @Test + public void test() { + List dos = userMapper.selectListDeep(new QueryWrapper<>()); + System.out.println(1); + } +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java new file mode 100644 index 0000000..83d6022 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java @@ -0,0 +1,25 @@ +package com.github.yulichang.test.mapping.config; + +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * mybatis-plus配置 + */ +@Configuration +public class MybatisPlusConfig { + + /** + * 分页插件 + */ + @Bean + public MybatisPlusInterceptor paginationInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + PaginationInnerInterceptor page = new PaginationInnerInterceptor(); + page.setOptimizeJoin(false); + interceptor.addInnerInterceptor(page); + return interceptor; + } +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/AddressDO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/AddressDO.java new file mode 100644 index 0000000..4bfd471 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/AddressDO.java @@ -0,0 +1,31 @@ +package com.github.yulichang.test.mapping.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@Data +@ToString +@Accessors(chain = true) +@EqualsAndHashCode +@TableName("address") +public class AddressDO { + + @TableId + private Integer id; + + private Integer userId; + + private Integer areaId; + + private String tel; + + private String address; + + @TableLogic + private Boolean del; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/AreaDO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/AreaDO.java new file mode 100644 index 0000000..fd1840f --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/AreaDO.java @@ -0,0 +1,31 @@ +package com.github.yulichang.test.mapping.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +@Data +@ToString +@Accessors(chain = true) +@EqualsAndHashCode +@TableName("area") +public class AreaDO { + + @TableId + private Integer id; + + private String province; + + private String city; + + private String area; + + private String postcode; + + @TableLogic + private Boolean del; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/UserDO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/UserDO.java new file mode 100644 index 0000000..935a406 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/entity/UserDO.java @@ -0,0 +1,49 @@ +package com.github.yulichang.test.mapping.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import com.github.yulichang.annotation.EntityMapping; +import com.github.yulichang.test.mapping.enums.Sex; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import lombok.experimental.Accessors; + +import java.util.List; +import java.util.Map; + +@Data +@ToString +@Accessors(chain = true) +@EqualsAndHashCode +@TableName(value = "`user`", autoResultMap = true) +public class UserDO { + + @TableId + private Integer id; + + private Integer pid; + + @TableField(value = "`name`", typeHandler = JacksonTypeHandler.class) + private Map name; + + private Sex sex; + + private String headImg; + + private Integer addressId; + + @TableLogic + private Boolean del; + + @TableField(exist = false) + @EntityMapping(thisField = "pid", joinField = "id") + private UserDO pUser; + + @TableField(exist = false) + @EntityMapping(thisField = "id", joinField = "pid") + private List userList; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/enums/Sex.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/enums/Sex.java new file mode 100644 index 0000000..64c1b59 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/enums/Sex.java @@ -0,0 +1,24 @@ +package com.github.yulichang.test.mapping.enums; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +public enum Sex { + + MAN(0, "男"), + + WOMAN(1, "女"); + + @EnumValue + private final int code; + private final String des; + + Sex(int code, String des) { + this.code = code; + this.des = des; + } + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/AddressMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/AddressMapper.java new file mode 100644 index 0000000..a190b48 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/AddressMapper.java @@ -0,0 +1,10 @@ +package com.github.yulichang.test.mapping.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.mapping.entity.AddressDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface AddressMapper extends MPJBaseMapper { +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/AreaMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/AreaMapper.java new file mode 100644 index 0000000..56a9e0f --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/AreaMapper.java @@ -0,0 +1,10 @@ +package com.github.yulichang.test.mapping.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.mapping.entity.AreaDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface AreaMapper extends MPJBaseMapper { +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/UserMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/UserMapper.java new file mode 100644 index 0000000..e13c26a --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/mapper/UserMapper.java @@ -0,0 +1,10 @@ +package com.github.yulichang.test.mapping.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.mapping.entity.UserDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface UserMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/resources/application-join.yml b/mybatis-plus-join-test/src/test/resources/application-join.yml new file mode 100644 index 0000000..5f17720 --- /dev/null +++ b/mybatis-plus-join-test/src/test/resources/application-join.yml @@ -0,0 +1,5 @@ +spring: + sql: + init: + schema-locations: classpath:db/join/schema.sql + data-locations: classpath:db/join/data.sql \ No newline at end of file diff --git a/mybatis-plus-join-test/src/test/resources/application-mapping.yml b/mybatis-plus-join-test/src/test/resources/application-mapping.yml new file mode 100644 index 0000000..083aef4 --- /dev/null +++ b/mybatis-plus-join-test/src/test/resources/application-mapping.yml @@ -0,0 +1,5 @@ +spring: + sql: + init: + schema-locations: classpath:db/mapping/schema.sql + data-locations: classpath:db/mapping/data.sql \ No newline at end of file diff --git a/mybatis-plus-join-test/src/main/resources/application.yml b/mybatis-plus-join-test/src/test/resources/application.yml similarity index 79% rename from mybatis-plus-join-test/src/main/resources/application.yml rename to mybatis-plus-join-test/src/test/resources/application.yml index 2c33924..6d099dd 100644 --- a/mybatis-plus-join-test/src/main/resources/application.yml +++ b/mybatis-plus-join-test/src/test/resources/application.yml @@ -4,11 +4,6 @@ spring: url: jdbc:h2:mem:test username: root password: test - sql: - init: - schema-locations: classpath:db/schema.sql - data-locations: classpath:db/data.sql - mybatis-plus: global-config: diff --git a/mybatis-plus-join-test/src/main/resources/db/data.sql b/mybatis-plus-join-test/src/test/resources/db/join/data.sql similarity index 100% rename from mybatis-plus-join-test/src/main/resources/db/data.sql rename to mybatis-plus-join-test/src/test/resources/db/join/data.sql diff --git a/mybatis-plus-join-test/src/main/resources/db/schema.sql b/mybatis-plus-join-test/src/test/resources/db/join/schema.sql similarity index 100% rename from mybatis-plus-join-test/src/main/resources/db/schema.sql rename to mybatis-plus-join-test/src/test/resources/db/join/schema.sql diff --git a/mybatis-plus-join-test/src/test/resources/db/mapping/data.sql b/mybatis-plus-join-test/src/test/resources/db/mapping/data.sql new file mode 100644 index 0000000..5b76f9a --- /dev/null +++ b/mybatis-plus-join-test/src/test/resources/db/mapping/data.sql @@ -0,0 +1,79 @@ +-- noinspection SqlDialectInspectionForFile + +-- noinspection SqlNoDataSourceInspectionForFile + +DELETE FROM area; + +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10001, '北京市01', '北京01', '朝阳01', '80001', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10002, '北京市02', '北京02', '朝阳02', '80002', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10003, '北京市03', '北京03', '朝阳03', '80003', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10004, '北京市04', '北京04', '朝阳04', '80004', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10005, '北京市05', '北京05', '朝阳05', '80005', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10006, '北京市06', '北京06', '朝阳06', '80006', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10007, '北京市07', '北京07', '朝阳07', '80007', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10008, '北京市08', '北京08', '朝阳08', '80008', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10009, '北京市09', '北京09', '朝阳09', '80009', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10010, '北京市10', '北京10', '朝阳10', '80010', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10011, '北京市11', '北京11', '朝阳11', '80011', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10012, '北京市12', '北京12', '朝阳12', '80012', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10013, '北京市13', '北京13', '朝阳13', '80013', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10014, '北京市14', '北京14', '朝阳14', '80014', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10015, '北京市15', '北京15', '朝阳15', '80015', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10016, '北京市16', '北京16', '朝阳16', '80016', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10017, '北京市17', '北京17', '朝阳17', '80017', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10018, '北京市18', '北京18', '朝阳18', '80018', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10019, '北京市19', '北京19', '朝阳19', '80019', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10020, '北京市20', '北京20', '朝阳20', '80020', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10021, '北京市21', '北京21', '朝阳21', '80021', false); +INSERT INTO area (id, province, city, area, postcode, del) VALUES (10022, '北京市22', '北京22', '朝阳22', '80022', false); + +DELETE FROM `user`; + +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES ( 1, 1, '{"aa":"aaa","bb":"bbb"}', 1, 1, 'https://url-01', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES ( 2, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-02', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES ( 3, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-03', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES ( 4, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-04', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES ( 5, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-05', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES ( 6, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-06', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES ( 7, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-07', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES ( 8, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-08', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES ( 9, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-09', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (10, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-10', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (11, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-11', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (12, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-12', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (13, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-13', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (14, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-14', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (15, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-15', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (16, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-16', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (17, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-17', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (18, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-18', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (19, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-19', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (20, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-20', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (21, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-21', false); +INSERT INTO `user` (id, pid, `name`, `address_id`, sex, head_img, del) VALUES (22, 1, '{"aa":"aaa","bb":"bbb"}', 1, 0, 'https://url-22', false); + + +DELETE FROM address; + +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 1, 1, 10001, '10000000001', '曹县01', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 2, 1, 10002, '10000000002', '曹县02', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 3, 1, 10003, '10000000003', '曹县03', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 4, 1, 10004, '10000000004', '曹县04', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 5, 1, 10005, '10000000005', '曹县05', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 6, 1, 10006, '10000000006', '曹县06', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 7, 1, 10007, '10000000007', '曹县07', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 8, 1, 10008, '10000000008', '曹县08', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES ( 9, 1, 10009, '10000000009', '曹县09', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (10,10, 10010, '10000000010', '曹县10', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (11,11, 10011, '10000000011', '曹县11', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (12,12, 10012, '10000000012', '曹县12', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (13,13, 10013, '10000000013', '曹县13', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (14,14, 10014, '10000000014', '曹县14', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (15,15, 10015, '10000000015', '曹县15', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (16,16, 10016, '10000000016', '曹县16', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (17,17, 10017, '10000000017', '曹县17', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (18,18, 10018, '10000000018', '曹县18', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (19,19, 10019, '10000000019', '曹县19', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (20,20, 10020, '10000000020', '曹县20', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (21,21, 10021, '10000000021', '曹县21', false); +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (22,22, 10022, '10000000022', '曹县22', false); \ No newline at end of file diff --git a/mybatis-plus-join-test/src/test/resources/db/mapping/schema.sql b/mybatis-plus-join-test/src/test/resources/db/mapping/schema.sql new file mode 100644 index 0000000..f077cd5 --- /dev/null +++ b/mybatis-plus-join-test/src/test/resources/db/mapping/schema.sql @@ -0,0 +1,43 @@ +-- noinspection SqlDialectInspectionForFile + +-- noinspection SqlNoDataSourceInspectionForFile + +DROP TABLE IF EXISTS area; + +create table area +( + id int auto_increment + primary key, + province varchar(255) null, + city varchar(255) null, + area varchar(255) null, + postcode varchar(255) null, + del bit +); + +DROP TABLE IF EXISTS `user`; + +create table `user` +( + id int auto_increment + primary key, + pid int null, + `name` varchar(255) not null, + `address_id` int not null, + sex tinyint not null, + head_img varchar(255) not null, + del bit +); + +DROP TABLE IF EXISTS address; + +create table address +( + id int auto_increment + primary key, + user_id int null, + area_id int null, + tel varchar(255) null, + address varchar(255) null, + del bit +); \ No newline at end of file From efcccd2da0d121552adc6928fa23e86c0ed4ca47 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Tue, 15 Nov 2022 22:48:05 +0800 Subject: [PATCH 10/23] =?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/interceptor/MPJInterceptor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 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 067353d..f26c341 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 @@ -246,8 +246,9 @@ public class MPJInterceptor implements Interceptor { this.buildResult(ms, mpjColl.getMybatisLabels(), columnSet, childMapping, columnList); } String childId = "MPJ_" + mpjColl.getEntityClass().getName() + StringPool.UNDERSCORE + mpjColl.getOfType().getName() + - StringPool.UNDERSCORE + childMapping.stream().map(i -> (CollectionUtils.isEmpty(i.getFlags()) ? - ResultFlag.CONSTRUCTOR : i.getFlags().get(0)) + i.getProperty() + i.getColumn()).collect(Collectors.joining(StringPool.DASH)); + StringPool.UNDERSCORE + childMapping.stream().map(i -> "(" + (CollectionUtils.isEmpty(i.getFlags()) ? + ResultFlag.CONSTRUCTOR : i.getFlags().get(0)) + "-" + i.getProperty() + "-" + i.getColumn() + ")") + .collect(Collectors.joining(StringPool.DASH)); parentMappings.add(new ResultMapping.Builder(ms.getConfiguration(), mpjColl.getProperty()) .javaType(mpjColl.getJavaType()) .nestedResultMapId(childId) From 9464dea9f2ab9bf77430b43eb37a338c440f2884 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 16 Nov 2022 18:27:45 +0800 Subject: [PATCH 11/23] =?UTF-8?q?=E5=90=8C=E6=AD=A5=20mybatis=20plus=203.5?= =?UTF-8?q?.2=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mybatis-plus-join-annotation/pom.xml | 2 + mybatis-plus-join-boot-starter/pom.xml | 4 +- mybatis-plus-join-core/pom.xml | 9 +- .../yulichang/interceptor/MPJInterceptor.java | 108 ++++--- .../github/yulichang/toolkit/ClassUtils.java | 267 ++++++++++++++++++ .../yulichang/toolkit/InterceptorList.java | 2 +- .../github/yulichang/toolkit/LambdaUtils.java | 65 +++-- .../yulichang/toolkit/MPJReflectionKit.java | 61 ++++ .../yulichang/toolkit/ReflectionKit.java | 84 +++--- .../toolkit/support/ColumnCache.java | 2 +- .../toolkit/support/IdeaProxyLambdaMeta.java | 77 +++++ .../yulichang/toolkit/support/LambdaMeta.java | 39 +++ .../toolkit/support/ReflectLambdaMeta.java | 78 +++++ .../toolkit/support/SelectColumn.java | 2 +- .../toolkit/support/SerializedLambda.java | 128 +++------ .../toolkit/support/ShadowLambdaMeta.java | 46 +++ .../yulichang/wrapper/MPJLambdaWrapper.java | 35 +-- .../wrapper/resultmap/MybatisLabel.java | 28 +- .../yulichang/wrapper/resultmap/Result.java | 2 +- mybatis-plus-join-test/pom.xml | 26 +- .../test/collection/Application.java | 9 + .../test/collection/CollectionTest.java | 47 +++ .../collection/config/MybatisPlusConfig.java | 24 ++ .../test/collection/dto/TableADTO.java | 17 ++ .../test/collection/dto/TableBDTO.java | 19 ++ .../test/collection/dto/TableCDTO.java | 19 ++ .../test/collection/dto/TableDDTO.java | 19 ++ .../test/collection/dto/TableEDTO.java | 15 + .../test/collection/entity/TableA.java | 15 + .../test/collection/entity/TableB.java | 17 ++ .../test/collection/entity/TableC.java | 17 ++ .../test/collection/entity/TableD.java | 17 ++ .../test/collection/entity/TableE.java | 17 ++ .../yulichang/test/collection/enums/Sex.java | 24 ++ .../test/collection/mapper/TableAMapper.java | 10 + .../test/collection/mapper/TableBMapper.java | 11 + .../test/collection/mapper/TableCMapper.java | 11 + .../test/collection/mapper/TableDMapper.java | 11 + .../test/collection/mapper/TableEMapper.java | 11 + .../test/join/LambdaWrapperTest.java | 9 +- .../yulichang/test/join/dto/TableDTO.java | 61 ++++ .../yulichang/test/join/entity/TableA.java | 15 + .../yulichang/test/join/entity/TableB.java | 17 ++ .../yulichang/test/join/entity/TableC.java | 17 ++ .../yulichang/test/join/entity/TableD.java | 17 ++ .../yulichang/test/join/entity/TableE.java | 17 ++ .../yulichang/test/join/entity/UserDO.java | 2 +- .../test/join/mapper/TableAMapper.java | 11 + .../test/join/mapper/TableBMapper.java | 11 + .../test/join/mapper/TableCMapper.java | 11 + .../test/join/mapper/TableDMapper.java | 11 + .../test/join/mapper/TableEMapper.java | 11 + .../mapping/config/MybatisPlusConfig.java | 1 - .../test/resources/application-collection.yml | 5 + .../src/test/resources/application.yml | 1 + .../src/test/resources/db/collection/data.sql | 29 ++ .../test/resources/db/collection/schema.sql | 48 ++++ .../src/test/resources/db/join/data.sql | 3 +- .../src/test/resources/db/join/schema.sql | 20 +- 59 files changed, 1441 insertions(+), 271 deletions(-) create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ClassUtils.java create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/IdeaProxyLambdaMeta.java create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/LambdaMeta.java create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ReflectLambdaMeta.java create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ShadowLambdaMeta.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/Application.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/CollectionTest.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/config/MybatisPlusConfig.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableADTO.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableBDTO.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableCDTO.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableDDTO.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableEDTO.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableA.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableB.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableC.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableD.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableE.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/enums/Sex.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableAMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableBMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableCMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableDMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableEMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/TableDTO.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableA.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableB.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableC.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableD.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableE.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableAMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableBMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableCMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableDMapper.java create mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableEMapper.java create mode 100644 mybatis-plus-join-test/src/test/resources/application-collection.yml create mode 100644 mybatis-plus-join-test/src/test/resources/db/collection/data.sql create mode 100644 mybatis-plus-join-test/src/test/resources/db/collection/schema.sql diff --git a/mybatis-plus-join-annotation/pom.xml b/mybatis-plus-join-annotation/pom.xml index d662729..463b4c9 100644 --- a/mybatis-plus-join-annotation/pom.xml +++ b/mybatis-plus-join-annotation/pom.xml @@ -1,4 +1,5 @@ + @@ -8,6 +9,7 @@ mybatis-plus-join-root 2.0.0 + 2.0.0 mybatis-plus-join-annotation mybatis-plus-join-annotation diff --git a/mybatis-plus-join-boot-starter/pom.xml b/mybatis-plus-join-boot-starter/pom.xml index a5eb38b..660091f 100644 --- a/mybatis-plus-join-boot-starter/pom.xml +++ b/mybatis-plus-join-boot-starter/pom.xml @@ -1,4 +1,5 @@ + @@ -8,6 +9,7 @@ mybatis-plus-join-root 2.0.0 + 2.0.0 mybatis-plus-join-boot-starter mybatis-plus-join-boot-starter @@ -45,7 +47,7 @@ com.github.yulichang mybatis-plus-join-core - ${mybaits-plus-join.version} + 2.0.0 org.springframework.boot diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml index d202a4e..d48f1c6 100644 --- a/mybatis-plus-join-core/pom.xml +++ b/mybatis-plus-join-core/pom.xml @@ -9,6 +9,7 @@ mybatis-plus-join-root 2.0.0 + 2.0.0 mybatis-plus-join-core mybatis-plus-join-core @@ -46,7 +47,7 @@ com.github.yulichang mybatis-plus-join-annotation - ${mybaits-plus-join.version} + 2.0.0 com.baomidou @@ -60,6 +61,12 @@ ${lombok.version} provided + + org.slf4j + slf4j-api + provided + 2.0.3 + org.springframework spring-aop 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 f26c341..5e1d268 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 @@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.toolkit.*; import com.github.yulichang.interfaces.MPJBaseJoin; import com.github.yulichang.method.MPJResultType; import com.github.yulichang.toolkit.Constant; -import com.github.yulichang.toolkit.ReflectionKit; import com.github.yulichang.toolkit.support.SelectColumn; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.resultmap.MybatisLabel; @@ -150,7 +149,6 @@ public class MPJInterceptor implements Interceptor { TableInfo tableInfo = TableInfoHelper.getTableInfo(resultType); String id = ms.getId() + StringPool.DOT + Constants.MYBATIS_PLUS + StringPool.UNDERSCORE + resultType.getName(); if (!(obj instanceof MPJLambdaWrapper) || Map.class.isAssignableFrom(resultType) || - ReflectionKit.isPrimitiveOrWrapper(resultType) || Collection.class.isAssignableFrom(resultType)) { result.add(getDefaultResultMap(tableInfo, ms, resultType, id)); return result; @@ -209,56 +207,86 @@ public class MPJInterceptor implements Interceptor { //移除result中不存在的标签 resultMappings.removeIf(i -> !fieldMap.containsKey(i.getProperty())); if (wrapper.isResultMap()) { - buildResult(ms, wrapper.getResultMapMybatisLabel(), columnSet, resultMappings, columnList); + for (Object o : wrapper.getResultMapMybatisLabel()) { + MybatisLabel label = (MybatisLabel) o; + resultMappings.add(buildResult(ms, label, columnSet, columnList)); + } } result.add(new ResultMap.Builder(ms.getConfiguration(), id, resultType, resultMappings).build()); return result; } - private void buildResult(MappedStatement ms, List> mybatisLabel, Set columnSet, - List parentMappings, List columnList) { - for (MybatisLabel mpjColl : mybatisLabel) { - List list = mpjColl.getResultList(); - if (CollectionUtils.isEmpty(list)) { - continue; + + //fix 重上往下会有resultMap覆盖问题,应该从根节点开始,id向上传递 + + /** + * @return 返回节点id + */ + private ResultMapping buildResult(MappedStatement ms, MybatisLabel mybatisLabel, Set columnSet, + List columnList) { + List resultList = mybatisLabel.getResultList(); + if (CollectionUtils.isEmpty(resultList)) { + return null; + } + List childMapping = new ArrayList<>(resultList.size()); + for (Result r : resultList) { + String columnName = r.getColumn(); + //列名去重 + columnName = getColumn(columnSet, columnName); + columnList.add(SelectColumn.of(mybatisLabel.getEntityClass(), r.getColumn(), null, + Objects.equals(columnName, r.getColumn()) ? null : columnName, null, null, true, null)); + ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), + StringUtils.getTargetColumn(columnName), r.getJavaType()); + if (r.isId()) {//主键标记为id标签 + builder.flags(Collections.singletonList(ResultFlag.ID)); } - List childMapping = new ArrayList<>(list.size()); - for (Result r : list) { - String columnName = r.getColumn(); - //列名去重 - columnName = getColumn(columnSet, columnName); - columnList.add(SelectColumn.of(mpjColl.getEntityClass(), r.getColumn(), null, - Objects.equals(columnName, r.getColumn()) ? null : columnName, null, null, true, null)); - ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), - StringUtils.getTargetColumn(columnName), r.getJavaType()); - if (r.isId()) {//主键标记为id标签 - builder.flags(Collections.singletonList(ResultFlag.ID)); - } - //TypeHandle - TableFieldInfo info = r.getTableFieldInfo(); - if (info != null && info.getTypeHandler() != null && info.getTypeHandler() != UnknownTypeHandler.class) { - builder.typeHandler(getTypeHandler(ms, info)); - } - childMapping.add(builder.build()); + //TypeHandle + TableFieldInfo info = r.getTableFieldInfo(); + if (info != null && info.getTypeHandler() != null && info.getTypeHandler() != UnknownTypeHandler.class) { + builder.typeHandler(getTypeHandler(ms, info)); } - //嵌套处理 - if (CollectionUtils.isNotEmpty(mpjColl.getMybatisLabels())) { - this.buildResult(ms, mpjColl.getMybatisLabels(), columnSet, childMapping, columnList); - } - String childId = "MPJ_" + mpjColl.getEntityClass().getName() + StringPool.UNDERSCORE + mpjColl.getOfType().getName() + + childMapping.add(builder.build()); + } + + String childId; + if (CollectionUtils.isEmpty(mybatisLabel.getMybatisLabels())) { + childId = "MPJ_" + mybatisLabel.getEntityClass().getName() + StringPool.UNDERSCORE + mybatisLabel.getOfType().getName() + StringPool.UNDERSCORE + childMapping.stream().map(i -> "(" + (CollectionUtils.isEmpty(i.getFlags()) ? ResultFlag.CONSTRUCTOR : i.getFlags().get(0)) + "-" + i.getProperty() + "-" + i.getColumn() + ")") .collect(Collectors.joining(StringPool.DASH)); - parentMappings.add(new ResultMapping.Builder(ms.getConfiguration(), mpjColl.getProperty()) - .javaType(mpjColl.getJavaType()) - .nestedResultMapId(childId) - .build()); - //双检 - if (!ms.getConfiguration().getResultMapNames().contains(childId)) { - ResultMap build = new ResultMap.Builder(ms.getConfiguration(), childId, mpjColl.getOfType(), childMapping).build(); - MPJInterceptor.addResultMap(ms, childId, build); + } else { + //递归调用 + StringBuilder sb = new StringBuilder("MPJ_["); + for (MybatisLabel o : mybatisLabel.getMybatisLabels()) { + if (Objects.isNull(o)) { + continue; + } + ResultMapping result = buildResult(ms, o, columnSet, columnList); + if (Objects.isNull(result)) { + continue; + } + childMapping.add(result); + sb.append(result.getNestedResultMapId()); + sb.append("]"); } + sb.append("_MPJ_") + .append(mybatisLabel.getEntityClass().getName()) + .append(StringPool.UNDERSCORE) + .append(mybatisLabel.getOfType().getName()) + .append(StringPool.UNDERSCORE); + childId = sb + childMapping.stream().map(i -> "(" + (CollectionUtils.isEmpty(i.getFlags()) ? + ResultFlag.CONSTRUCTOR : i.getFlags().get(0)) + "-" + i.getProperty() + "-" + i.getColumn() + ")") + .collect(Collectors.joining(StringPool.DASH)); } + //双检 + if (!ms.getConfiguration().getResultMapNames().contains(childId)) { + ResultMap build = new ResultMap.Builder(ms.getConfiguration(), childId, mybatisLabel.getOfType(), childMapping).build(); + MPJInterceptor.addResultMap(ms, childId, build); + } + return new ResultMapping.Builder(ms.getConfiguration(), mybatisLabel.getProperty()) + .javaType(mybatisLabel.getJavaType()) + .nestedResultMapId(childId) + .build(); } /** diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ClassUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ClassUtils.java new file mode 100644 index 0000000..71f6cd0 --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ClassUtils.java @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2011-2022, baomidou (jobob@qq.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.yulichang.toolkit; + +import com.baomidou.mybatisplus.core.toolkit.Assert; +import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import org.apache.ibatis.io.Resources; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.List; + +/** + *

+ * ClassUtils + *

+ * + * @author Caratacus + * @author HCL + * @since 2017/07/08 + */ +@SuppressWarnings("All") +public final class ClassUtils { + + private static ClassLoader systemClassLoader; + + static { + try { + systemClassLoader = ClassLoader.getSystemClassLoader(); + } catch (SecurityException ignored) { + // AccessControlException on Google App Engine + } + } + + /** + * 代理 class 的名称 + */ + private static final List PROXY_CLASS_NAMES = Arrays.asList("net.sf.cglib.proxy.Factory" + // cglib + , "org.springframework.cglib.proxy.Factory" + , "javassist.util.proxy.ProxyObject" + // javassist + , "org.apache.ibatis.javassist.util.proxy.ProxyObject"); + + private ClassUtils() { + } + + /** + * 判断传入的类型是否是布尔类型 + * + * @param type 类型 + * @return 如果是原生布尔或者包装类型布尔,均返回 true + */ + public static boolean isBoolean(Class type) { + return type == boolean.class || Boolean.class == type; + } + + /** + * 判断是否为代理对象 + * + * @param clazz 传入 class 对象 + * @return 如果对象class是代理 class,返回 true + */ + public static boolean isProxy(Class clazz) { + if (clazz != null) { + for (Class cls : clazz.getInterfaces()) { + if (PROXY_CLASS_NAMES.contains(cls.getName())) { + return true; + } + } + } + return false; + } + + /** + *

+ * 获取当前对象的 class + *

+ * + * @param clazz 传入 + * @return 如果是代理的class,返回父 class,否则返回自身 + */ + public static Class getUserClass(Class clazz) { + Assert.notNull(clazz, "Class must not be null"); + return isProxy(clazz) ? clazz.getSuperclass() : clazz; + } + + /** + *

+ * 获取当前对象的class + *

+ * + * @param object 对象 + * @return 返回对象的 user class + */ + public static Class getUserClass(Object object) { + Assert.notNull(object, "Instance must not be null"); + return getUserClass(object.getClass()); + } + + /** + *

+ * 根据指定的 class , 实例化一个对象,根据构造参数来实例化 + *

+ *

+ * 在 java9 及其之后的版本 Class.newInstance() 方法已被废弃 + *

+ * + * @param clazz 需要实例化的对象 + * @param 类型,由输入类型决定 + * @return 返回新的实例 + */ + public static T newInstance(Class clazz) { + try { + Constructor constructor = clazz.getDeclaredConstructor(); + constructor.setAccessible(true); + return constructor.newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | + NoSuchMethodException e) { + throw ExceptionUtils.mpe("实例化对象时出现错误,请尝试给 %s 添加无参的构造方法", e, clazz.getName()); + } + } + + /** + * 实例化对象. + * + * @param clazzName 类名 + * @param 类型 + * @return 实例 + * @since 3.3.2 + */ + @SuppressWarnings("unchecked") + public static T newInstance(String clazzName) { + return (T) newInstance(toClassConfident(clazzName)); + } + + + /** + *

+ * 请仅在确定类存在的情况下调用该方法 + *

+ * + * @param name 类名称 + * @return 返回转换后的 Class + */ + public static Class toClassConfident(String name) { + return toClassConfident(name, null); + } + + /** + * @param name + * @param classLoader + * @return + * @since 3.4.3 + */ + public static Class toClassConfident(String name, ClassLoader classLoader) { + try { + return loadClass(name, getClassLoaders(classLoader)); + } catch (ClassNotFoundException e) { + throw ExceptionUtils.mpe("找不到指定的class!请仅在明确确定会有 class 的时候,调用该方法", e); + } + } + + private static Class loadClass(String className, ClassLoader[] classLoaders) throws ClassNotFoundException { + for (ClassLoader classLoader : classLoaders) { + if (classLoader != null) { + try { + return Class.forName(className, true, classLoader); + } catch (ClassNotFoundException e) { + // ignore + } + } + } + throw new ClassNotFoundException("Cannot find class: " + className); + } + + + /** + * Determine the name of the package of the given class, + * e.g. "java.lang" for the {@code java.lang.String} class. + * + * @param clazz the class + * @return the package name, or the empty String if the class + * is defined in the default package + */ + public static String getPackageName(Class clazz) { + Assert.notNull(clazz, "Class must not be null"); + return getPackageName(clazz.getName()); + } + + /** + * Determine the name of the package of the given fully-qualified class name, + * e.g. "java.lang" for the {@code java.lang.String} class name. + * + * @param fqClassName the fully-qualified class name + * @return the package name, or the empty String if the class + * is defined in the default package + */ + public static String getPackageName(String fqClassName) { + Assert.notNull(fqClassName, "Class name must not be null"); + int lastDotIndex = fqClassName.lastIndexOf(StringPool.DOT); + return (lastDotIndex != -1 ? fqClassName.substring(0, lastDotIndex) : StringPool.EMPTY); + } + + /** + * Return the default ClassLoader to use: typically the thread context + * ClassLoader, if available; the ClassLoader that loaded the ClassUtils + * class will be used as fallback. + *

Call this method if you intend to use the thread context ClassLoader + * in a scenario where you clearly prefer a non-null ClassLoader reference: + * for example, for class path resource loading (but not necessarily for + * {@code Class.forName}, which accepts a {@code null} ClassLoader + * reference as well). + * + * @return the default ClassLoader (only {@code null} if even the system + * ClassLoader isn't accessible) + * @see Thread#getContextClassLoader() + * @see ClassLoader#getSystemClassLoader() + * @since 3.3.2 + */ + @Deprecated + public static ClassLoader getDefaultClassLoader() { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } catch (Throwable ex) { + // Cannot access thread context ClassLoader - falling back... + } + if (cl == null) { + // No thread context class loader -> use class loader of this class. + cl = ClassUtils.class.getClassLoader(); + if (cl == null) { + // getClassLoader() returning null indicates the bootstrap ClassLoader + try { + cl = ClassLoader.getSystemClassLoader(); + } catch (Throwable ex) { + // Cannot access system ClassLoader - oh well, maybe the caller can live with null... + } + } + } + return cl; + } + + private static ClassLoader[] getClassLoaders(ClassLoader classLoader) { + return new ClassLoader[]{ + classLoader, + Resources.getDefaultClassLoader(), + Thread.currentThread().getContextClassLoader(), + ClassUtils.class.getClassLoader(), + systemClassLoader}; + } +} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/InterceptorList.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/InterceptorList.java index e8620cc..c113632 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/InterceptorList.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/InterceptorList.java @@ -13,7 +13,7 @@ import java.util.function.Predicate; * 保证 MPJInterceptor 再最后一个(第一个执行) * * @author yulichang - * @since 1.2.5 + * @since 1.3.0 */ public class InterceptorList extends ArrayList { diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java index e782640..9e782cd 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java @@ -5,13 +5,13 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; -import com.github.yulichang.toolkit.support.ColumnCache; -import com.github.yulichang.toolkit.support.SerializedLambda; +import com.github.yulichang.toolkit.support.*; import org.apache.ibatis.reflection.property.PropertyNamer; -import java.lang.ref.WeakReference; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.util.Map; -import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import static java.util.Locale.ENGLISH; @@ -19,50 +19,54 @@ import static java.util.Locale.ENGLISH; /** * copy {@link com.baomidou.mybatisplus.core.toolkit.LambdaUtils} */ +@SuppressWarnings("unused") public final class LambdaUtils { /* ******* 自定义方法 *********** */ public static String getName(SFunction fn) { - return PropertyNamer.methodToProperty(resolve(fn).getImplMethodName()); + LambdaMeta extract = extract(fn); + String name = PropertyNamer.methodToProperty(extract.getImplMethodName()); + if (Character.isUpperCase(name.charAt(0))) { + Map map = MPJReflectionKit.getFieldMap(extract.getInstantiatedClass()); + if (map.containsKey(name)) { + return name; + } else { + return map.keySet().stream().filter(i -> i.equalsIgnoreCase(name)).findFirst().orElse(null); + } + } + return name; } @SuppressWarnings("unchecked") public static Class getEntityClass(SFunction fn) { - return (Class) resolve(fn).getInstantiatedType(); + return (Class) extract(fn).getInstantiatedClass(); } /* ******* 自定义方法 结束 以下代码均为拷贝 *********** */ - /** - * 字段映射 - */ private static final Map> COLUMN_CACHE_MAP = new ConcurrentHashMap<>(); /** - * SerializedLambda 反序列化缓存 - */ - private static final Map> FUNC_CACHE = new ConcurrentHashMap<>(); - - /** - * 解析 lambda 表达式, 该方法只是调用了 {@link SerializedLambda#resolve(SFunction)} 中的方法,在此基础上加了缓存。 * 该缓存可能会在任意不定的时间被清除 * * @param func 需要解析的 lambda 对象 * @param 类型,被调用的 Function 对象的目标类型 * @return 返回解析后的结果 - * @see SerializedLambda#resolve(SFunction) */ - public static SerializedLambda resolve(SFunction func) { - Class clazz = func.getClass(); - String name = clazz.getName(); - return Optional.ofNullable(FUNC_CACHE.get(name)) - .map(WeakReference::get) - .orElseGet(() -> { - SerializedLambda lambda = SerializedLambda.resolve(func); - FUNC_CACHE.put(name, new WeakReference<>(lambda)); - return lambda; - }); + public static LambdaMeta extract(SFunction func) { + // 1. IDEA 调试模式下 lambda 表达式是一个代理 + if (func instanceof Proxy) { + return new IdeaProxyLambdaMeta((Proxy) func); + } + // 2. 反射读取 + try { + Method method = func.getClass().getDeclaredMethod("writeReplace"); + return new ReflectLambdaMeta((java.lang.invoke.SerializedLambda) ReflectionKit.setAccessible(method).invoke(func)); + } catch (Throwable e) { + // 3. 反射失败使用序列化的方式读取 + return new ShadowLambdaMeta(SerializedLambda.extract(func)); + } } /** @@ -79,6 +83,14 @@ public final class LambdaUtils { return key.toUpperCase(ENGLISH); } + /** + * 将传入的表信息加入缓存 + * + * @param tableInfo 表信息 + */ + public static void installCache(TableInfo tableInfo) { + COLUMN_CACHE_MAP.put(tableInfo.getEntityType().getName(), createColumnCacheMap(tableInfo)); + } /** * 缓存实体字段 MAP 信息 @@ -115,5 +127,4 @@ public final class LambdaUtils { return info == null ? null : createColumnCacheMap(info); }); } - } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java new file mode 100644 index 0000000..23f3d14 --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java @@ -0,0 +1,61 @@ +package com.github.yulichang.toolkit; + +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.WildcardType; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 反射工具类 + * + * @author yulichang + * @since 2.0.0 + */ +@SuppressWarnings("unused") +public final class MPJReflectionKit { + + private static final Map, Map> CLASS_FIELD_CACHE = new ConcurrentHashMap<>(); + + + /** + * Collection字段的泛型 + */ + public static Class getGenericType(Field field) { + Type type = field.getGenericType(); + //没有写泛型 + if (!(type instanceof ParameterizedType)) { + return Object.class; + } + ParameterizedType pt = (ParameterizedType) type; + Type[] actualTypeArguments = pt.getActualTypeArguments(); + Type argument = actualTypeArguments[0]; + //通配符泛型 ? , ? extends XXX , ? super XXX + if (argument instanceof WildcardType) { + //获取上界 + Type[] types = ((WildcardType) argument).getUpperBounds(); + return (Class) types[0]; + } + return (Class) argument; + } + + /** + * 获取该类的所有属性列表 + * + * @param clazz 反射类 + */ + public static Map getFieldMap(Class clazz) { + if (clazz == null) { + return new HashMap<>(); + } + Map fieldMap = CLASS_FIELD_CACHE.get(clazz); + if (fieldMap != null) { + return fieldMap; + } + Map map = ReflectionKit.getFieldMap(clazz); + CLASS_FIELD_CACHE.put(clazz, map); + return map; + } +} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java index c681018..d9d92a8 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/ReflectionKit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2021, baomidou (jobob@qq.com). + * Copyright (c) 2011-2022, baomidou (jobob@qq.com). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,16 @@ */ package com.github.yulichang.toolkit; -import com.baomidou.mybatisplus.core.toolkit.Assert; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils; -import org.apache.ibatis.logging.Log; -import org.apache.ibatis.logging.LogFactory; +import com.baomidou.mybatisplus.core.toolkit.*; +import com.baomidou.mybatisplus.core.toolkit.reflect.GenericTypeUtils; -import java.lang.reflect.*; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.AccessController; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -37,14 +38,14 @@ import static java.util.stream.Collectors.toMap; * @author hcl * @since 2016-09-22 */ -@SuppressWarnings("unused") +@SuppressWarnings("All") public final class ReflectionKit { - private static final Log logger = LogFactory.getLog(ReflectionKit.class); /** * class field cache */ private static final Map, List> CLASS_FIELD_CACHE = new ConcurrentHashMap<>(); + @Deprecated private static final Map, Class> PRIMITIVE_WRAPPER_TYPE_MAP = new IdentityHashMap<>(8); private static final Map, Class> PRIMITIVE_TYPE_TO_WRAPPER_MAP = new IdentityHashMap<>(8); @@ -83,26 +84,20 @@ public final class ReflectionKit { } } - /** - * Collection字段的泛型 + *

+ * 反射对象获取泛型 + *

+ * + * @param clazz 对象 + * @param genericIfc 所属泛型父类 + * @param index 泛型所在位置 + * @return Class */ - public static Class getGenericType(Field field) { - Type type = field.getGenericType(); - //没有写泛型 - if (!(type instanceof ParameterizedType)) { - return Object.class; - } - ParameterizedType pt = (ParameterizedType) type; - Type[] actualTypeArguments = pt.getActualTypeArguments(); - Type argument = actualTypeArguments[0]; - //通配符泛型 ? , ? extends XXX , ? super XXX - if (argument instanceof WildcardType) { - //获取上界 - Type[] types = ((WildcardType) argument).getUpperBounds(); - return (Class) types[0]; - } - return (Class) argument; + public static Class getSuperClassGenericType(final Class clazz, final Class genericIfc, final int index) { + //update by noear @2021-09-03 + Class[] typeArguments = GenericTypeUtils.resolveTypeArguments(ClassUtils.getUserClass(clazz), genericIfc); + return null == typeArguments ? null : typeArguments[index]; } /** @@ -114,7 +109,7 @@ public final class ReflectionKit { */ public static Map getFieldMap(Class clazz) { List fieldList = getFieldList(clazz); - return CollectionUtils.isNotEmpty(fieldList) ? fieldList.stream().collect(Collectors.toMap(Field::getName, field -> field)) : Collections.emptyMap(); + return CollectionUtils.isNotEmpty(fieldList) ? fieldList.stream().collect(Collectors.toMap(Field::getName, Function.identity())) : Collections.emptyMap(); } /** @@ -145,11 +140,11 @@ public final class ReflectionKit { * 中间表实体重写父类属性 ` private transient Date createTime; ` */ return fieldMap.values().stream() - /* 过滤静态属性 */ - .filter(f -> !Modifier.isStatic(f.getModifiers())) - /* 过滤 transient关键字修饰的属性 */ - .filter(f -> !Modifier.isTransient(f.getModifiers())) - .collect(Collectors.toList()); + /* 过滤静态属性 */ + .filter(f -> !Modifier.isStatic(f.getModifiers())) + /* 过滤 transient关键字修饰的属性 */ + .filter(f -> !Modifier.isTransient(f.getModifiers())) + .collect(Collectors.toList()); }); } @@ -164,12 +159,12 @@ public final class ReflectionKit { public static Map excludeOverrideSuperField(Field[] fields, List superFieldList) { // 子类属性 Map fieldMap = Stream.of(fields).collect(toMap(Field::getName, identity(), - (u, v) -> { - throw new IllegalStateException(String.format("Duplicate key %s", u)); - }, - LinkedHashMap::new)); + (u, v) -> { + throw new IllegalStateException(String.format("Duplicate key %s", u)); + }, + LinkedHashMap::new)); superFieldList.stream().filter(field -> !fieldMap.containsKey(field.getName())) - .forEach(f -> fieldMap.put(f.getName(), f)); + .forEach(f -> fieldMap.put(f.getName(), f)); return fieldMap; } @@ -179,6 +174,7 @@ public final class ReflectionKit { * @param clazz class * @return 是否基本类型或基本包装类型 */ + @Deprecated public static boolean isPrimitiveOrWrapper(Class clazz) { Assert.notNull(clazz, "Class must not be null"); return (clazz.isPrimitive() || PRIMITIVE_WRAPPER_TYPE_MAP.containsKey(clazz)); @@ -187,4 +183,16 @@ public final class ReflectionKit { public static Class resolvePrimitiveIfNecessary(Class clazz) { return (clazz.isPrimitive() && clazz != void.class ? PRIMITIVE_TYPE_TO_WRAPPER_MAP.get(clazz) : clazz); } + + /** + * 设置可访问对象的可访问权限为 true + * + * @param object 可访问的对象 + * @param 类型 + * @return 返回设置后的对象 + */ + public static T setAccessible(T object) { + return AccessController.doPrivileged(new SetAccessibleAction<>(object)); + } + } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java index 2d4df23..9a4c95c 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java @@ -8,7 +8,7 @@ import lombok.Getter; * * @author yulichang * @see com.baomidou.mybatisplus.core.toolkit.support.ColumnCache - * @since 1.2.5 + * @since 1.3.0 */ public class ColumnCache extends com.baomidou.mybatisplus.core.toolkit.support.ColumnCache { diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/IdeaProxyLambdaMeta.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/IdeaProxyLambdaMeta.java new file mode 100644 index 0000000..a4c3482 --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/IdeaProxyLambdaMeta.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2011-2022, baomidou (jobob@qq.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.yulichang.toolkit.support; + +import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; +import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; + +/** + * 在 IDEA 的 Evaluate 中执行的 Lambda 表达式元数据需要使用该类处理元数据 + *

+ * Create by hcl at 2021/5/17 + */ +public class IdeaProxyLambdaMeta implements LambdaMeta { + private static final Field FIELD_MEMBER_NAME; + private static final Field FIELD_MEMBER_NAME_CLAZZ; + private static final Field FIELD_MEMBER_NAME_NAME; + + static { + try { + Class classDirectMethodHandle = Class.forName("java.lang.invoke.DirectMethodHandle"); + FIELD_MEMBER_NAME = ReflectionKit.setAccessible(classDirectMethodHandle.getDeclaredField("member")); + Class classMemberName = Class.forName("java.lang.invoke.MemberName"); + FIELD_MEMBER_NAME_CLAZZ = ReflectionKit.setAccessible(classMemberName.getDeclaredField("clazz")); + FIELD_MEMBER_NAME_NAME = ReflectionKit.setAccessible(classMemberName.getDeclaredField("name")); + } catch (ClassNotFoundException | NoSuchFieldException e) { + throw new MybatisPlusException(e); + } + } + + private final Class clazz; + private final String name; + + public IdeaProxyLambdaMeta(Proxy func) { + InvocationHandler handler = Proxy.getInvocationHandler(func); + try { + Object dmh = ReflectionKit.setAccessible(handler.getClass().getDeclaredField("val$target")).get(handler); + Object member = FIELD_MEMBER_NAME.get(dmh); + clazz = (Class) FIELD_MEMBER_NAME_CLAZZ.get(member); + name = (String) FIELD_MEMBER_NAME_NAME.get(member); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new MybatisPlusException(e); + } + } + + @Override + public String getImplMethodName() { + return name; + } + + @Override + public Class getInstantiatedClass() { + return clazz; + } + + @Override + public String toString() { + return clazz.getSimpleName() + "::" + name; + } + +} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/LambdaMeta.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/LambdaMeta.java new file mode 100644 index 0000000..80295f7 --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/LambdaMeta.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011-2022, baomidou (jobob@qq.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.yulichang.toolkit.support; + +/** + * Lambda 信息 + *

+ * Created by hcl at 2021/5/14 + */ +public interface LambdaMeta { + + /** + * 获取 lambda 表达式实现方法的名称 + * + * @return lambda 表达式对应的实现方法名称 + */ + String getImplMethodName(); + + /** + * 实例化该方法的类 + * + * @return 返回对应的类名称 + */ + Class getInstantiatedClass(); + +} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ReflectLambdaMeta.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ReflectLambdaMeta.java new file mode 100644 index 0000000..11796f7 --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ReflectLambdaMeta.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2011-2022, baomidou (jobob@qq.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.yulichang.toolkit.support; + + +import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.github.yulichang.toolkit.ClassUtils; +import com.github.yulichang.toolkit.ReflectionKit; +import lombok.extern.slf4j.Slf4j; + +import java.lang.invoke.SerializedLambda; +import java.lang.reflect.Field; + +/** + * Created by hcl at 2021/5/14 + */ +@Slf4j +public class ReflectLambdaMeta implements LambdaMeta { + private static final Field FIELD_CAPTURING_CLASS; + + static { + Field fieldCapturingClass; + try { + Class aClass = SerializedLambda.class; + fieldCapturingClass = ReflectionKit.setAccessible(aClass.getDeclaredField("capturingClass")); + } catch (Throwable e) { + // 解决高版本 jdk 的问题 gitee: https://gitee.com/baomidou/mybatis-plus/issues/I4A7I5 + log.warn(e.getMessage()); + fieldCapturingClass = null; + } + FIELD_CAPTURING_CLASS = fieldCapturingClass; + } + + private final SerializedLambda lambda; + + public ReflectLambdaMeta(SerializedLambda lambda) { + this.lambda = lambda; + } + + @Override + public String getImplMethodName() { + return lambda.getImplMethodName(); + } + + @Override + public Class getInstantiatedClass() { + String instantiatedMethodType = lambda.getInstantiatedMethodType(); + String instantiatedType = instantiatedMethodType.substring(2, instantiatedMethodType.indexOf(StringPool.SEMICOLON)).replace(StringPool.SLASH, StringPool.DOT); + return ClassUtils.toClassConfident(instantiatedType, getCapturingClassClassLoader()); + } + + private ClassLoader getCapturingClassClassLoader() { + // 如果反射失败,使用默认的 classloader + if (FIELD_CAPTURING_CLASS == null) { + return null; + } + try { + return ((Class) FIELD_CAPTURING_CLASS.get(lambda)).getClassLoader(); + } catch (IllegalAccessException e) { + throw new MybatisPlusException(e); + } + } + +} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SelectColumn.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SelectColumn.java index 1d4d96c..964cfc1 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SelectColumn.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SelectColumn.java @@ -9,7 +9,7 @@ import lombok.Getter; * MPJLambdaWrapper 查询字段 * * @author yulichang - * @since 1.2.5 + * @since 1.3.0 */ @Getter public class SelectColumn { diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SerializedLambda.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SerializedLambda.java index c1d5195..4b7d4cb 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SerializedLambda.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/SerializedLambda.java @@ -1,18 +1,31 @@ +/* + * Copyright (c) 2011-2022, baomidou (jobob@qq.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.github.yulichang.toolkit.support; -import com.baomidou.mybatisplus.core.toolkit.ClassUtils; -import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils; -import com.baomidou.mybatisplus.core.toolkit.SerializationUtils; -import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; import java.io.*; /** - * copy mp before 3.4.3 + * 当前类是 {@link java.lang.invoke.SerializedLambda } 的一个镜像 + *

+ * Create by hcl at 2020/7/17 */ -@SuppressWarnings("unused") +@SuppressWarnings("ALL") public class SerializedLambda implements Serializable { - private static final long serialVersionUID = 8025925345765570181L; private Class capturingClass; @@ -26,98 +39,35 @@ public class SerializedLambda implements Serializable { private String instantiatedMethodType; private Object[] capturedArgs; - /** - * 通过反序列化转换 lambda 表达式,该方法只能序列化 lambda 表达式,不能序列化接口实现或者正常非 lambda 写法的对象 - * - * @param lambda lambda对象 - * @return 返回解析后的 SerializedLambda - */ - public static SerializedLambda resolve(SFunction lambda) { - if (!lambda.getClass().isSynthetic()) { - throw ExceptionUtils.mpe("该方法仅能传入 lambda 表达式产生的合成类"); - } - try (ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(SerializationUtils.serialize(lambda))) { - @Override - protected Class resolveClass(ObjectStreamClass objectStreamClass) throws IOException, ClassNotFoundException { - Class clazz; - try { - clazz = ClassUtils.toClassConfident(objectStreamClass.getName()); - } catch (Exception ex) { - clazz = super.resolveClass(objectStreamClass); + public static SerializedLambda extract(Serializable serializable) { + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(serializable); + oos.flush(); + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())) { + @Override + protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { + Class clazz = super.resolveClass(desc); + return clazz == java.lang.invoke.SerializedLambda.class ? SerializedLambda.class : clazz; } - return clazz == java.lang.invoke.SerializedLambda.class ? SerializedLambda.class : clazz; + + }) { + return (SerializedLambda) ois.readObject(); } - }) { - return (SerializedLambda) objIn.readObject(); - } catch (ClassNotFoundException | IOException e) { - throw ExceptionUtils.mpe("This is impossible to happen", e); + } catch (IOException | ClassNotFoundException e) { + throw new MybatisPlusException(e); } } - /** - * 获取接口 class - * - * @return 返回 class 名称 - */ - public String getFunctionalInterfaceClassName() { - return normalizedName(functionalInterfaceClass); + public String getInstantiatedMethodType() { + return instantiatedMethodType; } - /** - * 获取实现的 class - * - * @return 实现类 - */ - public Class getImplClass() { - return ClassUtils.toClassConfident(getImplClassName()); + public Class getCapturingClass() { + return capturingClass; } - /** - * 获取 class 的名称 - * - * @return 类名 - */ - public String getImplClassName() { - return normalizedName(implClass); - } - - /** - * 获取实现者的方法名称 - * - * @return 方法名称 - */ public String getImplMethodName() { return implMethodName; } - - /** - * 正常化类名称,将类名称中的 / 替换为 . - * - * @param name 名称 - * @return 正常的类名 - */ - private String normalizedName(String name) { - return name.replace('/', '.'); - } - - /** - * @return 获取实例化方法的类型 - */ - public Class getInstantiatedType() { - String instantiatedTypeName = normalizedName(instantiatedMethodType.substring(2, instantiatedMethodType.indexOf(';'))); - return ClassUtils.toClassConfident(instantiatedTypeName); - } - - /** - * @return 字符串形式 - */ - @Override - public String toString() { - String interfaceName = getFunctionalInterfaceClassName(); - String implName = getImplClassName(); - return String.format("%s -> %s::%s", - interfaceName.substring(interfaceName.lastIndexOf('.') + 1), - implName.substring(implName.lastIndexOf('.') + 1), - implMethodName); - } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ShadowLambdaMeta.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ShadowLambdaMeta.java new file mode 100644 index 0000000..d1a3ad4 --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ShadowLambdaMeta.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011-2022, baomidou (jobob@qq.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.yulichang.toolkit.support; + + +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.github.yulichang.toolkit.ClassUtils; + +/** + * 基于 {@link com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda} 创建的元信息 + *

+ * Create by hcl at 2021/7/7 + */ +public class ShadowLambdaMeta implements LambdaMeta { + private final SerializedLambda lambda; + + public ShadowLambdaMeta(SerializedLambda lambda) { + this.lambda = lambda; + } + + @Override + public String getImplMethodName() { + return lambda.getImplMethodName(); + } + + @Override + public Class getInstantiatedClass() { + String instantiatedMethodType = lambda.getInstantiatedMethodType(); + String instantiatedType = instantiatedMethodType.substring(2, instantiatedMethodType.indexOf(StringPool.SEMICOLON)).replace(StringPool.SLASH, StringPool.DOT); + return ClassUtils.toClassConfident(instantiatedType, lambda.getCapturingClass().getClassLoader()); + } + +} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java index bbadbb7..51e47cf 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java @@ -10,11 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.Assert; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; -import com.github.yulichang.exception.MPJException; -import com.github.yulichang.toolkit.Constant; -import com.github.yulichang.toolkit.LambdaUtils; -import com.github.yulichang.toolkit.MPJWrappers; -import com.github.yulichang.toolkit.ReflectionKit; +import com.github.yulichang.toolkit.*; import com.github.yulichang.toolkit.support.ColumnCache; import com.github.yulichang.toolkit.support.SelectColumn; import com.github.yulichang.wrapper.enums.BaseFuncEnum; @@ -165,7 +161,7 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper * 会自动将 UserAddressDO类中相同属性的字段 以mybatis的方式映射到UserDTO.addressListDTO属性中 * - * @since 1.2.5 + * @since 1.3.0 * * @param child 连表数据库实体类 * @param dtoField 包装类对应的属性 @@ -177,19 +173,16 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper> MPJLambdaWrapper selectCollection(Class child, SFunction dtoField) { String dtoFieldName = LambdaUtils.getName(dtoField); Class dtoClass = LambdaUtils.getEntityClass(dtoField); - Map fieldMap = ReflectionKit.getFieldMap(dtoClass); + Map fieldMap = MPJReflectionKit.getFieldMap(dtoClass); Field field = fieldMap.get(dtoFieldName); this.resultMap = true; - Class genericType = ReflectionKit.getGenericType(field); + Class genericType = MPJReflectionKit.getGenericType(field); MybatisLabel.Builder builder; if (genericType == null || genericType.isAssignableFrom(child)) { //找不到集合泛型 List List List , 直接查询数据库实体 builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType()); } else { Class ofType = (Class) genericType; - if (ReflectionKit.isPrimitiveOrWrapper(ofType)) { - throw new MPJException("collection 不支持基本数据类型"); - } builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), ofType, true); } this.resultMapMybatisLabel.add(builder.build()); @@ -214,7 +207,7 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper的方式映射到UserDTO.addressListDTO属性中 * - * @since 1.2.5 + * @since 1.3.0 * * @param child 连表数据库实体类 * @param dtoField 包装类对应的属性 @@ -228,10 +221,10 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper child, SFunction dtoField, MFunc> collection) { String dtoFieldName = LambdaUtils.getName(dtoField); Class dtoClass = LambdaUtils.getEntityClass(dtoField); - Field field = ReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); + Field field = MPJReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); this.resultMap = true; //获取集合泛型 - Class genericType = ReflectionKit.getGenericType(field); + Class genericType = MPJReflectionKit.getGenericType(field); Class ofType = (Class) genericType; MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), ofType, false); this.resultMapMybatisLabel.add(collection.apply(builder).build()); @@ -241,17 +234,14 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper MPJLambdaWrapper selectAssociation(Class child, SFunction dtoField) { String dtoFieldName = LambdaUtils.getName(dtoField); Class dtoClass = LambdaUtils.getEntityClass(dtoField); - Map fieldMap = ReflectionKit.getFieldMap(dtoClass); + Map fieldMap = MPJReflectionKit.getFieldMap(dtoClass); Field field = fieldMap.get(dtoFieldName); Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); - if (ReflectionKit.isPrimitiveOrWrapper(field.getType())) { - throw new MPJException("association 不支持基本数据类型"); - } this.resultMap = true; MybatisLabel.Builder builder; builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) field.getType(), true); @@ -262,18 +252,15 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper MPJLambdaWrapper selectAssociation(Class child, SFunction dtoField, MFunc> collection) { String dtoFieldName = LambdaUtils.getName(dtoField); Class dtoClass = LambdaUtils.getEntityClass(dtoField); - Field field = ReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); + Field field = MPJReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); this.resultMap = true; Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); - if (ReflectionKit.isPrimitiveOrWrapper(field.getType())) { - throw new MPJException("association 不支持基本数据类型"); - } MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) child, false); this.resultMapMybatisLabel.add(collection.apply(builder).build()); return typedThis; diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java index 59d2093..4e80bc8 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java @@ -6,9 +6,8 @@ import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; 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.exception.MPJException; import com.github.yulichang.toolkit.LambdaUtils; -import com.github.yulichang.toolkit.ReflectionKit; +import com.github.yulichang.toolkit.MPJReflectionKit; import lombok.Getter; import java.lang.reflect.Field; @@ -23,7 +22,7 @@ import java.util.stream.Collectors; * collection 标签 目前先支持这几个属性 后续在扩展 * * @author yulichang - * @since 1.2.5 + * @since 1.3.0 */ @Getter public class MybatisLabel { @@ -120,18 +119,15 @@ public class MybatisLabel { public > Builder collection(Class entityClass, SFunction func) { String dtoFieldName = LambdaUtils.getName(func); Class dtoClass = LambdaUtils.getEntityClass(func); - Map fieldMap = ReflectionKit.getFieldMap(dtoClass); + Map fieldMap = MPJReflectionKit.getFieldMap(dtoClass); Field field = fieldMap.get(dtoFieldName); - Class genericType = ReflectionKit.getGenericType(field); + Class genericType = MPJReflectionKit.getGenericType(field); MybatisLabel.Builder builder; if (genericType == null || genericType.isAssignableFrom(entityClass)) { //找不到集合泛型 List List List , 直接查询数据库实体 builder = new Builder<>(dtoFieldName, entityClass, field.getType()); } else { Class ofType = (Class) genericType; - if (ReflectionKit.isPrimitiveOrWrapper(ofType)) { - throw new MPJException("collection 不支持基本数据类型"); - } builder = new Builder<>(dtoFieldName, entityClass, field.getType(), ofType, true); } mybatisLabel.mybatisLabels.add(builder.build()); @@ -144,9 +140,9 @@ public class MybatisLabel { public > Builder collection(Class entityClass, SFunction func, MFunc> mFunc) { String dtoFieldName = LambdaUtils.getName(func); Class dtoClass = LambdaUtils.getEntityClass(func); - Field field = ReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); + Field field = MPJReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); //获取集合泛型 - Class genericType = ReflectionKit.getGenericType(field); + Class genericType = MPJReflectionKit.getGenericType(field); Class ofType = (Class) genericType; MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, entityClass, field.getType(), ofType, false); mybatisLabel.mybatisLabels.add(mFunc.apply(builder).build()); @@ -158,13 +154,10 @@ public class MybatisLabel { */ public Builder association(Class child, SFunction dtoField) { Class dtoClass = LambdaUtils.getEntityClass(dtoField); - Map fieldMap = ReflectionKit.getFieldMap(dtoClass); + Map fieldMap = MPJReflectionKit.getFieldMap(dtoClass); String dtoFieldName = LambdaUtils.getName(dtoField); Field field = fieldMap.get(dtoFieldName); Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); - if (ReflectionKit.isPrimitiveOrWrapper(field.getType())) { - throw new MPJException("association 不支持基本数据类型"); - } MybatisLabel.Builder builder; builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) field.getType(), true); mybatisLabel.mybatisLabels.add(builder.build()); @@ -178,11 +171,8 @@ public class MybatisLabel { MFunc> collection) { String dtoFieldName = LambdaUtils.getName(dtoField); Class dtoClass = LambdaUtils.getEntityClass(dtoField); - Field field = ReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); + Field field = MPJReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); - if (ReflectionKit.isPrimitiveOrWrapper(field.getType())) { - throw new MPJException("association 不支持基本数据类型"); - } MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) child, false); mybatisLabel.mybatisLabels.add(collection.apply(builder).build()); return this; @@ -198,7 +188,7 @@ public class MybatisLabel { private void autoBuild(boolean auto, Class entityClass, Class tagClass) { TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass); - Map tagMap = ReflectionKit.getFieldMap(tagClass); + Map tagMap = MPJReflectionKit.getFieldMap(tagClass); if (auto && !tagMap.isEmpty()) { Function build = field -> { Result result = new Result(); diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Result.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Result.java index 99675e7..6105c79 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Result.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/Result.java @@ -17,7 +17,7 @@ import org.apache.ibatis.type.TypeHandler; * result 标签 * * @author yulichang - * @since 1.2.5 + * @since 1.3.0 */ @Getter @Setter(AccessLevel.PACKAGE) diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml index 3317236..bd13058 100644 --- a/mybatis-plus-join-test/pom.xml +++ b/mybatis-plus-join-test/pom.xml @@ -9,6 +9,7 @@ mybatis-plus-join-root 2.0.0 + 2.0.0 mybatis-plus-join-test mybatis-plus-join-test @@ -70,24 +71,35 @@ com.baomidou mybatis-plus-boot-starter - ${mybatis-plus.version} + + 3.4.2 com.github.yulichang mybatis-plus-join-boot-starter - ${mybaits-plus-join.version} + 2.0.0 - - com.github.pagehelper - pagehelper-spring-boot-starter - 1.4.5 - + + + + + com.fasterxml.jackson.core jackson-databind 2.14.0 + + org.springframework + spring-jdbc + 5.3.4 + + + + + + \ No newline at end of file diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/Application.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/Application.java new file mode 100644 index 0000000..b8b9aee --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/Application.java @@ -0,0 +1,9 @@ +package com.github.yulichang.test.collection; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication +public class Application { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/CollectionTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/CollectionTest.java new file mode 100644 index 0000000..7487c66 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/CollectionTest.java @@ -0,0 +1,47 @@ +package com.github.yulichang.test.collection; + +import com.github.yulichang.test.collection.dto.TableADTO; +import com.github.yulichang.test.collection.dto.TableBDTO; +import com.github.yulichang.test.collection.dto.TableCDTO; +import com.github.yulichang.test.collection.dto.TableDDTO; +import com.github.yulichang.test.collection.entity.*; +import com.github.yulichang.test.collection.mapper.TableAMapper; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 连表测试类 + *

+ * 支持mybatis-plus 查询枚举字段 + * 支持mybatis-plus typeHandle功能 + *

+ * 移除了mybatis-plus 逻辑删除支持,逻辑删除需要在连表查询时自己添加对应的条件 + */ +@SuppressWarnings("unused") +@SpringBootTest(properties = "spring.profiles.active=collection") +class CollectionTest { + @Resource + private TableAMapper tableAMapper; + + @Test + void testJoinCollection() { + //4层嵌套 a对多b b对多c c对多d d对多e + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + .selectAll(TableA.class) + .selectCollection(TableB.class, TableADTO::getBList, b -> b + .collection(TableC.class, TableBDTO::getCcList, c -> c + .collection(TableD.class, TableCDTO::getDList, d -> d + .collection(TableE.class, TableDDTO::getEList)))) + .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); + + List dtos = tableAMapper.selectJoinList(TableADTO.class, wrapper); + System.out.println(dtos); + } +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/config/MybatisPlusConfig.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/config/MybatisPlusConfig.java new file mode 100644 index 0000000..f3600a4 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/config/MybatisPlusConfig.java @@ -0,0 +1,24 @@ +package com.github.yulichang.test.collection.config; + +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * mybatis-plus配置 + */ +@Configuration +public class MybatisPlusConfig { + + /** + * 分页插件 + */ + @Bean + public MybatisPlusInterceptor paginationInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + PaginationInnerInterceptor page = new PaginationInnerInterceptor(); + interceptor.addInnerInterceptor(page); + return interceptor; + } +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableADTO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableADTO.java new file mode 100644 index 0000000..baec4bb --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableADTO.java @@ -0,0 +1,17 @@ +package com.github.yulichang.test.collection.dto; + +import lombok.Data; +import lombok.ToString; + +import java.util.List; + +@Data +@ToString +public class TableADTO { + + private Integer id; + + private String name; + + private List bList; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableBDTO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableBDTO.java new file mode 100644 index 0000000..b8643b5 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableBDTO.java @@ -0,0 +1,19 @@ +package com.github.yulichang.test.collection.dto; + +import lombok.Data; +import lombok.ToString; + +import java.util.List; + +@Data +@ToString +public class TableBDTO { + + private Integer id; + + private Integer aid; + + private String name; + + private List ccList; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableCDTO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableCDTO.java new file mode 100644 index 0000000..cb4c573 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableCDTO.java @@ -0,0 +1,19 @@ +package com.github.yulichang.test.collection.dto; + +import lombok.Data; +import lombok.ToString; + +import java.util.List; + +@Data +@ToString +public class TableCDTO { + + private Integer id; + + private Integer bid; + + private String name; + + private List dList; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableDDTO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableDDTO.java new file mode 100644 index 0000000..202eaf8 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableDDTO.java @@ -0,0 +1,19 @@ +package com.github.yulichang.test.collection.dto; + +import lombok.Data; +import lombok.ToString; + +import java.util.List; + +@Data +@ToString +public class TableDDTO { + + private Integer id; + + private Integer cid; + + private String name; + + private List eList; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableEDTO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableEDTO.java new file mode 100644 index 0000000..ed47f67 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/dto/TableEDTO.java @@ -0,0 +1,15 @@ +package com.github.yulichang.test.collection.dto; + +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +public class TableEDTO { + + private Integer id; + + private Integer did; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableA.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableA.java new file mode 100644 index 0000000..70209bc --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableA.java @@ -0,0 +1,15 @@ +package com.github.yulichang.test.collection.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_a") +public class TableA { + + @TableId + private Integer id; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableB.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableB.java new file mode 100644 index 0000000..bac6d48 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableB.java @@ -0,0 +1,17 @@ +package com.github.yulichang.test.collection.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_b") +public class TableB { + + @TableId + private Integer id; + + private Integer aid; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableC.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableC.java new file mode 100644 index 0000000..f2d8c30 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableC.java @@ -0,0 +1,17 @@ +package com.github.yulichang.test.collection.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_c") +public class TableC { + + @TableId + private Integer id; + + private Integer bid; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableD.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableD.java new file mode 100644 index 0000000..a73ac1d --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableD.java @@ -0,0 +1,17 @@ +package com.github.yulichang.test.collection.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_d") +public class TableD { + + @TableId + private Integer id; + + private Integer cid; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableE.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableE.java new file mode 100644 index 0000000..6299c75 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/entity/TableE.java @@ -0,0 +1,17 @@ +package com.github.yulichang.test.collection.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_e") +public class TableE { + + @TableId + private Integer id; + + private Integer did; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/enums/Sex.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/enums/Sex.java new file mode 100644 index 0000000..a5382ee --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/enums/Sex.java @@ -0,0 +1,24 @@ +package com.github.yulichang.test.collection.enums; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +public enum Sex { + + MAN(0, "男"), + + WOMAN(1, "女"); + + @EnumValue + private final int code; + private final String des; + + Sex(int code, String des) { + this.code = code; + this.des = des; + } + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableAMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableAMapper.java new file mode 100644 index 0000000..1c71440 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableAMapper.java @@ -0,0 +1,10 @@ +package com.github.yulichang.test.collection.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.collection.entity.TableA; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface TableAMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableBMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableBMapper.java new file mode 100644 index 0000000..c6680f0 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableBMapper.java @@ -0,0 +1,11 @@ +package com.github.yulichang.test.collection.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.collection.entity.TableB; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface TableBMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableCMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableCMapper.java new file mode 100644 index 0000000..148903d --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableCMapper.java @@ -0,0 +1,11 @@ +package com.github.yulichang.test.collection.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.collection.entity.TableC; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface TableCMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableDMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableDMapper.java new file mode 100644 index 0000000..97532cd --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableDMapper.java @@ -0,0 +1,11 @@ +package com.github.yulichang.test.collection.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.collection.entity.TableD; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface TableDMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableEMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableEMapper.java new file mode 100644 index 0000000..10964ff --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/mapper/TableEMapper.java @@ -0,0 +1,11 @@ +package com.github.yulichang.test.collection.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.collection.entity.TableE; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface TableEMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java index a1b9593..7dae67e 100644 --- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java @@ -11,7 +11,6 @@ import com.github.yulichang.test.join.entity.UserDO; import com.github.yulichang.test.join.mapper.UserMapper; import com.github.yulichang.toolkit.MPJWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; -import org.apache.ibatis.session.SqlSessionFactory; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -32,16 +31,9 @@ import java.util.Map; class LambdaWrapperTest { @Resource private UserMapper userMapper; - @Resource - private SqlSessionFactory sqlSessionFactory; - /** - * 一对多 - */ @Test void testJoin() { - userMapper.selectListDeep(new QueryWrapper<>()); - MPJLambdaWrapper wrapper = new MPJLambdaWrapper() .selectAll(UserDO.class) .selectCollection(AddressDO.class, UserDTO::getAddressList, addr -> addr @@ -109,6 +101,7 @@ class LambdaWrapperTest { */ @Test void test6() { + userMapper.selectPage(new Page<>(1, 10),new QueryWrapper<>()); IPage page = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class, MPJWrappers.lambdaJoin() .selectAll(UserDO.class) diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/TableDTO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/TableDTO.java new file mode 100644 index 0000000..c3d6aae --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/dto/TableDTO.java @@ -0,0 +1,61 @@ +package com.github.yulichang.test.join.dto; + +import lombok.Data; + +import java.util.List; + +@Data +public class TableDTO { + + private Integer id; + + private String name; + + private List bbList; + + @Data + public static class TableBDTO { + + private Integer id; + + private Integer aid; + + private String name; + + private List ccList; + } + + @Data + public static class TableCDTO { + + private Integer id; + + private Integer bid; + + private String name; + + private List ddList; + } + + @Data + public static class TableDDTO { + + private Integer id; + + private Integer cid; + + private String name; + + private List eeList; + } + + @Data + public static class TableEDTO { + + private Integer id; + + private Integer did; + + private String name; + } +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableA.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableA.java new file mode 100644 index 0000000..e22d6d7 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableA.java @@ -0,0 +1,15 @@ +package com.github.yulichang.test.join.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_a") +public class TableA { + + @TableId + private Integer id; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableB.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableB.java new file mode 100644 index 0000000..80205b0 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableB.java @@ -0,0 +1,17 @@ +package com.github.yulichang.test.join.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_b") +public class TableB { + + @TableId + private Integer id; + + private Integer aid; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableC.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableC.java new file mode 100644 index 0000000..1ed74e2 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableC.java @@ -0,0 +1,17 @@ +package com.github.yulichang.test.join.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_c") +public class TableC { + + @TableId + private Integer id; + + private Integer bid; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableD.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableD.java new file mode 100644 index 0000000..c44940c --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableD.java @@ -0,0 +1,17 @@ +package com.github.yulichang.test.join.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_d") +public class TableD { + + @TableId + private Integer id; + + private Integer cid; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableE.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableE.java new file mode 100644 index 0000000..e69a7ef --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableE.java @@ -0,0 +1,17 @@ +package com.github.yulichang.test.join.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("table_e") +public class TableE { + + @TableId + private Integer id; + + private Integer did; + + private String name; +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/UserDO.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/UserDO.java index edcd8df..8f589a4 100644 --- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/UserDO.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/UserDO.java @@ -24,7 +24,7 @@ public class UserDO { private Integer id; @TableField(value = "`name`", typeHandler = JacksonTypeHandler.class) - private Map name; + private Map aName; private Sex sex; diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableAMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableAMapper.java new file mode 100644 index 0000000..91a3bea --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableAMapper.java @@ -0,0 +1,11 @@ +package com.github.yulichang.test.join.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.join.entity.TableA; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface TableAMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableBMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableBMapper.java new file mode 100644 index 0000000..a3a2173 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableBMapper.java @@ -0,0 +1,11 @@ +package com.github.yulichang.test.join.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.join.entity.TableB; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface TableBMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableCMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableCMapper.java new file mode 100644 index 0000000..b74a614 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableCMapper.java @@ -0,0 +1,11 @@ +package com.github.yulichang.test.join.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.join.entity.TableC; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface TableCMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableDMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableDMapper.java new file mode 100644 index 0000000..2bd16d6 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableDMapper.java @@ -0,0 +1,11 @@ +package com.github.yulichang.test.join.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.join.entity.TableD; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface TableDMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableEMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableEMapper.java new file mode 100644 index 0000000..2f70960 --- /dev/null +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableEMapper.java @@ -0,0 +1,11 @@ +package com.github.yulichang.test.join.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.test.join.entity.TableE; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +@SuppressWarnings("unused") +public interface TableEMapper extends MPJBaseMapper { + +} diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java index 83d6022..79685b5 100644 --- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java +++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/mapping/config/MybatisPlusConfig.java @@ -18,7 +18,6 @@ public class MybatisPlusConfig { public MybatisPlusInterceptor paginationInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); PaginationInnerInterceptor page = new PaginationInnerInterceptor(); - page.setOptimizeJoin(false); interceptor.addInnerInterceptor(page); return interceptor; } diff --git a/mybatis-plus-join-test/src/test/resources/application-collection.yml b/mybatis-plus-join-test/src/test/resources/application-collection.yml new file mode 100644 index 0000000..00f280f --- /dev/null +++ b/mybatis-plus-join-test/src/test/resources/application-collection.yml @@ -0,0 +1,5 @@ +spring: + sql: + init: + schema-locations: classpath:db/collection/schema.sql + data-locations: classpath:db/collection/data.sql \ No newline at end of file diff --git a/mybatis-plus-join-test/src/test/resources/application.yml b/mybatis-plus-join-test/src/test/resources/application.yml index 6d099dd..b0ad69e 100644 --- a/mybatis-plus-join-test/src/test/resources/application.yml +++ b/mybatis-plus-join-test/src/test/resources/application.yml @@ -6,6 +6,7 @@ spring: password: test mybatis-plus: + typeEnumsPackage: com.github.yulichang.test global-config: db-config: logic-delete-field: del diff --git a/mybatis-plus-join-test/src/test/resources/db/collection/data.sql b/mybatis-plus-join-test/src/test/resources/db/collection/data.sql new file mode 100644 index 0000000..8e9b4c1 --- /dev/null +++ b/mybatis-plus-join-test/src/test/resources/db/collection/data.sql @@ -0,0 +1,29 @@ +-- noinspection SqlDialectInspectionForFile + +-- noinspection SqlNoDataSourceInspectionForFile + +DELETE FROM table_a; +insert into table_a (id, `name`) values (1, 'tableA1'); +insert into table_a (id, `name`) values (2, 'tableA2'); +insert into table_a (id, `name`) values (3, 'tableA3'); + +DELETE FROM table_b; +insert into table_b (id, aid, `name`) values (1, 1, 'tableB1'); +insert into table_b (id, aid, `name`) values (2, 1, 'tableB2'); +insert into table_b (id, aid, `name`) values (3, 2, 'tableB3'); + +DELETE FROM table_c; +insert into table_c (id, bid, `name`) values (1, 1, 'tableC1'); +insert into table_c (id, bid, `name`) values (2, 1, 'tableC2'); +insert into table_c (id, bid, `name`) values (3, 2, 'tableC3'); + +DELETE FROM table_d; +insert into table_d (id, cid, `name`) values (1, 1, 'tableD1'); +insert into table_d (id, cid, `name`) values (2, 1, 'tableD2'); +insert into table_d (id, cid, `name`) values (3, 2, 'tableD3'); + +DELETE FROM table_e; +insert into table_e (id, did, `name`) values (1, 1, 'tableE1'); +insert into table_e (id, did, `name`) values (2, 1, 'tableE2'); +insert into table_e (id, did, `name`) values (3, 2, 'tableE3'); + diff --git a/mybatis-plus-join-test/src/test/resources/db/collection/schema.sql b/mybatis-plus-join-test/src/test/resources/db/collection/schema.sql new file mode 100644 index 0000000..d8a1fc8 --- /dev/null +++ b/mybatis-plus-join-test/src/test/resources/db/collection/schema.sql @@ -0,0 +1,48 @@ +-- noinspection SqlDialectInspectionForFile + +-- noinspection SqlNoDataSourceInspectionForFile + + +DROP TABLE IF EXISTS table_a; +create table table_a +( + id int auto_increment + primary key, + `name` varchar(255) null +); + +DROP TABLE IF EXISTS table_b; +create table table_b +( + id int auto_increment + primary key, + `aid` int not null, + `name` varchar(255) null +); + +DROP TABLE IF EXISTS table_c; +create table table_c +( + id int auto_increment + primary key, + `bid` int not null, + `name` varchar(255) null +); + +DROP TABLE IF EXISTS table_d; +create table table_d +( + id int auto_increment + primary key, + `cid` int not null, + `name` varchar(255) null +); + +DROP TABLE IF EXISTS table_e; +create table table_e +( + id int auto_increment + primary key, + `did` int not null, + `name` varchar(255) null +); \ No newline at end of file diff --git a/mybatis-plus-join-test/src/test/resources/db/join/data.sql b/mybatis-plus-join-test/src/test/resources/db/join/data.sql index 2f8baa0..6bd397b 100644 --- a/mybatis-plus-join-test/src/test/resources/db/join/data.sql +++ b/mybatis-plus-join-test/src/test/resources/db/join/data.sql @@ -76,4 +76,5 @@ INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (18,18, 100 INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (19,19, 10019, '10000000019', '曹县19', false); INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (20,20, 10020, '10000000020', '曹县20', false); INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (21,21, 10021, '10000000021', '曹县21', false); -INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (22,22, 10022, '10000000022', '曹县22', false); \ No newline at end of file +INSERT INTO address (id, user_id, area_id, tel, address, del) VALUES (22,22, 10022, '10000000022', '曹县22', false); + diff --git a/mybatis-plus-join-test/src/test/resources/db/join/schema.sql b/mybatis-plus-join-test/src/test/resources/db/join/schema.sql index 264b2ea..f728079 100644 --- a/mybatis-plus-join-test/src/test/resources/db/join/schema.sql +++ b/mybatis-plus-join-test/src/test/resources/db/join/schema.sql @@ -12,20 +12,20 @@ create table area city varchar(255) null, area varchar(255) null, postcode varchar(255) null, - del bit + del bit ); DROP TABLE IF EXISTS `user`; create table `user` ( - id int auto_increment + id int auto_increment primary key, - `name` varchar(255) not null, - `address_id` int not null, - sex tinyint not null, - head_img varchar(255) not null, - del bit + `name` varchar(255) not null, + `address_id` int not null, + sex tinyint not null, + head_img varchar(255) not null, + del bit ); DROP TABLE IF EXISTS address; @@ -34,9 +34,9 @@ create table address ( id int auto_increment primary key, - user_id int null, - area_id int null, + user_id int null, + area_id int null, tel varchar(255) null, address varchar(255) null, - del bit + del bit ); \ No newline at end of file From 37feb491b69c7de0a09e6faa76f1f08a0866b14f Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 16 Nov 2022 18:40:01 +0800 Subject: [PATCH 12/23] =?UTF-8?q?=E5=B5=8C=E5=A5=97=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mybatis-plus-join-test/pom.xml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml index bd13058..e4d3920 100644 --- a/mybatis-plus-join-test/pom.xml +++ b/mybatis-plus-join-test/pom.xml @@ -71,8 +71,7 @@ com.baomidou mybatis-plus-boot-starter - - 3.4.2 + 3.4.2 com.github.yulichang @@ -80,11 +79,11 @@ 2.0.0 - - - - - + + + + + com.fasterxml.jackson.core jackson-databind @@ -95,11 +94,6 @@ spring-jdbc 5.3.4 - - - - - \ No newline at end of file From 6dd3a1ec3c1f2f121f598af76a77e24ac75debe8 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 16 Nov 2022 18:55:04 +0800 Subject: [PATCH 13/23] pom --- mybatis-plus-join-annotation/pom.xml | 2 +- mybatis-plus-join-boot-starter/pom.xml | 4 ++-- mybatis-plus-join-core/pom.xml | 4 ++-- mybatis-plus-join-test/pom.xml | 2 +- pom.xml | 4 ---- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/mybatis-plus-join-annotation/pom.xml b/mybatis-plus-join-annotation/pom.xml index 463b4c9..72403c9 100644 --- a/mybatis-plus-join-annotation/pom.xml +++ b/mybatis-plus-join-annotation/pom.xml @@ -47,7 +47,7 @@ com.baomidou mybatis-plus-core - ${mybatis-plus.version} + 3.5.2 provided diff --git a/mybatis-plus-join-boot-starter/pom.xml b/mybatis-plus-join-boot-starter/pom.xml index 660091f..c88f5e8 100644 --- a/mybatis-plus-join-boot-starter/pom.xml +++ b/mybatis-plus-join-boot-starter/pom.xml @@ -58,13 +58,13 @@ com.baomidou mybatis-plus-boot-starter - ${mybatis-plus.version} + 3.5.2 provided org.projectlombok lombok - ${lombok.version} + 1.18.24 provided diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml index d48f1c6..8cc1ba5 100644 --- a/mybatis-plus-join-core/pom.xml +++ b/mybatis-plus-join-core/pom.xml @@ -52,13 +52,13 @@ com.baomidou mybatis-plus-extension - ${mybatis-plus.version} + 3.5.2 provided org.projectlombok lombok - ${lombok.version} + 1.18.24 provided diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml index e4d3920..396ae49 100644 --- a/mybatis-plus-join-test/pom.xml +++ b/mybatis-plus-join-test/pom.xml @@ -66,7 +66,7 @@ org.projectlombok lombok - ${lombok.version} + 1.18.24 com.baomidou diff --git a/pom.xml b/pom.xml index f7a7274..c10686c 100644 --- a/pom.xml +++ b/pom.xml @@ -37,10 +37,6 @@ - 2.0.0 - 3.5.2 - 1.18.24 - 1.8 1.8 1.8 From 2b05832304674740f1524379285296a41d3ec5a7 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Mon, 21 Nov 2022 19:30:36 +0800 Subject: [PATCH 14/23] id --- .../java/com/github/yulichang/interceptor/MPJInterceptor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 95965ec..9aabb62 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 @@ -200,7 +200,8 @@ public class MPJInterceptor implements Interceptor { } else { // 主键列 resultMappings.add(new ResultMapping.Builder(ms.getConfiguration(), i.getTagProperty(), - StringUtils.getTargetColumn(i.getColumnName()), i.getKeyType()).build()); + StringUtils.getTargetColumn(i.getColumnName()), i.getKeyType()) + .flags(Collections.singletonList(ResultFlag.ID)).build()); } } Set columnSet = resultMappings.stream().map(ResultMapping::getColumn).collect(Collectors.toSet()); From a6eb12bc9e42b6818eac558ec7302934b619d8d0 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Tue, 22 Nov 2022 09:53:30 +0800 Subject: [PATCH 15/23] id --- .../java/com/github/yulichang/interceptor/MPJInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9aabb62..831782a 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 @@ -95,7 +95,7 @@ public class MPJInterceptor implements Interceptor { public MappedStatement getMappedStatement(MappedStatement ms, Class resultType, Object ew) { String id = ms.getId() + StringPool.UNDERSCORE + resultType.getName(); - if (ew instanceof MPJLambdaWrapper) { + if (ew instanceof MPJLambdaWrapper && ((MPJLambdaWrapper) ew).isResultMap()) { //不走缓存 return buildMappedStatement(ms, resultType, ew, id); } From f8ca459519766390dd1fee35cf1488b0d44d9eb4 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Tue, 22 Nov 2022 16:21:23 +0800 Subject: [PATCH 16/23] =?UTF-8?q?LambdaWrapper=E5=89=AF=E8=A1=A8=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=80=BB=E8=BE=91=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MybatisPlusJoinAutoConfiguration.java | 2 + .../MybatisPlusJoinProperties.java | 7 +- ...itional-spring-configuration-metadata.json | 6 + .../yulichang/config/ConfigProperties.java | 9 ++ .../yulichang/interceptor/MPJInterceptor.java | 2 +- .../yulichang/method/MPJBaseMethod.java | 7 ++ .../yulichang/toolkit/LogicInfoUtils.java | 40 +++++++ .../yulichang/toolkit/MPJReflectionKit.java | 3 +- .../yulichang/wrapper/MPJLambdaWrapper.java | 54 +++++---- .../wrapper/interfaces/LambdaJoin.java | 93 +++------------ .../yulichang/wrapper/interfaces/Query.java | 110 +----------------- 11 files changed, 121 insertions(+), 212 deletions(-) create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java 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 e203d8b..c67983f 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 @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.autoconfigure.MybatisPlusLanguageDriverAutoConfi import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector; import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; import com.baomidou.mybatisplus.core.injector.ISqlInjector; +import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.config.InterceptorConfig; import com.github.yulichang.injector.MPJSqlInjector; import com.github.yulichang.interceptor.MPJInterceptor; @@ -55,6 +56,7 @@ public class MybatisPlusJoinAutoConfiguration { public MybatisPlusJoinAutoConfiguration(MybatisPlusJoinProperties properties) { this.properties = properties; + ConfigProperties.subTableLogic = properties.getSubTableLogic(); } /** diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java index bb23df8..2b7228d 100644 --- a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java +++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java @@ -18,5 +18,10 @@ public class MybatisPlusJoinProperties { /** * 打印banner */ - private Boolean banner = false; + private Boolean banner = true; + + /** + * 连表查询副表是否启用逻辑删除(前提是MP配置了逻辑删除) + */ + private Boolean subTableLogic = true; } 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 aa9ddcb..de6b922 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 @@ -12,6 +12,12 @@ "defaultValue": true, "type": "java.lang.Boolean", "description": "打印 banner." + }, + { + "name": "mybatis-plus-join.sub-table-logic", + "defaultValue": true, + "type": "java.lang.Boolean", + "description": "连表查询副表是否启用逻辑删除(前提是MP配置了逻辑删除)." } ] } \ No newline at end of file diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java new file mode 100644 index 0000000..71eb06f --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java @@ -0,0 +1,9 @@ +package com.github.yulichang.config; + +/** + * @author yulichang + * @since 2.0.0 + */ +public class ConfigProperties { + public static boolean subTableLogic = true; +} 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 831782a..63db8b4 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 @@ -315,7 +315,7 @@ public class MPJInterceptor implements Interceptor { pool.add(columnName); return columnName; } - columnName = "mpj_" + StringUtils.getTargetColumn(columnName); + columnName = "join_" + StringUtils.getTargetColumn(columnName); return getColumn(pool, columnName); } 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 dae42c6..d1bfbd4 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 @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils; +import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.toolkit.Constant; import java.util.Objects; @@ -26,6 +27,9 @@ public interface MPJBaseMethod extends Constants { sqlScript = SqlScriptUtils.convertIf(sqlScript, String.format("%s != null", WRAPPER_ENTITY), true); sqlScript += NEWLINE; sqlScript += (NEWLINE + getLogicDeleteSql(table, true, true) + NEWLINE); + if (ConfigProperties.subTableLogic) { + sqlScript += (String.format("${%s.logicSql}", 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); @@ -37,6 +41,9 @@ public interface MPJBaseMethod extends Constants { String sqlScript = getAllSqlWhere(table, false, true, WRAPPER_ENTITY_DOT); sqlScript = SqlScriptUtils.convertIf(sqlScript, String.format("%s != null", WRAPPER_ENTITY), true); sqlScript += NEWLINE; + if (ConfigProperties.subTableLogic) { + sqlScript += String.format("${%s.logicSql}", WRAPPER); + } sqlScript += SqlScriptUtils.convertIf(String.format("${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_NONEMPTYOFWHERE), true); sqlScript = SqlScriptUtils.convertWhere(sqlScript) + NEWLINE; sqlScript += SqlScriptUtils.convertIf(String.format(" ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_EMPTYOFWHERE), true); diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java new file mode 100644 index 0000000..c0768e2 --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java @@ -0,0 +1,40 @@ +package com.github.yulichang.toolkit; + +import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; +import com.baomidou.mybatisplus.core.toolkit.Assert; +import com.baomidou.mybatisplus.core.toolkit.Constants; + +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 逻辑删除信息类 + * + * @author yulichang + * @since 2.0.0 + */ +public class LogicInfoUtils implements Constants { + + private static final Map, String> LOGIC_CACHE = new ConcurrentHashMap<>(); + + + @SuppressWarnings("ConstantConditions") + public static String getLogicInfo(int tableIndex, Class clazz) { + String logicStr = LOGIC_CACHE.get(clazz); + if (Objects.nonNull(logicStr)) { + return logicStr; + } + TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz); + Assert.notNull(tableInfo, "%s 不是数据库实体或没有注册到mybatis plus中", clazz.getName()); + final String value = tableInfo.getLogicDeleteFieldInfo().getLogicNotDeleteValue(); + if (NULL.equalsIgnoreCase(value)) { + logicStr = Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + " IS NULL"; + } else { + logicStr = Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + EQUALS + String.format(tableInfo.getLogicDeleteFieldInfo().isCharSequence() ? "'%s'" : "%s", value); + } + LOGIC_CACHE.put(clazz, logicStr); + return logicStr; + } +} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java index 23f3d14..18e55f2 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java @@ -19,6 +19,7 @@ public final class MPJReflectionKit { private static final Map, Map> CLASS_FIELD_CACHE = new ConcurrentHashMap<>(); + private static final Map EMPTY_MAP = new HashMap<>(); /** * Collection字段的泛型 @@ -48,7 +49,7 @@ public final class MPJReflectionKit { */ public static Map getFieldMap(Class clazz) { if (clazz == null) { - return new HashMap<>(); + return EMPTY_MAP; } Map fieldMap = CLASS_FIELD_CACHE.get(clazz); if (fieldMap != null) { diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java index 51e47cf..554f66c 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java @@ -5,11 +5,11 @@ import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments; 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.ArrayUtils; -import com.baomidou.mybatisplus.core.toolkit.Assert; -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.*; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.github.yulichang.config.ConfigProperties; +import com.github.yulichang.toolkit.LambdaUtils; +import com.github.yulichang.toolkit.ReflectionKit; import com.github.yulichang.toolkit.*; import com.github.yulichang.toolkit.support.ColumnCache; import com.github.yulichang.toolkit.support.SelectColumn; @@ -33,8 +33,6 @@ import java.util.stream.Collectors; /** * 参考 {@link com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper} * Lambda 语法使用 Wrapper - *

- * 推荐使用 MPJWrappers.lambdaJoin();构造 * * @author yulichang * @see MPJWrappers @@ -301,20 +299,16 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper MPJLambdaWrapper selectFunc(boolean condition, BaseFuncEnum funcEnum, SFunction column, String alias) { - if (condition) { - ColumnCache cache = getCache(column); - selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(column), cache.getColumn(), - cache.getTableFieldInfo(), alias, alias, cache.getKeyType(), false, funcEnum)); - } + public MPJLambdaWrapper selectFunc(BaseFuncEnum funcEnum, SFunction column, String alias) { + ColumnCache cache = getCache(column); + selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(column), cache.getColumn(), + cache.getTableFieldInfo(), alias, alias, cache.getKeyType(), false, funcEnum)); return typedThis; } @Override - public MPJLambdaWrapper selectFunc(boolean condition, BaseFuncEnum funcEnum, Object column, String alias) { - if (condition) { - selectColumns.add(SelectColumn.of(null, column.toString(), null, alias, alias, null, false, funcEnum)); - } + public MPJLambdaWrapper selectFunc(BaseFuncEnum funcEnum, Object column, String alias) { + selectColumns.add(SelectColumn.of(null, column.toString(), null, alias, alias, null, false, funcEnum)); return typedThis; } @@ -335,7 +329,7 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper { String str = Constant.TABLE_ALIAS + getDefault(subTable.get(i.getClazz())) + StringPool.DOT + i.getColumnName(); return (i.getFuncEnum() == null ? str : String.format(i.getFuncEnum().getSql(), str)) + @@ -399,14 +393,26 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper MPJLambdaWrapper join(String keyWord, boolean condition, Class clazz, OnFunction function) { - if (condition) { - MPJLambdaWrapper apply = function.apply(instance(keyWord, clazz)); - onWrappers.add(apply); - subTable.put(clazz, tableIndex); - tableIndex++; + /** + * 副表部分逻辑删除支持 + */ + public String getLogicSql() { + if (ConfigProperties.subTableLogic) { + if (CollectionUtils.isEmpty(subTable)) { + return StringPool.EMPTY; + } + return "AND " + subTable.entrySet().stream().map(entry -> + LogicInfoUtils.getLogicInfo(entry.getValue(), entry.getKey())).collect(Collectors.joining(" AND ")); } + return StringPool.EMPTY; + } + + @Override + public MPJLambdaWrapper join(String keyWord, Class clazz, OnFunction function) { + MPJLambdaWrapper apply = function.apply(instance(keyWord, clazz)); + subTable.put(clazz, tableIndex); + onWrappers.add(apply); + tableIndex++; return typedThis; } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/LambdaJoin.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/LambdaJoin.java index b15397f..a6c56c8 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/LambdaJoin.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/LambdaJoin.java @@ -19,7 +19,7 @@ public interface LambdaJoin extends MPJBaseJoin { * @param right 条件 */ default Children leftJoin(Class clazz, SFunction left, SFunction right) { - return leftJoin(true, clazz, left, right); + return leftJoin(clazz, on -> on.eq(left, right)); } /** @@ -27,129 +27,62 @@ public interface LambdaJoin extends MPJBaseJoin { *

* 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...) * - * @param clazz 关联的实体类 + * @param clazz 关联实体类 * @param function 条件 */ default Children leftJoin(Class clazz, OnFunction function) { - return leftJoin(true, clazz, function); - } - - /** - * left join - * - * @param condition 是否执行 - * @param clazz 关联的实体类 - * @param left 条件 - * @param right 条件 - */ - default Children leftJoin(boolean condition, Class clazz, SFunction left, SFunction right) { - return leftJoin(condition, clazz, on -> on.eq(left, right)); - } - - /** - * left join - *

- * 例 leftJoin(UserDO.class, on -> on.eq(UserDO::getId,UserAddressDO::getUserId).le().gt()...) - * - * @param condition 是否执行 - * @param clazz 关联实体类 - * @param function 条件 - */ - default Children leftJoin(boolean condition, Class clazz, OnFunction function) { - return join(Constant.LEFT_JOIN, condition, clazz, function); + return join(Constant.LEFT_JOIN, clazz, function); } /** * ignore 参考 left join */ default Children rightJoin(Class clazz, SFunction left, SFunction right) { - return rightJoin(true, clazz, left, right); + return rightJoin(clazz, on -> on.eq(left, right)); } /** * ignore 参考 left join */ default Children rightJoin(Class clazz, OnFunction function) { - return rightJoin(true, clazz, function); - } - - /** - * ignore 参考 left join - */ - default Children rightJoin(boolean condition, Class clazz, SFunction left, SFunction right) { - return rightJoin(condition, clazz, on -> on.eq(left, right)); - } - - /** - * ignore 参考 left join - */ - default Children rightJoin(boolean condition, Class clazz, OnFunction function) { - return join(Constant.RIGHT_JOIN, condition, clazz, function); + return join(Constant.RIGHT_JOIN, clazz, function); } /** * ignore 参考 left join */ default Children innerJoin(Class clazz, SFunction left, SFunction right) { - return innerJoin(true, clazz, left, right); + return innerJoin(clazz, on -> on.eq(left, right)); } /** * ignore 参考 left join */ default Children innerJoin(Class clazz, OnFunction function) { - return innerJoin(true, clazz, function); + return join(Constant.INNER_JOIN, clazz, function); } - /** - * ignore 参考 left join - */ - default Children innerJoin(boolean condition, Class clazz, SFunction left, SFunction right) { - return innerJoin(condition, clazz, on -> on.eq(left, right)); - } - - /** - * ignore 参考 left join - */ - default Children innerJoin(boolean condition, Class clazz, OnFunction function) { - return join(Constant.INNER_JOIN, condition, clazz, function); - } /** * ignore 参考 left join */ default Children fullJoin(Class clazz, SFunction left, SFunction right) { - return fullJoin(true, clazz, left, right); + return fullJoin(clazz, on -> on.eq(left, right)); } /** * ignore 参考 left join */ default Children fullJoin(Class clazz, OnFunction function) { - return fullJoin(true, clazz, function); - } - - /** - * ignore 参考 left join - */ - default Children fullJoin(boolean condition, Class clazz, SFunction left, SFunction right) { - return fullJoin(condition, clazz, on -> on.eq(left, right)); - } - - /** - * ignore 参考 left join - */ - default Children fullJoin(boolean condition, Class clazz, OnFunction function) { - return join(Constant.FULL_JOIN, condition, clazz, function); + return join(Constant.FULL_JOIN, clazz, function); } /** * 查询基类 可以直接调用此方法实现以上所有功能 * - * @param keyWord 连表关键字 - * @param condition 是否执行 - * @param clazz 连表实体类 - * @param function 关联条件 + * @param keyWord 连表关键字 + * @param clazz 连表实体类 + * @param function 关联条件 */ - Children join(String keyWord, boolean condition, Class clazz, OnFunction function); + Children join(String keyWord, Class clazz, OnFunction function); } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java index 815c269..63b1c55 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java @@ -75,40 +75,20 @@ public interface Query extends Serializable { * @param column 函数作用的字段 * @param alias 别名 */ - Children selectFunc(boolean condition, BaseFuncEnum funcEnum, Object column, String alias); + Children selectFunc(BaseFuncEnum funcEnum, Object column, String alias); - Children selectFunc(boolean condition, BaseFuncEnum funcEnum, SFunction column, String alias); - - default Children selectFunc(BaseFuncEnum funcEnum, Object column, String alias) { - return selectFunc(true, funcEnum, column, alias); - } - - default Children selectFunc(BaseFuncEnum funcEnum, SFunction column, String alias) { - return selectFunc(true, funcEnum, column, alias); - } + Children selectFunc(BaseFuncEnum funcEnum, SFunction column, String alias); default Children selectFunc(BaseFuncEnum funcEnum, SFunction column, SFunction alias) { - return selectFunc(true, funcEnum, column, LambdaUtils.getName(alias)); + return selectFunc(funcEnum, column, LambdaUtils.getName(alias)); } default Children selectFunc(BaseFuncEnum funcEnum, SFunction column) { - return selectFunc(true, funcEnum, column, column); + return selectFunc(funcEnum, column, column); } default Children selectFunc(BaseFuncEnum funcEnum, Object column, SFunction alias) { - return selectFunc(true, funcEnum, column, LambdaUtils.getName(alias)); - } - - default Children selectFunc(boolean condition, BaseFuncEnum funcEnum, SFunction column, SFunction alias) { - return selectFunc(condition, funcEnum, column, LambdaUtils.getName(alias)); - } - - default Children selectFunc(boolean condition, BaseFuncEnum funcEnum, SFunction column) { - return selectFunc(condition, funcEnum, column, column); - } - - default Children selectFunc(boolean condition, BaseFuncEnum funcEnum, Object column, SFunction alias) { - return selectFunc(condition, funcEnum, column, LambdaUtils.getName(alias)); + return selectFunc(funcEnum, column, LambdaUtils.getName(alias)); } /** @@ -138,18 +118,6 @@ public interface Query extends Serializable { return selectFunc(DefaultFuncEnum.SUM, column, alias); } - default Children selectSum(boolean condition, SFunction column) { - return selectFunc(condition, DefaultFuncEnum.SUM, column); - } - - default Children selectSum(boolean condition, SFunction column, SFunction alias) { - return selectFunc(condition, DefaultFuncEnum.SUM, column, alias); - } - - default Children selectSum(boolean condition, SFunction column, String alias) { - return selectFunc(condition, DefaultFuncEnum.SUM, column, alias); - } - /** * COUNT() */ @@ -173,26 +141,6 @@ public interface Query extends Serializable { return selectFunc(DefaultFuncEnum.COUNT, column, alias); } - default Children selectCount(boolean condition, SFunction column) { - return selectFunc(condition, DefaultFuncEnum.COUNT, column); - } - - default Children selectCount(boolean condition, Object column, SFunction alias) { - return selectFunc(condition, DefaultFuncEnum.COUNT, column, alias); - } - - default Children selectCount(boolean condition, Object column, String alias) { - return selectFunc(condition, DefaultFuncEnum.COUNT, column, alias); - } - - default Children selectCount(boolean condition, SFunction column, SFunction alias) { - return selectFunc(condition, DefaultFuncEnum.COUNT, column, alias); - } - - default Children selectCount(boolean condition, SFunction column, String alias) { - return selectFunc(condition, DefaultFuncEnum.COUNT, column, alias); - } - /** * MAX() */ @@ -208,18 +156,6 @@ public interface Query extends Serializable { return selectFunc(DefaultFuncEnum.MAX, column, alias); } - default Children selectMax(boolean condition, SFunction column) { - return selectFunc(condition, DefaultFuncEnum.MAX, column); - } - - default Children selectMax(boolean condition, SFunction column, SFunction alias) { - return selectFunc(condition, DefaultFuncEnum.MAX, column, alias); - } - - default Children selectMax(boolean condition, SFunction column, String alias) { - return selectFunc(condition, DefaultFuncEnum.MAX, column, alias); - } - /** * MIN() */ @@ -235,18 +171,6 @@ public interface Query extends Serializable { return selectFunc(DefaultFuncEnum.MIN, column, alias); } - default Children selectMin(boolean condition, SFunction column) { - return selectFunc(condition, DefaultFuncEnum.MIN, column); - } - - default Children selectMin(boolean condition, SFunction column, SFunction alias) { - return selectFunc(condition, DefaultFuncEnum.MIN, column, alias); - } - - default Children selectMin(boolean condition, SFunction column, String alias) { - return selectFunc(condition, DefaultFuncEnum.MIN, column, alias); - } - /** * MIN() */ @@ -262,18 +186,6 @@ public interface Query extends Serializable { return selectFunc(DefaultFuncEnum.AVG, column, alias); } - default Children selectAvg(boolean condition, SFunction column) { - return selectFunc(condition, DefaultFuncEnum.AVG, column); - } - - default Children selectAvg(boolean condition, SFunction column, SFunction alias) { - return selectFunc(condition, DefaultFuncEnum.AVG, column, alias); - } - - default Children selectAvg(boolean condition, SFunction column, String alias) { - return selectFunc(condition, DefaultFuncEnum.AVG, column, alias); - } - /** * LEN() */ @@ -288,16 +200,4 @@ public interface Query extends Serializable { default Children selectLen(SFunction column, String alias) { return selectFunc(DefaultFuncEnum.LEN, column, alias); } - - default Children selectLen(boolean condition, SFunction column) { - return selectFunc(condition, DefaultFuncEnum.LEN, column); - } - - default Children selectLen(boolean condition, SFunction column, SFunction alias) { - return selectFunc(condition, DefaultFuncEnum.LEN, column, alias); - } - - default Children selectLen(boolean condition, SFunction column, String alias) { - return selectFunc(condition, DefaultFuncEnum.LEN, column, alias); - } } From 12821a2c876cfe9511011ea427676b6d1c4b76fd Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Tue, 22 Nov 2022 16:55:59 +0800 Subject: [PATCH 17/23] =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yulichang/wrapper/MPJLambdaWrapper.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java index 554f66c..43dd997 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java @@ -148,16 +148,16 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper - * 举例 UserDO UserAddressDO 为一对多关系 UserDTO 为结果类 + * 举例 UserDO AddressDO 为一对多关系 UserDTO 为结果类 *

      *     MPJLambdaQueryWrapper wrapper = new MPJLambdaQueryWrapper();
      *     wrapper.selectAll(UserDO.class)
-     *            .selectCollection(UserAddressDO.class, UserDTO::getAddressListDTO)
-     *            .leftJoin(UserAddressDO.class, ...... )
+     *            .selectCollection(AddressDO.class, UserDTO::getAddressListDTO)
+     *            .leftJoin(AddressDO.class, ...... )
      *            .eq(...)
      *            ...
      * 
-     * 会自动将 UserAddressDO类中相同属性的字段 以mybatis的方式映射到UserDTO.addressListDTO属性中
+     * 会自动将 AddressDO类中相同属性的字段 以mybatis的方式映射到UserDTO.addressListDTO属性中
      *
      * @since 1.3.0
      *
@@ -190,20 +190,20 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper
-     * 举例 UserDO UserAddressDO 为一对多关系  UserDTO 为结果类
+     * 举例 UserDO AddressDO 为一对多关系  UserDTO 为结果类
      * 
-     *     MPJLambdaQueryWrapper wrapper = new MPJLambdaQueryWrapper();
-     *     wrapper.selectAll(UserDO.class)
-     *            .selectCollection(UserAddressDO.class, UserDTO::getAddressListDTO, map -> map
-     *                 .id(UserAddressDO::getId, AddressDTO::getId)                     //如果属性名一致 可以传一个
-     *                 .result(UserAddressDO::getUserId)                                //如果属性名一致 可以传一个
-     *                 .result(UserAddressDO::getAddress, AddressDTO::getAddress)))     //如果属性名一致 可以传一个
-     *            .leftJoin(UserAddressDO.class, ...... )
-     *            .eq(...)
-     *            ...
+     *   MPJLambdaQueryWrapper wrapper = new MPJLambdaQueryWrapper();
+     *   wrapper.selectAll(UserDO.class)
+     *      .selectCollection(AddressDO.class, UserDTO::getAddressListDTO, map -> map
+     *           .id(AddressDO::getId, AddressDTO::getId)                 //如果属性名一致 可以传一个
+     *           .result(AddressDO::getUserId)                            //如果属性名一致 可以传一个
+     *           .result(AddressDO::getAddress, AddressDTO::getAddress))) //如果属性名一致 可以传一个
+     *      .leftJoin(AddressDO.class, ...... )
+     *      .eq(...)
+     *      ...
      * 
      *
-     * 会自动将 UserAddressDO类中指定的字段 以mybatis的方式映射到UserDTO.addressListDTO属性中
+     * 会自动将 AddressDO类中指定的字段 以mybatis的方式映射到UserDTO.addressListDTO属性中
      *
      * @since 1.3.0
      *

From 7afb9f6a1e4596cf8645037eb88975c4cb7562a6 Mon Sep 17 00:00:00 2001
From: yulichang <570810310@qq.com>
Date: Wed, 23 Nov 2022 16:38:26 +0800
Subject: [PATCH 18/23] =?UTF-8?q?fix=20=E9=80=BB=E8=BE=91=E5=88=A0?=
 =?UTF-8?q?=E9=99=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../java/com/github/yulichang/query/MPJQueryWrapper.java  | 8 ++++++++
 1 file changed, 8 insertions(+)

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 e2aa3d2..48df15a 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
@@ -204,6 +204,13 @@ public class MPJQueryWrapper extends AbstractWrapper extends AbstractWrapper
Date: Wed, 23 Nov 2022 17:20:20 +0800
Subject: [PATCH 19/23] =?UTF-8?q?fix=20=E9=80=BB=E8=BE=91=E5=88=A0?=
 =?UTF-8?q?=E9=99=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../github/yulichang/toolkit/LogicInfoUtils.java    | 13 +++++++++----
 .../github/yulichang/wrapper/MPJLambdaWrapper.java  |  4 ++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java
index c0768e2..7ff8d5a 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
 import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
 import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
 
 import java.util.Map;
 import java.util.Objects;
@@ -28,11 +29,15 @@ public class LogicInfoUtils implements Constants {
         }
         TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
         Assert.notNull(tableInfo, "%s 不是数据库实体或没有注册到mybatis plus中", clazz.getName());
-        final String value = tableInfo.getLogicDeleteFieldInfo().getLogicNotDeleteValue();
-        if (NULL.equalsIgnoreCase(value)) {
-            logicStr = Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + " IS NULL";
+        if (tableInfo.isWithLogicDelete() && Objects.nonNull(tableInfo.getLogicDeleteFieldInfo())) {
+            final String value = tableInfo.getLogicDeleteFieldInfo().getLogicNotDeleteValue();
+            if (NULL.equalsIgnoreCase(value)) {
+                logicStr = " AND " + Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + " IS NULL";
+            } else {
+                logicStr = " AND " + Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + EQUALS + String.format(tableInfo.getLogicDeleteFieldInfo().isCharSequence() ? "'%s'" : "%s", value);
+            }
         } else {
-            logicStr = Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + EQUALS + String.format(tableInfo.getLogicDeleteFieldInfo().isCharSequence() ? "'%s'" : "%s", value);
+            logicStr = StringPool.EMPTY;
         }
         LOGIC_CACHE.put(clazz, logicStr);
         return logicStr;
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java
index 43dd997..a73b3f7 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java
@@ -401,8 +401,8 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper
-                    LogicInfoUtils.getLogicInfo(entry.getValue(), entry.getKey())).collect(Collectors.joining(" AND "));
+            return subTable.entrySet().stream().map(entry -> LogicInfoUtils.getLogicInfo(entry.getValue(),
+                    entry.getKey())).collect(Collectors.joining(StringPool.SPACE));
         }
         return StringPool.EMPTY;
     }

From fadcad436d42b7b877fe3d2455ffc24909339d31 Mon Sep 17 00:00:00 2001
From: yulichang <570810310@qq.com>
Date: Thu, 24 Nov 2022 18:52:31 +0800
Subject: [PATCH 20/23] test

---
 mybatis-plus-join-test/pom.xml                |  7 +++++-
 .../test/collection/CollectionTest.java       |  1 +
 .../test/join/LambdaWrapperTest.java          | 23 +++++++++++++------
 .../yulichang/test/join/entity/TableA.java    | 15 ------------
 .../yulichang/test/join/entity/TableB.java    | 17 --------------
 .../yulichang/test/join/entity/TableC.java    | 17 --------------
 .../yulichang/test/join/entity/TableD.java    | 17 --------------
 .../yulichang/test/join/entity/TableE.java    | 17 --------------
 .../test/join/mapper/TableAMapper.java        | 11 ---------
 .../test/join/mapper/TableBMapper.java        | 11 ---------
 .../test/join/mapper/TableCMapper.java        | 11 ---------
 .../test/join/mapper/TableDMapper.java        | 11 ---------
 .../test/join/mapper/TableEMapper.java        | 11 ---------
 .../src/test/resources/application.yml        |  3 ++-
 14 files changed, 25 insertions(+), 147 deletions(-)
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableA.java
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableB.java
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableC.java
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableD.java
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableE.java
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableAMapper.java
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableBMapper.java
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableCMapper.java
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableDMapper.java
 delete mode 100644 mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableEMapper.java

diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml
index 396ae49..dcf51c4 100644
--- a/mybatis-plus-join-test/pom.xml
+++ b/mybatis-plus-join-test/pom.xml
@@ -71,7 +71,7 @@
         
             com.baomidou
             mybatis-plus-boot-starter
-            3.4.2
+            3.5.2
         
         
             com.github.yulichang
@@ -89,6 +89,11 @@
             jackson-databind
             2.14.0
         
+        
+            com.baomidou
+            mybatis-plus-boot-starter
+            3.5.2
+        
         
             org.springframework
             spring-jdbc
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/CollectionTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/CollectionTest.java
index 7487c66..1c16508 100644
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/CollectionTest.java
+++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/collection/CollectionTest.java
@@ -42,6 +42,7 @@ class CollectionTest {
                 .leftJoin(TableE.class, TableE::getDid, TableD::getId);
 
         List dtos = tableAMapper.selectJoinList(TableADTO.class, wrapper);
+        assert dtos.size() == 1;
         System.out.println(dtos);
     }
 }
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java
index 7dae67e..847869b 100644
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java
+++ b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/LambdaWrapperTest.java
@@ -40,8 +40,14 @@ class LambdaWrapperTest {
                         .association(AreaDO.class, AddressDTO::getArea))
                 .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
                 .leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)
-                .orderByDesc(UserDO::getId);
+                .orderByDesc(UserDO::getId)
+                .last("unfdjknsnnjkfd");
         List list = userMapper.selectJoinList(UserDTO.class, wrapper);
+        String s = wrapper.getSqlSegment();
+        System.out.println(s);
+        if (list.size() != 1) {
+            throw new RuntimeException();
+        }
         list.forEach(System.out::println);
     }
 
@@ -57,7 +63,8 @@ class LambdaWrapperTest {
                         .select(AddressDO::getAddress)
                         .select(AreaDO::getProvince)
                         .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
-                        .leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId));
+                        .leftJoin(AreaDO.class, AreaDO::getId, AddressDO::getAreaId)
+                        .last("unfdjknsnnjkfd"));
         iPage.getRecords().forEach(System.out::println);
     }
 
@@ -78,7 +85,8 @@ class LambdaWrapperTest {
                         .and(i -> i.eq(UserDO::getHeadImg, "er")
                                 .or()
                                 .eq(AddressDO::getUserId, 1))
-                        .eq(UserDO::getId, 1));
+                        .eq(UserDO::getId, 1)
+                        .last("ljfnkegrwbgejkwbenf"));
         page.getRecords().forEach(System.out::println);
     }
 
@@ -91,7 +99,7 @@ class LambdaWrapperTest {
                 .selectSum(UserDO::getId)
                 .selectMax(UserDO::getId, UserDTO::getHeadImg)
                 .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
-                .eq(UserDO::getId, 1));
+                .last("unfdjknsnnjkfd"));
         System.out.println(one);
     }
 
@@ -101,14 +109,15 @@ class LambdaWrapperTest {
      */
     @Test
     void test6() {
-        userMapper.selectPage(new Page<>(1, 10),new QueryWrapper<>());
+        userMapper.selectPage(new Page<>(1, 10), new QueryWrapper<>());
         IPage page = userMapper.selectJoinPage(new Page<>(1, 10), UserDTO.class,
                 MPJWrappers.lambdaJoin()
                         .selectAll(UserDO.class)
                         .select(AddressDO.class, p -> true)
                         .select(AddressDO::getAddress)
                         .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
-                        .eq(UserDO::getId, 1));
+                        .eq(UserDO::getId, 1)
+                        .last("unfdjknsnnjkfd"));
         page.getRecords().forEach(System.out::println);
     }
 
@@ -122,7 +131,7 @@ class LambdaWrapperTest {
                 .selectAll(UserDO.class)
                 .select(AddressDO::getAddress)
                 .leftJoin(AddressDO.class, AddressDO::getUserId, UserDO::getId)
-                .eq(UserDO::getId, 1));
+                .last("unfdjknsnnjkfd"));
         list.forEach(System.out::println);
     }
 }
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableA.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableA.java
deleted file mode 100644
index e22d6d7..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableA.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.github.yulichang.test.join.entity;
-
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-
-@Data
-@TableName("table_a")
-public class TableA {
-
-    @TableId
-    private Integer id;
-
-    private String name;
-}
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableB.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableB.java
deleted file mode 100644
index 80205b0..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableB.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.github.yulichang.test.join.entity;
-
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-
-@Data
-@TableName("table_b")
-public class TableB {
-
-    @TableId
-    private Integer id;
-
-    private Integer aid;
-
-    private String name;
-}
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableC.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableC.java
deleted file mode 100644
index 1ed74e2..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableC.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.github.yulichang.test.join.entity;
-
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-
-@Data
-@TableName("table_c")
-public class TableC {
-
-    @TableId
-    private Integer id;
-
-    private Integer bid;
-
-    private String name;
-}
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableD.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableD.java
deleted file mode 100644
index c44940c..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableD.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.github.yulichang.test.join.entity;
-
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-
-@Data
-@TableName("table_d")
-public class TableD {
-
-    @TableId
-    private Integer id;
-
-    private Integer cid;
-
-    private String name;
-}
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableE.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableE.java
deleted file mode 100644
index e69a7ef..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/entity/TableE.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.github.yulichang.test.join.entity;
-
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-
-@Data
-@TableName("table_e")
-public class TableE {
-
-    @TableId
-    private Integer id;
-
-    private Integer did;
-
-    private String name;
-}
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableAMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableAMapper.java
deleted file mode 100644
index 91a3bea..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableAMapper.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.github.yulichang.test.join.mapper;
-
-import com.github.yulichang.base.MPJBaseMapper;
-import com.github.yulichang.test.join.entity.TableA;
-import org.apache.ibatis.annotations.Mapper;
-
-@Mapper
-@SuppressWarnings("unused")
-public interface TableAMapper extends MPJBaseMapper {
-
-}
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableBMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableBMapper.java
deleted file mode 100644
index a3a2173..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableBMapper.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.github.yulichang.test.join.mapper;
-
-import com.github.yulichang.base.MPJBaseMapper;
-import com.github.yulichang.test.join.entity.TableB;
-import org.apache.ibatis.annotations.Mapper;
-
-@Mapper
-@SuppressWarnings("unused")
-public interface TableBMapper extends MPJBaseMapper {
-
-}
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableCMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableCMapper.java
deleted file mode 100644
index b74a614..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableCMapper.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.github.yulichang.test.join.mapper;
-
-import com.github.yulichang.base.MPJBaseMapper;
-import com.github.yulichang.test.join.entity.TableC;
-import org.apache.ibatis.annotations.Mapper;
-
-@Mapper
-@SuppressWarnings("unused")
-public interface TableCMapper extends MPJBaseMapper {
-
-}
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableDMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableDMapper.java
deleted file mode 100644
index 2bd16d6..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableDMapper.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.github.yulichang.test.join.mapper;
-
-import com.github.yulichang.base.MPJBaseMapper;
-import com.github.yulichang.test.join.entity.TableD;
-import org.apache.ibatis.annotations.Mapper;
-
-@Mapper
-@SuppressWarnings("unused")
-public interface TableDMapper extends MPJBaseMapper {
-
-}
diff --git a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableEMapper.java b/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableEMapper.java
deleted file mode 100644
index 2f70960..0000000
--- a/mybatis-plus-join-test/src/test/java/com/github/yulichang/test/join/mapper/TableEMapper.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.github.yulichang.test.join.mapper;
-
-import com.github.yulichang.base.MPJBaseMapper;
-import com.github.yulichang.test.join.entity.TableE;
-import org.apache.ibatis.annotations.Mapper;
-
-@Mapper
-@SuppressWarnings("unused")
-public interface TableEMapper extends MPJBaseMapper {
-
-}
diff --git a/mybatis-plus-join-test/src/test/resources/application.yml b/mybatis-plus-join-test/src/test/resources/application.yml
index b0ad69e..21a04ba 100644
--- a/mybatis-plus-join-test/src/test/resources/application.yml
+++ b/mybatis-plus-join-test/src/test/resources/application.yml
@@ -18,4 +18,5 @@ mybatis-plus:
 
 # 打印 mybatis plus join banner
 mybatis-plus-join:
-  banner: true
\ No newline at end of file
+  banner: true
+  sub-table-logic: true
\ No newline at end of file

From 89a6dfd4aa5a0141524b87d509c4c1daefac63b0 Mon Sep 17 00:00:00 2001
From: yulichang <570810310@qq.com>
Date: Sun, 27 Nov 2022 18:42:24 +0800
Subject: [PATCH 21/23] =?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 mybatis-plus-join-annotation/pom.xml                      | 4 ++--
 mybatis-plus-join-boot-starter/pom.xml                    | 8 ++++----
 .../autoconfigure/MybatisPlusJoinAutoConfiguration.java   | 2 +-
 .../autoconfigure/MybatisPlusJoinProperties.java          | 2 +-
 mybatis-plus-join-core/pom.xml                            | 6 +++---
 .../com/github/yulichang/config/ConfigProperties.java     | 2 +-
 .../com/github/yulichang/config/InterceptorConfig.java    | 2 +-
 .../java/com/github/yulichang/toolkit/LogicInfoUtils.java | 2 +-
 .../com/github/yulichang/toolkit/MPJReflectionKit.java    | 2 +-
 mybatis-plus-join-test/pom.xml                            | 6 +++---
 pom.xml                                                   | 4 ++--
 11 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/mybatis-plus-join-annotation/pom.xml b/mybatis-plus-join-annotation/pom.xml
index 72403c9..cc58eeb 100644
--- a/mybatis-plus-join-annotation/pom.xml
+++ b/mybatis-plus-join-annotation/pom.xml
@@ -7,9 +7,9 @@
     
         com.github.yulichang
         mybatis-plus-join-root
-        2.0.0
+        1.3.8
     
-    2.0.0
+    1.3.8
     mybatis-plus-join-annotation
     mybatis-plus-join-annotation
 
diff --git a/mybatis-plus-join-boot-starter/pom.xml b/mybatis-plus-join-boot-starter/pom.xml
index c88f5e8..79b91c6 100644
--- a/mybatis-plus-join-boot-starter/pom.xml
+++ b/mybatis-plus-join-boot-starter/pom.xml
@@ -7,11 +7,11 @@
     
         com.github.yulichang
         mybatis-plus-join-root
-        2.0.0
+        1.3.8
     
-    2.0.0
+    1.3.8
     mybatis-plus-join-boot-starter
-    mybatis-plus-join-boot-starter
+    mybatis-plus-join-boot
 
     An enhanced toolkit of Mybatis-Plus to simplify development.
     https://github.com/yulichang/mybatis-plus-join
@@ -47,7 +47,7 @@
         
             com.github.yulichang
             mybatis-plus-join-core
-            2.0.0
+            1.3.8
         
         
             org.springframework.boot
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 c67983f..bbb011b 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
@@ -37,7 +37,7 @@ import java.util.List;
  * springboot 自动配置类
  *
  * @author yulichang
- * @since 2.0.0
+ * @since 1.3.7
  */
 @SuppressWarnings("unused")
 @Configuration(proxyBeanMethods = false)
diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java
index 2b7228d..91dfdf5 100644
--- a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java
+++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java
@@ -8,7 +8,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
  * 配置类
  *
  * @author yulichang
- * @since 2.0.0
+ * @since 1.3.7
  */
 @Data
 @Accessors(chain = true)
diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml
index 8cc1ba5..28430cb 100644
--- a/mybatis-plus-join-core/pom.xml
+++ b/mybatis-plus-join-core/pom.xml
@@ -7,9 +7,9 @@
     
         com.github.yulichang
         mybatis-plus-join-root
-        2.0.0
+        1.3.8
     
-    2.0.0
+    1.3.8
     mybatis-plus-join-core
     mybatis-plus-join-core
 
@@ -47,7 +47,7 @@
         
             com.github.yulichang
             mybatis-plus-join-annotation
-            2.0.0
+            1.3.8
         
         
             com.baomidou
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java
index 71eb06f..e96c9aa 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java
@@ -2,7 +2,7 @@ package com.github.yulichang.config;
 
 /**
  * @author yulichang
- * @since 2.0.0
+ * @since 1.3.7
  */
 public class ConfigProperties {
     public static boolean subTableLogic = true;
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java
index ad1b06b..60f8f59 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java
@@ -28,7 +28,7 @@ public class InterceptorConfig {
             //打印banner
             System.out.println(" _ _   |_  _ _|_. ___ _ |    _  .  _  .  _  \n" +
                     "| | |\\/|_)(_| | |_\\  |_)||_|_\\  | (_) | | | \n" +
-                    "     /               |          /            2.0.0");
+                    "     /               |          /            1.3.8");
         }
     }
 
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java
index 7ff8d5a..bfd1dce 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LogicInfoUtils.java
@@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap;
  * 逻辑删除信息类
  *
  * @author yulichang
- * @since 2.0.0
+ * @since 1.3.7
  */
 public class LogicInfoUtils implements Constants {
 
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java
index 18e55f2..1f923e4 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java
@@ -12,7 +12,7 @@ import java.util.concurrent.ConcurrentHashMap;
  * 反射工具类
  *
  * @author yulichang
- * @since 2.0.0
+ * @since 1.3.7
  */
 @SuppressWarnings("unused")
 public final class MPJReflectionKit {
diff --git a/mybatis-plus-join-test/pom.xml b/mybatis-plus-join-test/pom.xml
index dcf51c4..53dec2d 100644
--- a/mybatis-plus-join-test/pom.xml
+++ b/mybatis-plus-join-test/pom.xml
@@ -7,9 +7,9 @@
     
         com.github.yulichang
         mybatis-plus-join-root
-        2.0.0
+        1.3.8
     
-    2.0.0
+    1.3.8
     mybatis-plus-join-test
     mybatis-plus-join-test
 
@@ -76,7 +76,7 @@
         
             com.github.yulichang
             mybatis-plus-join-boot-starter
-            2.0.0
+            1.3.8
         
         
         
diff --git a/pom.xml b/pom.xml
index c10686c..c0b5e32 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
     com.github.yulichang
     mybatis-plus-join-root
     pom
-    2.0.0
+    1.3.8
     mybatis-plus-join-root
 
     An enhanced toolkit of Mybatis-Plus to simplify development.
@@ -33,7 +33,7 @@
         mybatis-plus-join-boot-starter
         mybatis-plus-join-core
         mybatis-plus-join-annotation
-        mybatis-plus-join-test
+        mybatis-plus-join
     
 
     

From 7d861ebbcbddc716b8cd3f47cf6c27c4030ffd67 Mon Sep 17 00:00:00 2001
From: yulichang <570810310@qq.com>
Date: Sun, 27 Nov 2022 19:43:37 +0800
Subject: [PATCH 22/23] =?UTF-8?q?fix=20=E9=80=BB=E8=BE=91=E5=88=A0?=
 =?UTF-8?q?=E9=99=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 README.md                                                     | 4 ++--
 mybatis-plus-join-boot-starter/pom.xml                        | 2 +-
 .../main/java/com/github/yulichang/method/MPJBaseMethod.java  | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 2931923..5c1c52a 100644
--- a/README.md
+++ b/README.md
@@ -15,12 +15,12 @@ QQ群:1022221898
   
       com.github.yulichang
       mybatis-plus-join-boot-starter
-      2.0.0
+      1.3.8
   
   ```
 - Gradle
   ```
-   implementation 'com.github.yulichang:mybatis-plus-join-boot-starter:2.0.0'
+   implementation 'com.github.yulichang:mybatis-plus-join-boot-starter:1.3.8'
   ```
   或者clone代码到本地执行 mvn install, 再引入以上依赖  
   
diff --git a/mybatis-plus-join-boot-starter/pom.xml b/mybatis-plus-join-boot-starter/pom.xml index 79b91c6..1c37bc0 100644 --- a/mybatis-plus-join-boot-starter/pom.xml +++ b/mybatis-plus-join-boot-starter/pom.xml @@ -11,7 +11,7 @@ 1.3.8 mybatis-plus-join-boot-starter - mybatis-plus-join-boot + mybatis-plus-join-boot-starter An enhanced toolkit of Mybatis-Plus to simplify development. https://github.com/yulichang/mybatis-plus-join 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 d1bfbd4..60bcad0 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 @@ -42,9 +42,9 @@ public interface MPJBaseMethod extends Constants { sqlScript = SqlScriptUtils.convertIf(sqlScript, String.format("%s != null", WRAPPER_ENTITY), true); sqlScript += NEWLINE; if (ConfigProperties.subTableLogic) { - sqlScript += String.format("${%s.logicSql}", WRAPPER); + sqlScript += (String.format("${%s.logicSql}", WRAPPER) + NEWLINE); } - sqlScript += SqlScriptUtils.convertIf(String.format("${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_NONEMPTYOFWHERE), true); + sqlScript += SqlScriptUtils.convertIf(String.format("AND ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_NONEMPTYOFWHERE), true); sqlScript = SqlScriptUtils.convertWhere(sqlScript) + NEWLINE; sqlScript += SqlScriptUtils.convertIf(String.format(" ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_EMPTYOFWHERE), true); sqlScript = SqlScriptUtils.convertIf(sqlScript, String.format("%s != null", WRAPPER), true); From b35169546f5aba2ac25daf058da85e4087df9616 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Sun, 27 Nov 2022 20:18:44 +0800 Subject: [PATCH 23/23] 1.3.8 --- mybatis-plus-join-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml index 28430cb..ab0d912 100644 --- a/mybatis-plus-join-core/pom.xml +++ b/mybatis-plus-join-core/pom.xml @@ -65,7 +65,7 @@ org.slf4j slf4j-api provided - 2.0.3 + 2.0.4
org.springframework @@ -74,4 +74,4 @@ provided - \ No newline at end of file +