mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
项目模块化 2.0.0
This commit is contained in:
parent
2af3e6b7ba
commit
8812da14ee
@ -14,13 +14,13 @@ QQ群:1022221898
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
```
|
||||
- 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, 再引入以上依赖
|
||||
<br>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-root</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>mybatis-plus-join-annotation</artifactId>
|
||||
<name>mybatis-plus-join-annotation</name>
|
||||
@ -33,9 +33,20 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<jdkVersion>1.8</jdkVersion>
|
||||
<jdkVersion.test>1.8</jdkVersion.test>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<github.global.server>github</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-core</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-root</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<name>mybatis-plus-join-boot-starter</name>
|
||||
@ -33,8 +33,11 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<jdkVersion>1.8</jdkVersion>
|
||||
<jdkVersion.test>1.8</jdkVersion.test>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<github.global.server>github</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@ -44,14 +47,23 @@
|
||||
<artifactId>mybatis-plus-join-core</artifactId>
|
||||
<version>${mybaits-plus-join.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
<version>2.7.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
@ -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<ApplicationReadyEvent> {
|
||||
@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> T getBean(Class<T> clazz) {
|
||||
return this.applicationContext.getBean(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullableProblems")
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-root</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>mybatis-plus-join-core</artifactId>
|
||||
<name>mybatis-plus-join-core</name>
|
||||
@ -32,10 +32,12 @@
|
||||
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||
</scm>
|
||||
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<jdkVersion>1.8</jdkVersion>
|
||||
<jdkVersion.test>1.8</jdkVersion.test>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<github.global.server>github</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@ -45,5 +47,23 @@
|
||||
<artifactId>mybatis-plus-join-annotation</artifactId>
|
||||
<version>${mybaits-plus-join.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
<version>5.3.23</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -28,7 +28,7 @@ public class InterceptorConfig {
|
||||
//打印banner
|
||||
System.out.println(" _ _ |_ _ _|_. ___ _ | _ . _ . _ \n" +
|
||||
"| | |\\/|_)(_| | |_\\ |_)||_|_\\ | (_) | | | \n" +
|
||||
" / | / 1.3.0");
|
||||
" / | / 2.0.0");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<ApplicationReadyEvent> {
|
||||
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())));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,9 +28,6 @@ import static java.util.stream.Collectors.toList;
|
||||
*/
|
||||
public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
|
||||
private static final List<String> 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<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
|
||||
List<String> methodList = Arrays.asList("SelectOne", "SelectCount",
|
||||
"SelectMaps", "SelectMapsPage", "SelectObjs", "SelectList", "SelectPage");
|
||||
List<AbstractMethod> 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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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> T getBean(Class<T> clazz) {
|
||||
return SpringContentUtils.springContext.getBean(clazz);
|
||||
}
|
||||
|
||||
public interface SpringContext {
|
||||
|
||||
<T> T getBean(Class<T> clazz);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-root</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>mybatis-plus-join-test</artifactId>
|
||||
<name>mybatis-plus-join-test</name>
|
||||
@ -36,8 +36,11 @@
|
||||
<properties>
|
||||
<springboot.version>2.5.4</springboot.version>
|
||||
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<jdkVersion>1.8</jdkVersion>
|
||||
<jdkVersion.test>1.8</jdkVersion.test>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<github.global.server>github</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@ -62,12 +65,17 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>${mybaits-plus-join.version}</version>
|
||||
</dependency>
|
||||
<!-- PageHelper 兼容性测试 -->
|
||||
<dependency>
|
||||
|
24
pom.xml
24
pom.xml
@ -5,7 +5,7 @@
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-root</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>${mybaits-plus-join.version}</version>
|
||||
<version>2.0.0</version>
|
||||
<name>mybatis-plus-join-root</name>
|
||||
|
||||
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
||||
@ -37,31 +37,19 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<mybaits-plus-join.version>1.3.0</mybaits-plus-join.version>
|
||||
<mybaits-plus-join.version>2.0.0</mybaits-plus-join.version>
|
||||
<mybatis-plus.version>3.5.2</mybatis-plus.version>
|
||||
<lombok.version>1.18.24</lombok.version>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<github.global.server>github</github.global.server>
|
||||
<jdkVersion>1.8</jdkVersion>
|
||||
<jdkVersion.test>1.8</jdkVersion.test>
|
||||
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<github.global.server>github</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
Loading…
x
Reference in New Issue
Block a user