Skip to content

Commit aa1a44e

Browse files
committed
本例主要演示springboot与mybaits-plus实现多租户和自动填充
1 parent bad17d7 commit aa1a44e

29 files changed

+2407
-0
lines changed

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,32 @@
627627
/springboot-chaincontext/springboot-chaincontext.iml
628628
/springboot-chaincontext/target/classes/META-INF/
629629
/springboot-mq-idempotent-consume/target/classes/
630+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/common/advice/ResultResponseAdvice.class
631+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/common/exception/BusinessException.class
632+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/common/model/BaseEntity.class
633+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/common/model/Result.class
634+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/common/model/ValidMsg.class
635+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/common/swagger/SwaggerConfig.class
636+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/extension/crud/UpdateWapperAspect.class
637+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/extension/metadata/MyMetaObjectHandler.class
638+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/generator/model/CodeGeneratorHelper.class
639+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/generator/util/CodeGenerator.class
640+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/generator/util/CodeGeneratorUtils$1.class
641+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/generator/util/CodeGeneratorUtils$2.class
642+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/generator/util/CodeGeneratorUtils.class
643+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/generator/util/YmlUtils.class
644+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/msg/controller/MsgLogController.class
645+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/msg/dao/MsgLogDao.class
646+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/msg/entity/MsgLog.class
647+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/msg/service/impl/MsgLogServiceImpl.class
648+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/msg/service/MsgLogService.class
649+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/tenant/config/MyBatisPlusTenantConfig$1.class
650+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/tenant/config/MyBatisPlusTenantConfig.class
651+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/tenant/config/MyBatisPlusTenantProperties.class
652+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/tenant/parser/CustomTenantSqlParser.class
653+
/springboot-mybatisplus-tenant/target/classes/com/github/lybgeek/mybatisplus/SpringbootMybatisplusTenantApplication.class
654+
/springboot-mybatisplus-tenant/target/classes/mybatis/msg/MsgLogDao.xml
655+
/springboot-mybatisplus-tenant/target/classes/application.yml
656+
/springboot-mybatisplus-tenant/target/classes/application-jdbc.yml
657+
/springboot-mybatisplus-tenant/target/classes/demo_test.sql
658+
/springboot-mybatisplus-tenant/springboot-mybatisplus-tenant.iml

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<module>springboot-mybatis-autoId</module>
3535
<module>springboot-code-authorization</module>
3636
<module>springboot-chaincontext</module>
37+
<module>springboot-mybatisplus-tenant</module>
3738
</modules>
3839
<parent>
3940
<groupId>org.springframework.boot</groupId>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
本例主要演示springboot与mybaits-plus实现多租户和自动填充。
2+
3+
主要实现的功能点
4+
5+
- 修复mybatis-plus 3.4+版本之前插入多租户会出现Column 'tenant_id' specified twice问题,这个问题发生的本质是实体自己手动去设置租户id【注:3.4+版本,官方已经修复这个问题】
6+
7+
- 解决mybatis-plus使用update(Wrapper<T> updateWrapper),自动填充更新失效问题
8+
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>springboot-learning</artifactId>
7+
<groupId>com.github.lybgeek</groupId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>springboot-mybatisplus-tenant</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-web</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-freemarker</artifactId>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-aop</artifactId>
27+
</dependency>
28+
29+
<!--mybatis-plus-->
30+
<dependency>
31+
<groupId>com.baomidou</groupId>
32+
<artifactId>mybatis-plus-boot-starter</artifactId>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>com.baomidou</groupId>
37+
<artifactId>mybatis-plus-generator</artifactId>
38+
</dependency>
39+
40+
41+
<dependency>
42+
<groupId>org.yaml</groupId>
43+
<artifactId>snakeyaml</artifactId>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>mysql</groupId>
48+
<artifactId>mysql-connector-java</artifactId>
49+
<scope>runtime</scope>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>com.alibaba</groupId>
54+
<artifactId>druid-spring-boot-starter</artifactId>
55+
</dependency>
56+
57+
58+
59+
<dependency>
60+
<groupId>cn.hutool</groupId>
61+
<artifactId>hutool-all</artifactId>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>com.google.guava</groupId>
66+
<artifactId>guava</artifactId>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.apache.commons</groupId>
71+
<artifactId>commons-collections4</artifactId>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>org.apache.commons</groupId>
76+
<artifactId>commons-lang3</artifactId>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>io.springfox</groupId>
81+
<artifactId>springfox-swagger2</artifactId>
82+
</dependency>
83+
84+
<dependency>
85+
<groupId>io.springfox</groupId>
86+
<artifactId>springfox-swagger-ui</artifactId>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>io.swagger</groupId>
91+
<artifactId>swagger-annotations</artifactId>
92+
</dependency>
93+
94+
<dependency>
95+
<groupId>io.swagger</groupId>
96+
<artifactId>swagger-models</artifactId>
97+
</dependency>
98+
99+
<dependency>
100+
<groupId>com.alibaba</groupId>
101+
<artifactId>fastjson</artifactId>
102+
</dependency>
103+
104+
105+
<dependency>
106+
<groupId>org.projectlombok</groupId>
107+
<artifactId>lombok</artifactId>
108+
<optional>true</optional>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.springframework.boot</groupId>
112+
<artifactId>spring-boot-starter-test</artifactId>
113+
<scope>test</scope>
114+
</dependency>
115+
</dependencies>
116+
117+
<build>
118+
<plugins>
119+
<plugin>
120+
<groupId>org.springframework.boot</groupId>
121+
<artifactId>spring-boot-maven-plugin</artifactId>
122+
<configuration>
123+
<excludes>
124+
<exclude>
125+
<groupId>org.projectlombok</groupId>
126+
<artifactId>lombok</artifactId>
127+
</exclude>
128+
</excludes>
129+
</configuration>
130+
</plugin>
131+
</plugins>
132+
</build>
133+
134+
135+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.lybgeek.mybatisplus;
2+
3+
import org.mybatis.spring.annotation.MapperScan;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
@SpringBootApplication
8+
@MapperScan(basePackages = "com.github.lybgeek.**.dao")
9+
public class SpringbootMybatisplusTenantApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(SpringbootMybatisplusTenantApplication.class, args);
13+
}
14+
15+
}

0 commit comments

Comments
 (0)