From 1f04682c16801665ced72d76e831bb42dee5b75f Mon Sep 17 00:00:00 2001
From: zhanghonghao <287232522@qq.com>
Date: Fri, 2 Apr 2021 15:47:40 +0800
Subject: [PATCH 01/11] =?UTF-8?q?=E6=8F=90=E4=BA=A4pom=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lab-04-rabbitmq/lab-04-rabbitmq-native/pom.xml | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lab-04-rabbitmq/lab-04-rabbitmq-native/pom.xml b/lab-04-rabbitmq/lab-04-rabbitmq-native/pom.xml
index 9ed25eafe..9129e03ad 100644
--- a/lab-04-rabbitmq/lab-04-rabbitmq-native/pom.xml
+++ b/lab-04-rabbitmq/lab-04-rabbitmq-native/pom.xml
@@ -3,9 +3,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- lab-04
- cn.iocoder.springboot.labs
- 1.0-SNAPSHOT
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.2.1.RELEASE
+
4.0.0
From e7b091d5c58c27ea9ae03da39766edec949e0c32 Mon Sep 17 00:00:00 2001
From: YunaiV
Date: Sun, 8 Aug 2021 18:34:30 +0800
Subject: [PATCH 02/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Spring=20Boot=20?=
=?UTF-8?q?=E8=B0=83=E8=AF=95=E6=BA=90=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d0fa02e16..156b27a84 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,8 @@
* [《芋道 Spring Boot 快速入门》](http://www.iocoder.cn/Spring-Boot/quick-start/?github)
* [《芋道 Spring Boot 自动配置原理》](http://www.iocoder.cn/Spring-Boot/autoconfigure/?github) 对应 [lab-47](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-47)
-* [《芋道 Spring Boot 芋道 Spring Boot Jar 启动原理》](http://www.iocoder.cn/Spring-Boot/jar/?github)
+* [《芋道 Spring Boot Jar 启动原理》](http://www.iocoder.cn/Spring-Boot/jar/?github)
+* [《芋道 Spring Boot 调试环境》](http://www.iocoder.cn/Spring-Boot/build-debugging-environment-2-6-0/?github)
## 开发工具
From baf8bcab08056b4e6893da9e8763ba0b67bb0d11 Mon Sep 17 00:00:00 2001
From: YunaiV
Date: Sat, 21 Aug 2021 21:26:34 +0800
Subject: [PATCH 03/11] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20showdoc=20=E7=94=9F?=
=?UTF-8?q?=E6=88=90=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lab-24/lab-24-apidoc-showdoc/pom.xml | 23 +++++++++++
.../lab24/apidoc/ShowDocApplication.java | 13 +++++++
.../apidoc/controller/UserController.java | 22 +++++++++++
.../apidoc/controller/vo/UserLoginReqVO.java | 26 +++++++++++++
.../apidoc/controller/vo/UserLoginRespVO.java | 38 +++++++++++++++++++
lab-24/pom.xml | 1 +
pom.xml | 2 +-
7 files changed, 124 insertions(+), 1 deletion(-)
create mode 100644 lab-24/lab-24-apidoc-showdoc/pom.xml
create mode 100644 lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/ShowDocApplication.java
create mode 100644 lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/UserController.java
create mode 100644 lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/vo/UserLoginReqVO.java
create mode 100644 lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/vo/UserLoginRespVO.java
diff --git a/lab-24/lab-24-apidoc-showdoc/pom.xml b/lab-24/lab-24-apidoc-showdoc/pom.xml
new file mode 100644
index 000000000..e9a1f734a
--- /dev/null
+++ b/lab-24/lab-24-apidoc-showdoc/pom.xml
@@ -0,0 +1,23 @@
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.2.11.RELEASE
+
+
+ 4.0.0
+
+ lab-24-apidoc-showdoc
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
diff --git a/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/ShowDocApplication.java b/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/ShowDocApplication.java
new file mode 100644
index 000000000..ae4b80421
--- /dev/null
+++ b/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/ShowDocApplication.java
@@ -0,0 +1,13 @@
+package cn.iocoder.springboot.lab24.apidoc;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class ShowDocApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ShowDocApplication.class, args);
+ }
+
+}
diff --git a/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/UserController.java b/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/UserController.java
new file mode 100644
index 000000000..1e85425f1
--- /dev/null
+++ b/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/UserController.java
@@ -0,0 +1,22 @@
+package cn.iocoder.springboot.lab24.apidoc.controller;
+
+import cn.iocoder.springboot.lab24.apidoc.controller.vo.UserLoginReqVO;
+import cn.iocoder.springboot.lab24.apidoc.controller.vo.UserLoginRespVO;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+
+@RestController
+@RequestMapping("/users")
+public class UserController {
+
+ @PostMapping("/login")
+ public UserLoginRespVO login(@RequestBody UserLoginReqVO reqVO) {
+ UserLoginRespVO respVO = new UserLoginRespVO();
+ respVO.setUserId(1024);
+ respVO.setUsername(reqVO.getUsername());
+ respVO.setName("芋道源码");
+ return respVO;
+ }
+
+}
diff --git a/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/vo/UserLoginReqVO.java b/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/vo/UserLoginReqVO.java
new file mode 100644
index 000000000..deb154499
--- /dev/null
+++ b/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/vo/UserLoginReqVO.java
@@ -0,0 +1,26 @@
+package cn.iocoder.springboot.lab24.apidoc.controller.vo;
+
+public class UserLoginReqVO {
+
+ private String username;
+
+ private String password;
+
+ public String getUsername() {
+ return username;
+ }
+
+ public UserLoginReqVO setUsername(String username) {
+ this.username = username;
+ return this;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public UserLoginReqVO setPassword(String password) {
+ this.password = password;
+ return this;
+ }
+}
diff --git a/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/vo/UserLoginRespVO.java b/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/vo/UserLoginRespVO.java
new file mode 100644
index 000000000..5473aba37
--- /dev/null
+++ b/lab-24/lab-24-apidoc-showdoc/src/main/java/cn/iocoder/springboot/lab24/apidoc/controller/vo/UserLoginRespVO.java
@@ -0,0 +1,38 @@
+package cn.iocoder.springboot.lab24.apidoc.controller.vo;
+
+public class UserLoginRespVO {
+
+ private Integer userId;
+
+ private String name;
+
+ private String username;
+
+ public Integer getUserId() {
+ return userId;
+ }
+
+ public UserLoginRespVO setUserId(Integer userId) {
+ this.userId = userId;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public UserLoginRespVO setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public UserLoginRespVO setUsername(String username) {
+ this.username = username;
+ return this;
+ }
+
+}
diff --git a/lab-24/pom.xml b/lab-24/pom.xml
index 7d0bf03c5..20dc9f820 100644
--- a/lab-24/pom.xml
+++ b/lab-24/pom.xml
@@ -16,6 +16,7 @@
lab-24-apidoc-swagger-knife4j
lab-24-apidoc-japidocs
lab-24-apidoc-swagger-starter
+ lab-24-apidoc-showdoc
diff --git a/pom.xml b/pom.xml
index c976242b6..23bd90cac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
-
+ lab-24
From 60a9dd53038e1cf2fd131d44d4119d44a49bce52 Mon Sep 17 00:00:00 2001
From: YunaiV
Date: Sun, 22 Aug 2021 01:03:58 +0800
Subject: [PATCH 04/11] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20showdoc=20=E7=94=9F?=
=?UTF-8?q?=E6=88=90=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lab-24/lab-24-apidoc-showdoc/showdoc_api.sh | 64 +++++++++++++++++++
.../apidoc/controller/UserController.java | 26 +++++++-
.../apidoc/controller/vo/UserLoginReqVO.java | 3 +
lab-24/lab-24-apidoc-showdoc/swagger.json | 1 +
4 files changed, 92 insertions(+), 2 deletions(-)
create mode 100644 lab-24/lab-24-apidoc-showdoc/showdoc_api.sh
create mode 100644 lab-24/lab-24-apidoc-showdoc/swagger.json
diff --git a/lab-24/lab-24-apidoc-showdoc/showdoc_api.sh b/lab-24/lab-24-apidoc-showdoc/showdoc_api.sh
new file mode 100644
index 000000000..bf24f883f
--- /dev/null
+++ b/lab-24/lab-24-apidoc-showdoc/showdoc_api.sh
@@ -0,0 +1,64 @@
+#! /bin/bash
+#
+# 文档说明: https://www.showdoc.com.cn/page/741656402509783
+#
+api_key="60fc53cea6af4758c1686cb22ba20566472255580" #api_key
+api_token="0bbb5f564a9ee66333115b1abb8f8d541979489118" #api_token
+url="https://www.showdoc.com.cn/server/?s=/api/open/fromComments" #同步到的url。使用www.showdoc.com.cn的不需要修改,使用私有版的请修改
+#
+#
+#
+#
+#
+# 如果第一个参数是目录,则使用参数目录。若无,则使用脚本所在的目录。
+if [[ -z "$1" ]] || [[ ! -d "$1" ]] ; then #目录判断,如果$1不是目录或者是空,则使用当前目录
+ curren_dir=$(dirname $(readlink -f $0))
+else
+ curren_dir=$(cd $1; pwd)
+fi
+#echo "$curren_dir"
+# 递归搜索文件
+searchfile() {
+
+ old_IFS="$IFS"
+ IFS=$'\n' #IFS修改
+ for chkfile in $1/*
+ do
+ filesize=`ls -l $chkfile | awk '{ print $5 }'`
+ maxsize=$((1024*1024*1)) # 1M以下的文本文件才会被扫描
+ if [[ -f "$chkfile" ]] && [ $filesize -le $maxsize ] && [[ -n $(file $chkfile | grep text) ]] ; then # 只对text文件类型操作
+ echo "正在扫描 $chkfile"
+ result=$(sed -n -e '/\/\*\*/,/\*\//p' $chkfile | grep showdoc) # 正则匹配
+ if [ ! -z "$result" ] ; then
+ txt=$(sed -n -e '/\/\*\*/,/\*\//p' $chkfile)
+ #echo "sed -n -e '/\/\*\*/,/\*\//p' $chkfile"
+ #echo $result
+ if [[ $txt =~ "@url" ]] && [[ $txt =~ "@title" ]]; then
+ echo -e "\033[32m $chkfile 扫描到内容 , 正在生成文档 \033[0m "
+ txt2=${txt//&/_this_and_change_}
+ # 通过接口生成文档
+curl -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' "${url}" --data-binary @- <
Date: Sun, 22 Aug 2021 02:43:51 +0800
Subject: [PATCH 05/11] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20showdoc=20=E7=94=9F?=
=?UTF-8?q?=E6=88=90=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 1 +
lab-24/lab-24-apidoc-showdoc/showdoc_db.sh | 33 +++++++++++++++++++
...c \345\205\245\351\227\250\343\200\213.md" | 1 +
3 files changed, 35 insertions(+)
create mode 100644 lab-24/lab-24-apidoc-showdoc/showdoc_db.sh
create mode 100644 "lab-24/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\346\226\207\346\241\243 ShowDoc \345\205\245\351\227\250\343\200\213.md"
diff --git a/README.md b/README.md
index 156b27a84..a4f74eb9c 100644
--- a/README.md
+++ b/README.md
@@ -65,6 +65,7 @@
* [《性能测试 —— Tomcat、Jetty、Undertow 基准测试》](http://www.iocoder.cn/Performance-Testing/Tomcat-Jetty-Undertow-benchmark/?github) 对应 [lab-05-benchmark-tomcat-jetty-undertow](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-05-benchmark-tomcat-jetty-undertow)
* [《性能测试 —— SpringMVC、Webflux 基准测试》](http://www.iocoder.cn/Performance-Testing/SpringMVC-Webflux-benchmark/?github) 对应 [lab-06](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-06)
* [《芋道 Spring Boot API 接口文档 JApiDocs 入门》](http://www.iocoder.cn/Spring-Boot/JApiDocs/?github) 对应 [lab-24](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-24)
+* [《芋道 Spring Boot API 接口文档 ShowDoc 入门》](http://www.iocoder.cn/Spring-Boot/ShowDoc/?github) 对应 [lab-24](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-24)
* [《芋道 Spring Boot API 接口调试 IDEA HTTP Client》](http://www.iocoder.cn/Spring-Boot/IDEA-HTTP-Client/?github) 对应 [lab-71-http-debug](https://github.com/YunaiV/SpringBoot-Labs/blob/master/lab-71-http-debug/)
## RPC 开发
diff --git a/lab-24/lab-24-apidoc-showdoc/showdoc_db.sh b/lab-24/lab-24-apidoc-showdoc/showdoc_db.sh
new file mode 100644
index 000000000..bb385790e
--- /dev/null
+++ b/lab-24/lab-24-apidoc-showdoc/showdoc_db.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+#
+#
+host="127.0.0.1" #数据库所在地址。默认是localhost
+port=3306 #数据库所在端口。默认是3306
+user="root" #数据库的用户名
+password="123456" #密码
+db="ruoyi -vue-pro" #要同步的数据库名。要同步多个db可以将本脚本复制多份
+api_key="60fc53cea6af4758c1686cb22ba20566472255580" #api_key
+api_token="0bbb5f564a9ee66333115b1abb8f8d541979489118" #api_token
+cat_name="数据字典" #可选。如果想把生成的文档都放在项目的子目录下,则这里填写子目录名。
+url="https://www.showdoc.com.cn/server/?s=/api/open/updateDbItem" #可选。同步到的url。如果是使用www.showdoc.com.cn ,则不需要再改此项。如果是部署私有版版showdoc,请改此项为http://xx.com/server/index.php?s=/api/open/updateDbItem 。其中xx.com为你的部署域名
+#
+#
+#
+#
+#
+#
+export MYSQL_PWD=${password}
+COMMAND="set names utf8;select TABLE_NAME ,TABLE_COMMENT from tables where TABLE_SCHEMA ='${db}' "
+declare table_info=`mysql -h${host} -P${port} -u${user} --show-warnings=false -D information_schema -e "${COMMAND}" `
+#echo $table_info
+COMMAND="set names utf8;select TABLE_NAME ,COLUMN_NAME, COLUMN_DEFAULT ,IS_NULLABLE ,COLUMN_TYPE ,COLUMN_COMMENT from COLUMNS where TABLE_SCHEMA ='${db}' "
+declare table_detail=`mysql -h${host} -P${port} -u${user} --show-warnings=false -D information_schema -e "${COMMAND}" `
+#echo $table_detail
+table_info2=${table_info//&/_this_and_change_}
+table_detail2=${table_detail//&/_this_and_change_}
+curl -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' "${url}" --data-binary @- <
From 5be6fe347b92e579cdf619b1d50cb3f3e1b0f202 Mon Sep 17 00:00:00 2001
From: YunaiV
Date: Sat, 4 Dec 2021 09:02:21 +0800
Subject: [PATCH 06/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20mybatis=20plus=20?=
=?UTF-8?q?=E5=A4=9A=E7=A7=9F=E6=88=B7=E7=9A=84=E7=A4=BA=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../lab-12-mybatis-plus-tenant/pom.xml | 43 +++++++++
.../springboot/lab12/mybatis/Application.java | 9 ++
.../mybatis/config/MybatisPlusConfig.java | 40 ++++++++
.../lab12/mybatis/dataobject/UserDO.java | 96 +++++++++++++++++++
.../lab12/mybatis/mapper/UserMapper.java | 30 ++++++
.../src/main/resources/application.yaml | 30 ++++++
.../src/main/resources/mapper/UserMapper.xml | 19 ++++
.../src/main/resources/sql/users.sql | 10 ++
.../lab12/mybatis/mapper/UserMapperTest.java | 67 +++++++++++++
lab-12-mybatis/pom.xml | 1 +
pom.xml | 2 +-
11 files changed, 346 insertions(+), 1 deletion(-)
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/pom.xml
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/Application.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/MybatisPlusConfig.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/dataobject/UserDO.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapper.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/application.yaml
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/mapper/UserMapper.xml
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/sql/users.sql
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapperTest.java
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/pom.xml b/lab-12-mybatis/lab-12-mybatis-plus-tenant/pom.xml
new file mode 100644
index 000000000..9c7d7bd4d
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/pom.xml
@@ -0,0 +1,43 @@
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.3.RELEASE
+
+
+ 4.0.0
+
+ lab-12-mybatis-plus-tenant
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+ mysql
+ mysql-connector-java
+ 5.1.48
+
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.4.1
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/Application.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/Application.java
new file mode 100644
index 000000000..ba4ae5d28
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/Application.java
@@ -0,0 +1,9 @@
+package cn.iocoder.springboot.lab12.mybatis;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@MapperScan(basePackages = "cn.iocoder.springboot.lab12.mybatis.mapper")
+public class Application {
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/MybatisPlusConfig.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/MybatisPlusConfig.java
new file mode 100644
index 000000000..964044bab
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/MybatisPlusConfig.java
@@ -0,0 +1,40 @@
+package cn.iocoder.springboot.lab12.mybatis.config;
+
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
+import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
+import net.sf.jsqlparser.expression.Expression;
+import net.sf.jsqlparser.expression.LongValue;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MybatisPlusConfig {
+
+ /**
+ * 新多租户插件配置,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存万一出现问题
+ */
+ @Bean
+ public MybatisPlusInterceptor mybatisPlusInterceptor() {
+ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+ interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
+
+ @Override
+ public Expression getTenantId() {
+ return new LongValue(10);
+ }
+
+ // 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件
+ @Override
+ public boolean ignoreTable(String tableName) {
+ return false;
+ }
+
+ }));
+ // 如果用了分页插件注意先 add TenantLineInnerInterceptor 再 add PaginationInnerInterceptor
+ // 用了分页插件必须设置 MybatisConfiguration#useDeprecatedExecutor = false
+// interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+ return interceptor;
+ }
+
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/dataobject/UserDO.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/dataobject/UserDO.java
new file mode 100644
index 000000000..bf53c7740
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/dataobject/UserDO.java
@@ -0,0 +1,96 @@
+package cn.iocoder.springboot.lab12.mybatis.dataobject;
+
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.util.Date;
+
+/**
+ * 用户 DO
+ */
+@TableName(value = "users")
+public class UserDO {
+
+ /**
+ * 用户编号
+ */
+ private Integer id;
+ /**
+ * 账号
+ */
+ private String username;
+ /**
+ * 密码(明文)
+ *
+ * ps:生产环境下,千万不要明文噢
+ */
+ private String password;
+ /**
+ * 创建时间
+ */
+ private Date createTime;
+ /**
+ * 是否删除
+ */
+ @TableLogic
+ private Integer deleted;
+ /**
+ * 租户编号
+ */
+ private Integer tenantId;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public UserDO setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public UserDO setUsername(String username) {
+ this.username = username;
+ return this;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public UserDO setPassword(String password) {
+ this.password = password;
+ return this;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public UserDO setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ return this;
+ }
+
+ public Integer getDeleted() {
+ return deleted;
+ }
+
+ public UserDO setDeleted(Integer deleted) {
+ this.deleted = deleted;
+ return this;
+ }
+
+ public Integer getTenantId() {
+ return tenantId;
+ }
+
+ public UserDO setTenantId(Integer tenantId) {
+ this.tenantId = tenantId;
+ return this;
+ }
+
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapper.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapper.java
new file mode 100644
index 000000000..65aefd683
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapper.java
@@ -0,0 +1,30 @@
+package cn.iocoder.springboot.lab12.mybatis.mapper;
+
+import cn.iocoder.springboot.lab12.mybatis.dataobject.UserDO;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+@Repository
+public interface UserMapper extends BaseMapper {
+
+ default UserDO selectByUsername(@Param("username") String username) {
+ return selectOne(new QueryWrapper().eq("username", username));
+ }
+
+ List selectByIds(@Param("ids") Collection ids);
+
+ default IPage selectPageByCreateTime(IPage page, @Param("createTime") Date createTime) {
+ return selectPage(page,
+ new QueryWrapper().gt("create_time", createTime)
+// new QueryWrapper().like("username", "46683d9d")
+ );
+ }
+
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/application.yaml b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/application.yaml
new file mode 100644
index 000000000..989353a86
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/application.yaml
@@ -0,0 +1,30 @@
+spring:
+ # datasource 数据源配置内容
+ datasource:
+ url: jdbc:mysql://127.0.0.1:3306/testb5f4?useSSL=false&useUnicode=true&characterEncoding=UTF-8
+ driver-class-name: com.mysql.jdbc.Driver
+ username: root
+ password: 123456
+
+# mybatis-plus 配置内容
+mybatis-plus:
+ configuration:
+ map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
+ global-config:
+ db-config:
+ id-type: auto # ID 主键自增
+ logic-delete-value: 1 # 逻辑已删除值(默认为 1)
+ logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
+ mapper-locations: classpath*:mapper/*.xml
+ type-aliases-package: cn.iocoder.springboot.lab12.mybatis.dataobject
+
+# logging
+logging:
+ level:
+ # dao 开启 debug 模式 mybatis 输入 sql
+ cn:
+ iocoder:
+ springboot:
+ lab12:
+ mybatis:
+ mapper: debug
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/mapper/UserMapper.xml b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/mapper/UserMapper.xml
new file mode 100644
index 000000000..91d31116b
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/mapper/UserMapper.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+ id, username, password, create_time
+
+
+
+
+
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/sql/users.sql b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/sql/users.sql
new file mode 100644
index 000000000..8a0b36087
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/sql/users.sql
@@ -0,0 +1,10 @@
+CREATE TABLE `users` (
+ `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户编号',
+ `username` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '账号',
+ `password` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '密码',
+ `create_time` datetime DEFAULT NULL COMMENT '创建时间',
+ `deleted` bit(1) DEFAULT NULL COMMENT '是否删除。0-未删除;1-删除',
+ `tenant_id` int(11) NOT NULL COMMENT '租户编号',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `idx_username` (`username`)
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapperTest.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapperTest.java
new file mode 100644
index 000000000..b88a497ef
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapperTest.java
@@ -0,0 +1,67 @@
+package cn.iocoder.springboot.lab12.mybatis.mapper;
+
+import cn.iocoder.springboot.lab12.mybatis.Application;
+import cn.iocoder.springboot.lab12.mybatis.dataobject.UserDO;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = Application.class)
+public class UserMapperTest {
+
+ @Autowired
+ private UserMapper userMapper;
+
+ @Test
+ public void testInsert() {
+ UserDO user = new UserDO().setUsername(UUID.randomUUID().toString())
+ .setPassword("nicai").setCreateTime(new Date())
+ .setDeleted(0); // 一般情况下,是否删除,可以全局枚举下。
+ userMapper.insert(user);
+ }
+
+ @Test
+ public void testUpdateById() {
+ UserDO updateUser = new UserDO().setId(1)
+ .setPassword("wobucai");
+ userMapper.updateById(updateUser);
+ }
+
+ @Test
+ public void testDeleteById() {
+ userMapper.deleteById(2);
+ }
+
+ @Test
+ public void testSelectById() {
+ userMapper.selectById(1);
+ }
+
+ @Test
+ public void testSelectByUsername() {
+ UserDO userDO = userMapper.selectByUsername("yunai");
+ System.out.println(userDO);
+ }
+
+ @Test
+ public void testSelectByIds() {
+ List users = userMapper.selectByIds(Arrays.asList(1, 3));
+ System.out.println("users:" + users.size());
+ }
+
+ @Test
+ public void testSelectPageByCreateTime() {
+ IPage page = new Page<>(1, 10);
+ Date createTime = new Date(2018 - 1990, Calendar.FEBRUARY, 24); // 临时 Demo ,实际不建议这么写
+ page = userMapper.selectPageByCreateTime(page, createTime);
+ System.out.println("users:" + page.getRecords().size());
+ }
+
+}
diff --git a/lab-12-mybatis/pom.xml b/lab-12-mybatis/pom.xml
index abc9330d2..462b3ec46 100644
--- a/lab-12-mybatis/pom.xml
+++ b/lab-12-mybatis/pom.xml
@@ -16,6 +16,7 @@
lab-12-mybatis-annotation
lab-12-mybatis-plus
lab-12-mybatis-tk
+ lab-12-mybatis-plus-tenant
diff --git a/pom.xml b/pom.xml
index 23bd90cac..979689f3b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,7 @@
-
+ lab-12-mybatis
From b96e0a1d2571883ebe1ae972dda5fee6d0284a9f Mon Sep 17 00:00:00 2001
From: YunaiV
Date: Sat, 4 Dec 2021 09:24:50 +0800
Subject: [PATCH 07/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20mybatis=20plus=20?=
=?UTF-8?q?=E5=A4=9A=E7=A7=9F=E6=88=B7=E7=9A=84=E7=A4=BA=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../mybatis/dataobject/UserProfileDO.java | 78 ++++++++++++
.../lab12/mybatis/mapper/UserMapper.java | 5 +
.../mybatis/mapper/UserProfileMapper.java | 9 ++
.../lab12/mybatis/vo/UserDetailVO.java | 116 ++++++++++++++++++
.../src/main/resources/mapper/UserMapper.xml | 15 +++
.../src/main/resources/sql/users.sql | 30 +++--
.../lab12/mybatis/mapper/UserMapperTest.java | 36 ++++++
7 files changed, 279 insertions(+), 10 deletions(-)
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/dataobject/UserProfileDO.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserProfileMapper.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/vo/UserDetailVO.java
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/dataobject/UserProfileDO.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/dataobject/UserProfileDO.java
new file mode 100644
index 000000000..a9bc2d660
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/dataobject/UserProfileDO.java
@@ -0,0 +1,78 @@
+package cn.iocoder.springboot.lab12.mybatis.dataobject;
+
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+/**
+ * 用户拓展 DO
+ */
+@TableName(value = "user_profile")
+public class UserProfileDO {
+
+ /**
+ * 编号
+ */
+ private Integer id;
+ /**
+ * 用户编号
+ */
+ private Integer userId;
+ /**
+ * 性别
+ */
+ private Integer gender;
+ /**
+ * 是否删除
+ */
+ @TableLogic
+ private Integer deleted;
+ /**
+ * 租户编号
+ */
+ private Integer tenantId;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public UserProfileDO setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public Integer getGender() {
+ return gender;
+ }
+
+ public UserProfileDO setGender(Integer gender) {
+ this.gender = gender;
+ return this;
+ }
+
+ public Integer getDeleted() {
+ return deleted;
+ }
+
+ public UserProfileDO setDeleted(Integer deleted) {
+ this.deleted = deleted;
+ return this;
+ }
+
+ public Integer getTenantId() {
+ return tenantId;
+ }
+
+ public UserProfileDO setTenantId(Integer tenantId) {
+ this.tenantId = tenantId;
+ return this;
+ }
+
+ public Integer getUserId() {
+ return userId;
+ }
+
+ public UserProfileDO setUserId(Integer userId) {
+ this.userId = userId;
+ return this;
+ }
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapper.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapper.java
index 65aefd683..bd9553923 100644
--- a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapper.java
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapper.java
@@ -1,6 +1,7 @@
package cn.iocoder.springboot.lab12.mybatis.mapper;
import cn.iocoder.springboot.lab12.mybatis.dataobject.UserDO;
+import cn.iocoder.springboot.lab12.mybatis.vo.UserDetailVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -27,4 +28,8 @@ default IPage selectPageByCreateTime(IPage page, @Param("createT
);
}
+ List selectListA();
+
+ List selectListB();
+
}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserProfileMapper.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserProfileMapper.java
new file mode 100644
index 000000000..6648c443e
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserProfileMapper.java
@@ -0,0 +1,9 @@
+package cn.iocoder.springboot.lab12.mybatis.mapper;
+
+import cn.iocoder.springboot.lab12.mybatis.dataobject.UserProfileDO;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface UserProfileMapper extends BaseMapper {
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/vo/UserDetailVO.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/vo/UserDetailVO.java
new file mode 100644
index 000000000..ba0e37bb8
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/vo/UserDetailVO.java
@@ -0,0 +1,116 @@
+package cn.iocoder.springboot.lab12.mybatis.vo;
+
+import com.baomidou.mybatisplus.annotation.TableLogic;
+
+import java.util.Date;
+
+public class UserDetailVO {
+
+ /**
+ * 用户编号
+ */
+ private Integer id;
+ /**
+ * 账号
+ */
+ private String username;
+ /**
+ * 密码(明文)
+ *
+ * ps:生产环境下,千万不要明文噢
+ */
+ private String password;
+ /**
+ * 性别
+ */
+ private Integer gender;
+ /**
+ * 创建时间
+ */
+ private Date createTime;
+ /**
+ * 是否删除
+ */
+ @TableLogic
+ private Integer deleted;
+ /**
+ * 租户编号
+ */
+ private Integer tenantId;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public UserDetailVO setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public UserDetailVO setUsername(String username) {
+ this.username = username;
+ return this;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public UserDetailVO setPassword(String password) {
+ this.password = password;
+ return this;
+ }
+
+ public Integer getGender() {
+ return gender;
+ }
+
+ public UserDetailVO setGender(Integer gender) {
+ this.gender = gender;
+ return this;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public UserDetailVO setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ return this;
+ }
+
+ public Integer getDeleted() {
+ return deleted;
+ }
+
+ public UserDetailVO setDeleted(Integer deleted) {
+ this.deleted = deleted;
+ return this;
+ }
+
+ public Integer getTenantId() {
+ return tenantId;
+ }
+
+ public UserDetailVO setTenantId(Integer tenantId) {
+ this.tenantId = tenantId;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "UserDetailVO{" +
+ "id=" + id +
+ ", username='" + username + '\'' +
+ ", password='" + password + '\'' +
+ ", gender=" + gender +
+ ", createTime=" + createTime +
+ ", deleted=" + deleted +
+ ", tenantId=" + tenantId +
+ '}';
+ }
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/mapper/UserMapper.xml b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/mapper/UserMapper.xml
index 91d31116b..f4a3a9f25 100644
--- a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/mapper/UserMapper.xml
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/mapper/UserMapper.xml
@@ -16,4 +16,19 @@
+
+
+
+
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/sql/users.sql b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/sql/users.sql
index 8a0b36087..3d6d0fbb5 100644
--- a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/sql/users.sql
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/resources/sql/users.sql
@@ -1,10 +1,20 @@
-CREATE TABLE `users` (
- `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户编号',
- `username` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '账号',
- `password` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '密码',
- `create_time` datetime DEFAULT NULL COMMENT '创建时间',
- `deleted` bit(1) DEFAULT NULL COMMENT '是否删除。0-未删除;1-删除',
- `tenant_id` int(11) NOT NULL COMMENT '租户编号',
- PRIMARY KEY (`id`),
- UNIQUE KEY `idx_username` (`username`)
-) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
+CREATE TABLE `users`
+(
+ `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户编号',
+ `username` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '账号',
+ `password` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '密码',
+ `create_time` datetime DEFAULT NULL COMMENT '创建时间',
+ `deleted` bit(1) DEFAULT NULL COMMENT '是否删除。0-未删除;1-删除',
+ `tenant_id` int(11) NOT NULL COMMENT '租户编号',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
+
+CREATE TABLE `user_profile`
+(
+ `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号',
+ `user_id` int(11) NOT NULL COMMENT '用户编号',
+ `gender` int(11) NOT NULL COMMENT '性别',
+ `deleted` bit(1) DEFAULT NULL COMMENT '是否删除。0-未删除;1-删除',
+ `tenant_id` int(11) NOT NULL COMMENT '租户编号',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapperTest.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapperTest.java
index b88a497ef..8e1158d53 100644
--- a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapperTest.java
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/mapper/UserMapperTest.java
@@ -2,6 +2,9 @@
import cn.iocoder.springboot.lab12.mybatis.Application;
import cn.iocoder.springboot.lab12.mybatis.dataobject.UserDO;
+import cn.iocoder.springboot.lab12.mybatis.dataobject.UserProfileDO;
+import cn.iocoder.springboot.lab12.mybatis.vo.UserDetailVO;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.junit.Test;
@@ -18,6 +21,27 @@ public class UserMapperTest {
@Autowired
private UserMapper userMapper;
+ @Autowired
+ private UserProfileMapper userProfileMapper;
+
+ @Test
+ public void initTestData() {
+ // 清理数据
+ userMapper.delete(new QueryWrapper<>());
+ userProfileMapper.delete(new QueryWrapper<>());
+ // 插入一个用户
+ UserDO userDO = new UserDO().setUsername(UUID.randomUUID().toString())
+ .setPassword("nicai").setCreateTime(new Date())
+ .setDeleted(0); // 一般情况下,是否删除,可以全局枚举下。
+ userMapper.insert(userDO);
+ // 插入该用户的拓展信息
+ UserProfileDO userProfileDO = new UserProfileDO();
+ userProfileDO.setUserId(userDO.getId());
+ userProfileDO.setGender(1);
+ userProfileDO.setTenantId(10); // TODO 全局写死
+ userProfileDO.setDeleted(0); // 一般情况下,是否删除,可以全局枚举下。
+ userProfileMapper.insert(userProfileDO);
+ }
@Test
public void testInsert() {
@@ -64,4 +88,16 @@ public void testSelectPageByCreateTime() {
System.out.println("users:" + page.getRecords().size());
}
+ @Test
+ public void testSelectListA() {
+ List list = userMapper.selectListA();
+ System.out.println(list);
+ }
+
+ @Test
+ public void testSelectListB() {
+ List list = userMapper.selectListB();
+ System.out.println(list);
+ }
+
}
From 9023aa01094d779f477aa9fddb2e4aacc8a38602 Mon Sep 17 00:00:00 2001
From: YunaiV
Date: Sat, 4 Dec 2021 17:20:16 +0800
Subject: [PATCH 08/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20TTL=20=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E5=A4=9A=E7=A7=9F=E6=88=B7=E4=B8=8E=E4=B8=8A=E4=B8=8B?=
=?UTF-8?q?=E6=96=87=E7=9A=84=E9=9B=86=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../lab-12-mybatis-plus-tenant/pom.xml | 6 +++
.../lab12/mybatis/config/AsyncConfig.java | 32 ++++++++++++++
.../mybatis/config/MybatisPlusConfig.java | 4 +-
.../lab12/mybatis/context/TenantHolder.java | 19 ++++++++
.../core/TtlThreadPoolTaskExecutor.java | 44 +++++++++++++++++++
.../lab12/mybatis/service/UserService.java | 29 ++++++++++++
.../lab12/mybatis/util/TtlExecutorsUtil.java | 23 ++++++++++
.../mybatis/service/UserServiceTest.java | 31 +++++++++++++
8 files changed, 187 insertions(+), 1 deletion(-)
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/AsyncConfig.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/context/TenantHolder.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/core/TtlThreadPoolTaskExecutor.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/service/UserService.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/util/TtlExecutorsUtil.java
create mode 100644 lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/service/UserServiceTest.java
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/pom.xml b/lab-12-mybatis/lab-12-mybatis-plus-tenant/pom.xml
index 9c7d7bd4d..659a9fce0 100644
--- a/lab-12-mybatis/lab-12-mybatis-plus-tenant/pom.xml
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/pom.xml
@@ -38,6 +38,12 @@
test
+
+ com.alibaba
+ transmittable-thread-local
+ 2.12.2
+
+
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/AsyncConfig.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/AsyncConfig.java
new file mode 100644
index 000000000..3c22aa542
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/AsyncConfig.java
@@ -0,0 +1,32 @@
+package cn.iocoder.springboot.lab12.mybatis.config;
+
+import com.alibaba.ttl.TtlRunnable;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+@Configuration
+@EnableAsync
+public class AsyncConfig {
+
+ @Bean
+ public BeanPostProcessor executorBeanPostProcessor() {
+ return new BeanPostProcessor() {
+
+ @Override
+ public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
+ if (!(bean instanceof ThreadPoolTaskExecutor)) {
+ return bean;
+ }
+ ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean;
+ executor.setTaskDecorator(TtlRunnable::get);
+ return executor;
+ }
+
+ };
+ }
+
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/MybatisPlusConfig.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/MybatisPlusConfig.java
index 964044bab..ca599aefc 100644
--- a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/MybatisPlusConfig.java
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/config/MybatisPlusConfig.java
@@ -1,5 +1,6 @@
package cn.iocoder.springboot.lab12.mybatis.config;
+import cn.iocoder.springboot.lab12.mybatis.context.TenantHolder;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
@@ -21,7 +22,8 @@ public MybatisPlusInterceptor mybatisPlusInterceptor() {
@Override
public Expression getTenantId() {
- return new LongValue(10);
+ Integer tenantId = TenantHolder.getTenantId();
+ return new LongValue(tenantId);
}
// 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/context/TenantHolder.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/context/TenantHolder.java
new file mode 100644
index 000000000..d56044934
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/context/TenantHolder.java
@@ -0,0 +1,19 @@
+package cn.iocoder.springboot.lab12.mybatis.context;
+
+import com.alibaba.ttl.TransmittableThreadLocal;
+
+public class TenantHolder {
+
+ private static final ThreadLocal TENANT_ID = new TransmittableThreadLocal<>();
+// private static final ThreadLocal TENANT_ID = new ThreadLocal<>();
+// private static final ThreadLocal TENANT_ID = new InheritableThreadLocal<>();
+
+ public static void setTenantId(Integer tenantId) {
+ TENANT_ID.set(tenantId);
+ }
+
+ public static Integer getTenantId() {
+ return TENANT_ID.get();
+ }
+
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/core/TtlThreadPoolTaskExecutor.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/core/TtlThreadPoolTaskExecutor.java
new file mode 100644
index 000000000..5144ed7bc
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/core/TtlThreadPoolTaskExecutor.java
@@ -0,0 +1,44 @@
+package cn.iocoder.springboot.lab12.mybatis.core;
+
+import com.alibaba.ttl.TtlCallable;
+import com.alibaba.ttl.TtlRunnable;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.util.concurrent.ListenableFuture;
+
+import java.util.Objects;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
+
+@Deprecated
+public class TtlThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
+
+ @Override
+ public void execute(Runnable task) {
+ super.execute(Objects.requireNonNull(TtlRunnable.get(task)));
+ }
+
+ @Override
+ public void execute(Runnable task, long startTimeout) {
+ super.execute(Objects.requireNonNull(TtlRunnable.get(task)), startTimeout);
+ }
+
+ @Override
+ public Future> submit(Runnable task) {
+ return super.submit(Objects.requireNonNull(TtlRunnable.get(task)));
+ }
+
+ @Override
+ public Future submit(Callable task) {
+ return super.submit(Objects.requireNonNull(TtlCallable.get(task)));
+ }
+
+ @Override
+ public ListenableFuture> submitListenable(Runnable task) {
+ return super.submitListenable(Objects.requireNonNull(TtlRunnable.get(task)));
+ }
+
+ @Override
+ public ListenableFuture submitListenable(Callable task) {
+ return super.submitListenable(Objects.requireNonNull(TtlCallable.get(task)));
+ }
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/service/UserService.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/service/UserService.java
new file mode 100644
index 000000000..00e5a93b4
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/service/UserService.java
@@ -0,0 +1,29 @@
+package cn.iocoder.springboot.lab12.mybatis.service;
+
+import cn.iocoder.springboot.lab12.mybatis.dataobject.UserDO;
+import cn.iocoder.springboot.lab12.mybatis.mapper.UserMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.AsyncResult;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.concurrent.Future;
+
+@Service
+public class UserService {
+
+ private final Logger log = LoggerFactory.getLogger(UserService.class);
+
+ @Resource
+ private UserMapper userMapper;
+
+ @Async
+ public Future getUserAsync(Integer id) {
+ UserDO userDO = userMapper.selectById(id);
+ log.info("[getUserAsync][id({}) user({})]", id, userDO);
+ return AsyncResult.forValue(userDO);
+ }
+
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/util/TtlExecutorsUtil.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/util/TtlExecutorsUtil.java
new file mode 100644
index 000000000..a73c13351
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/main/java/cn/iocoder/springboot/lab12/mybatis/util/TtlExecutorsUtil.java
@@ -0,0 +1,23 @@
+package cn.iocoder.springboot.lab12.mybatis.util;
+
+import com.alibaba.ttl.spi.TtlEnhanced;
+import com.alibaba.ttl.threadpool.agent.TtlAgent;
+import org.springframework.lang.Nullable;
+
+import java.util.concurrent.Executor;
+
+/**
+ * {@link com.alibaba.ttl.threadpool.TtlExecutors} 工具类
+ */
+@Deprecated
+public class TtlExecutorsUtil {
+
+ public static Executor getTtlThreadPoolTaskExecutor(@Nullable Executor executor) {
+ if (TtlAgent.isTtlAgentLoaded() || null == executor || executor instanceof TtlEnhanced) {
+ return executor;
+ }
+// return new ExecutorTtlWrapper(executor, true);
+ return null;
+ }
+
+}
diff --git a/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/service/UserServiceTest.java b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/service/UserServiceTest.java
new file mode 100644
index 000000000..53b54a41b
--- /dev/null
+++ b/lab-12-mybatis/lab-12-mybatis-plus-tenant/src/test/java/cn/iocoder/springboot/lab12/mybatis/service/UserServiceTest.java
@@ -0,0 +1,31 @@
+package cn.iocoder.springboot.lab12.mybatis.service;
+
+import cn.iocoder.springboot.lab12.mybatis.Application;
+import cn.iocoder.springboot.lab12.mybatis.context.TenantHolder;
+import cn.iocoder.springboot.lab12.mybatis.dataobject.UserDO;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = Application.class)
+public class UserServiceTest {
+
+ @Resource
+ private UserService userService;
+
+ @Test
+ public void testGetUserAsync() throws ExecutionException, InterruptedException {
+ TenantHolder.setTenantId(10); // TODO 芋艿:写死
+ Future future = userService.getUserAsync(9);
+ future.get();
+ }
+
+}
From f41616c0572740696b32a6075a297846d0d25380 Mon Sep 17 00:00:00 2001
From: YunaiV
Date: Sat, 19 Mar 2022 11:24:03 +0800
Subject: [PATCH 09/11] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20MinIO=20=E7=A4=BA?=
=?UTF-8?q?=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lab-72-minio/pom.xml | 30 ++++++++++++
.../springboot/lab72/MinIOApplication.java | 13 +++++
.../lab72/config/MinIOConfiguration.java | 32 ++++++++++++
.../lab72/controller/FileController.java | 49 +++++++++++++++++++
pom.xml | 7 +--
5 files changed, 128 insertions(+), 3 deletions(-)
create mode 100644 lab-72-minio/pom.xml
create mode 100644 lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/MinIOApplication.java
create mode 100644 lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/config/MinIOConfiguration.java
create mode 100644 lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/controller/FileController.java
diff --git a/lab-72-minio/pom.xml b/lab-72-minio/pom.xml
new file mode 100644
index 000000000..8d6eec844
--- /dev/null
+++ b/lab-72-minio/pom.xml
@@ -0,0 +1,30 @@
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.6.4
+
+
+ 4.0.0
+
+ lab-72-minio
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ io.minio
+ minio
+ 8.2.2
+
+
+
+
diff --git a/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/MinIOApplication.java b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/MinIOApplication.java
new file mode 100644
index 000000000..78bc92cef
--- /dev/null
+++ b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/MinIOApplication.java
@@ -0,0 +1,13 @@
+package cn.iocoder.springboot.lab72;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class MinIOApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(MinIOApplication.class, args);
+ }
+
+}
diff --git a/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/config/MinIOConfiguration.java b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/config/MinIOConfiguration.java
new file mode 100644
index 000000000..a67f767f7
--- /dev/null
+++ b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/config/MinIOConfiguration.java
@@ -0,0 +1,32 @@
+package cn.iocoder.springboot.lab72.config;
+
+import io.minio.BucketExistsArgs;
+import io.minio.MakeBucketArgs;
+import io.minio.MinioClient;
+import io.minio.SetBucketPolicyArgs;
+import io.minio.errors.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.io.IOException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+@Configuration
+public class MinIOConfiguration {
+
+ @Bean
+ public MinioClient minioClient() {
+ // Minio 配置。实际项目中,定义到 application.yml 配置文件中
+ String endpoint = "http://127.0.0.1:9000";
+ String accessKey = "admin";
+ String secretKey = "password";
+
+ // 创建 MinioClient 客户端
+ return MinioClient.builder()
+ .endpoint(endpoint)
+ .credentials(accessKey, secretKey)
+ .build();
+ }
+
+}
diff --git a/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/controller/FileController.java b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/controller/FileController.java
new file mode 100644
index 000000000..1c4461ae8
--- /dev/null
+++ b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/controller/FileController.java
@@ -0,0 +1,49 @@
+package cn.iocoder.springboot.lab72.controller;
+
+import io.minio.MinioClient;
+import io.minio.PutObjectArgs;
+import io.minio.RemoveObjectArgs;
+import io.minio.errors.*;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.UUID;
+
+@RestController
+@RequestMapping("/file")
+public class FileController {
+
+ @Resource
+ private MinioClient minioClient;
+
+ // Minio 配置。实际项目中,定义到 application.yml 配置文件中
+ private String endpoint = "http://127.0.0.1:9000";
+ private String bucket = "yudaoyuanma";
+
+ @PostMapping("/upload")
+ public String upload(@RequestParam("file") MultipartFile file) throws Exception {
+ // 上传
+ String path = UUID.randomUUID().toString(); // 文件名,使用 UUID 随机
+ minioClient.putObject(PutObjectArgs.builder()
+ .bucket(bucket) // 存储桶
+ .object(path) // 文件名
+ .stream(file.getInputStream(), file.getSize(), -1) // 文件内容
+ .contentType(file.getContentType()) // 文件类型
+ .build());
+ // 拼接路径
+ return String.format("%s/%s/%s", endpoint, bucket, path);
+ }
+
+ @DeleteMapping("/delete")
+ public void delete(@RequestParam("path") String path) throws Exception {
+ minioClient.removeObject(RemoveObjectArgs.builder()
+ .bucket(bucket) // 存储桶
+ .object(path) // 文件名
+ .build());
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 979689f3b..53ada183d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,7 @@
- lab-12-mybatis
+
@@ -31,7 +31,7 @@
- lab-24
+
@@ -78,6 +78,7 @@
+
@@ -111,7 +112,7 @@
- lab-71-http-debug
+ lab-72-minio
From 8f8952ff8c373628036cdf9a6f7fa5a33d200271 Mon Sep 17 00:00:00 2001
From: YunaiV
Date: Sat, 19 Mar 2022 12:44:30 +0800
Subject: [PATCH 10/11] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20MinIO=20=E7=A4=BA?=
=?UTF-8?q?=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 4 ++++
.../lab72/config/MinIOConfiguration.java | 11 +----------
.../lab72/controller/FileController.java | 14 +++++++-------
... MinIO \345\205\245\351\227\250\343\200\213.md" | 1 +
4 files changed, 13 insertions(+), 17 deletions(-)
create mode 100644 "lab-72-minio/\343\200\212\350\212\213\351\201\223 Spring Boot \345\257\271\350\261\241\345\255\230\345\202\250 MinIO \345\205\245\351\227\250\343\200\213.md"
diff --git a/README.md b/README.md
index a4f74eb9c..379c0e3d8 100644
--- a/README.md
+++ b/README.md
@@ -80,6 +80,10 @@
* 《芋道 Spring Boot RSocket 入门》计划中...
* 《芋道 Spring Boot Tars 入门》计划中...
+## 文件存储
+
+* [《芋道 Spring Boot 对象存储 MinIO 入门》](https://www.iocoder.cn/Spring-Boot/MinIO/?github) 对应 [lab-72-minio](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-72-minio)
+
## 数据访问
**关系数据库**
diff --git a/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/config/MinIOConfiguration.java b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/config/MinIOConfiguration.java
index a67f767f7..3efe05c1d 100644
--- a/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/config/MinIOConfiguration.java
+++ b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/config/MinIOConfiguration.java
@@ -1,16 +1,7 @@
package cn.iocoder.springboot.lab72.config;
-import io.minio.BucketExistsArgs;
-import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
-import io.minio.SetBucketPolicyArgs;
-import io.minio.errors.*;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-import java.io.IOException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
+import org.springframework.context.annotation.*;
@Configuration
public class MinIOConfiguration {
diff --git a/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/controller/FileController.java b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/controller/FileController.java
index 1c4461ae8..3e1b3e630 100644
--- a/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/controller/FileController.java
+++ b/lab-72-minio/src/main/java/cn/iocoder/springboot/lab72/controller/FileController.java
@@ -1,16 +1,10 @@
package cn.iocoder.springboot.lab72.controller;
-import io.minio.MinioClient;
-import io.minio.PutObjectArgs;
-import io.minio.RemoveObjectArgs;
-import io.minio.errors.*;
+import io.minio.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
-import java.io.IOException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
import java.util.UUID;
@RestController
@@ -24,6 +18,9 @@ public class FileController {
private String endpoint = "http://127.0.0.1:9000";
private String bucket = "yudaoyuanma";
+ /**
+ * 上传文件
+ */
@PostMapping("/upload")
public String upload(@RequestParam("file") MultipartFile file) throws Exception {
// 上传
@@ -38,6 +35,9 @@ public String upload(@RequestParam("file") MultipartFile file) throws Exception
return String.format("%s/%s/%s", endpoint, bucket, path);
}
+ /**
+ * 删除文件
+ */
@DeleteMapping("/delete")
public void delete(@RequestParam("path") String path) throws Exception {
minioClient.removeObject(RemoveObjectArgs.builder()
diff --git "a/lab-72-minio/\343\200\212\350\212\213\351\201\223 Spring Boot \345\257\271\350\261\241\345\255\230\345\202\250 MinIO \345\205\245\351\227\250\343\200\213.md" "b/lab-72-minio/\343\200\212\350\212\213\351\201\223 Spring Boot \345\257\271\350\261\241\345\255\230\345\202\250 MinIO \345\205\245\351\227\250\343\200\213.md"
new file mode 100644
index 000000000..5047d9820
--- /dev/null
+++ "b/lab-72-minio/\343\200\212\350\212\213\351\201\223 Spring Boot \345\257\271\350\261\241\345\255\230\345\202\250 MinIO \345\205\245\351\227\250\343\200\213.md"
@@ -0,0 +1 @@
+
From 7b64abf015db7dca071f328d16263c9de5ef2070 Mon Sep 17 00:00:00 2001
From: HelloiChen
Date: Sat, 26 Mar 2022 23:49:23 +0800
Subject: [PATCH 11/11] Update org.apache.dubbo.rpc.Filter
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
dubbo SPI 文件 内容错误,导致加载不到SPI类
---
.../main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/labx-07-spring-cloud-alibaba-dubbo/labx-07-sca-dubbo-demo04-filter/labx-07-sca-dubbo-demo04-provider/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/labx-07-spring-cloud-alibaba-dubbo/labx-07-sca-dubbo-demo04-filter/labx-07-sca-dubbo-demo04-provider/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
index cac783d5a..b27766c67 100644
--- a/labx-07-spring-cloud-alibaba-dubbo/labx-07-sca-dubbo-demo04-filter/labx-07-sca-dubbo-demo04-provider/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
+++ b/labx-07-spring-cloud-alibaba-dubbo/labx-07-sca-dubbo-demo04-filter/labx-07-sca-dubbo-demo04-provider/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
@@ -1 +1 @@
-dubboExceptionFilter=cn.iocoder.springcloudalibaba.labx7.providerdemo.filter
+dubboExceptionFilter=cn.iocoder.springcloudalibaba.labx7.providerdemo.filter.DubboExceptionFilter