From 31866ac9c205e7a6d47eccebeda860f619eb486a Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Mon, 29 Jun 2020 19:24:34 +0800 Subject: [PATCH 01/29] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=92=8C=20Spring=20Bo?= =?UTF-8?q?ot=20Labs=20=E6=97=A0=E5=85=B3=E7=9A=84=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 - lab-08/pom.xml | 47 ------ .../labs/lab08/UserApplication.java | 13 -- .../springboot/labs/lab08/UserController.java | 27 --- lab-08/src/main/resources/application.yaml | 22 --- ...7\206\345\244\207\345\210\240\351\231\244" | 0 lab-09/pom.xml | 19 --- .../labs/lab09/graph/DijkstraTest.java | 71 -------- .../springboot/labs/lab09/graph/Graph.java | 146 ---------------- .../labs/lab09/leetcode/no0035/Main.java | 10 -- .../lab09/leetcode/no0035/Solution01.java | 76 --------- .../lab09/leetcode/no0035/Solution02.java | 84 ---------- .../lab09/leetcode/no0036/Solution01.java | 76 --------- .../lab09/leetcode/no0036/Solution02.java | 64 ------- .../labs/lab09/leetcode/no0072/Solution.java | 47 ------ .../lab09/leetcode/no0120/Solution01.java | 69 -------- .../lab09/leetcode/no0120/Solution02.java | 43 ----- .../labs/lab09/leetcode/no0123/Solution.java | 68 -------- .../labs/lab09/leetcode/no0146/LRUCache.java | 30 ---- .../lab09/leetcode/no0146/LRUCache02.java | 147 ----------------- .../lab09/leetcode/no0152/Solution01.java | 68 -------- .../lab09/leetcode/no0152/Solution02.java | 57 ------- .../lab09/leetcode/no0152/Solution03.java | 44 ----- .../labs/lab09/leetcode/no0208/Trie.java | 105 ------------ .../lab09/leetcode/no0231/Solution01.java | 39 ----- .../lab09/leetcode/no0235/Solution01.java | 50 ------ .../lab09/leetcode/no0235/Solution02.java | 21 --- .../lab09/leetcode/no0235/Solution03.java | 22 --- .../labs/lab09/leetcode/no0235/TreeNode.java | 11 -- .../lab09/leetcode/no0300/Solution01.java | 36 ---- .../lab09/leetcode/no0300/Solution02.java | 81 --------- .../lab09/leetcode/no0703/KthLargest.java | 136 --------------- .../lab09/leetcode/no0703/KthLargest2.java | 57 ------- .../labs/lab09/leetcode/package-info.java | 4 - .../linkedlist/HuiWenLinkedListTest.java | 110 ------------ .../labs/lab09/match/RabinKarp.java | 57 ------- .../labs/lab09/search/SkipList.java | 114 ------------- .../labs/lab09/search/SkipList2.java | 156 ------------------ .../labs/lab09/search/SkipListTest.java | 42 ----- .../labs/lab09/search/SquareTest.java | 38 ----- .../labs/lab09/sort/BucketSorterTest.java | 53 ------ .../labs/lab09/sort/HeapSorterTest.java | 134 --------------- .../labs/lab09/sort/MergeSorterTest.java | 64 ------- .../labs/lab09/sort/QuickSorterTest.java | 94 ----------- .../labs/lab09/sort/RadixSorterTest.java | 77 --------- .../labs/lab09/sort/TheFirstBigKTest.java | 79 --------- .../labs/lab09/tree/MySQLBTreePlusTest.java | 67 -------- ...7\206\345\244\207\345\210\240\351\231\244" | 0 lab-10/pom.xml | 27 --- .../springboot/labs/lab10/Controller.java | 22 --- .../labs/lab10/SpringMVCApplication.java | 13 -- .../springboot/labs/lab10/TestListener.java | 15 -- .../labs/lab10/UserHealthIndicator.java | 20 --- .../ServerLifeCycleConfiguration.java | 19 --- ...erverLifeCycleConfigurationProperties.java | 8 - .../ServerLifeCycleHealthIndicator.java | 46 ------ .../lifecycle/ServerLifeCycleListener.java | 57 ------- .../lab10/lifecycle/StatusController.java | 28 ---- .../src/main/resources/application.properties | 2 - ...7\206\345\244\207\345\210\240\351\231\244" | 0 pom.xml | 3 - 61 files changed, 3143 deletions(-) delete mode 100644 lab-08/pom.xml delete mode 100644 lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserApplication.java delete mode 100644 lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserController.java delete mode 100644 lab-08/src/main/resources/application.yaml delete mode 100644 "lab-08/\345\207\206\345\244\207\345\210\240\351\231\244" delete mode 100644 lab-09/pom.xml delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/graph/DijkstraTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/graph/Graph.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Main.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Solution01.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Solution02.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0036/Solution01.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0036/Solution02.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0072/Solution.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0120/Solution01.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0120/Solution02.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0123/Solution.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0146/LRUCache.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0146/LRUCache02.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution01.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution02.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution03.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0208/Trie.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0231/Solution01.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution01.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution02.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution03.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/TreeNode.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0300/Solution01.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0300/Solution02.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0703/KthLargest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0703/KthLargest2.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/package-info.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/linkedlist/HuiWenLinkedListTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/match/RabinKarp.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipList.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipList2.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipListTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SquareTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/BucketSorterTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/HeapSorterTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/MergeSorterTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/QuickSorterTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/RadixSorterTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/TheFirstBigKTest.java delete mode 100644 lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/tree/MySQLBTreePlusTest.java delete mode 100644 "lab-09/\345\207\206\345\244\207\345\210\240\351\231\244" delete mode 100644 lab-10/pom.xml delete mode 100644 lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/Controller.java delete mode 100644 lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/SpringMVCApplication.java delete mode 100644 lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/TestListener.java delete mode 100644 lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/UserHealthIndicator.java delete mode 100644 lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleConfiguration.java delete mode 100644 lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleConfigurationProperties.java delete mode 100644 lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleHealthIndicator.java delete mode 100644 lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleListener.java delete mode 100644 lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/StatusController.java delete mode 100644 lab-10/src/main/resources/application.properties delete mode 100644 "lab-10/\345\207\206\345\244\207\345\210\240\351\231\244" diff --git a/README.md b/README.md index 59f014880..79e614ce7 100644 --- a/README.md +++ b/README.md @@ -385,18 +385,10 @@ 如下是草稿目录,未来需要整理下 -# lab-08 - -简单测试,Tomcat + Redis 提供最小接口,看看 QPS - # lab-9 记录阅读极客时间《数据结构与算法之美》的题目。 -# lab-10 - -Spring Boot 优雅关闭示例。 - # lab-50 Email 示例 diff --git a/lab-08/pom.xml b/lab-08/pom.xml deleted file mode 100644 index bc3bdcfb9..000000000 --- a/lab-08/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - org.springframework.boot - spring-boot-starter-parent - 2.1.4.RELEASE - - - 4.0.0 - - lab-08 - - - - org.springframework.boot - spring-boot-starter-web - - - - - - - - org.springframework.boot - spring-boot-starter-redis - 1.4.7.RELEASE - - - - - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserApplication.java b/lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserApplication.java deleted file mode 100644 index e8a285f94..000000000 --- a/lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.iocoder.springboot.labs.lab08; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class UserApplication { - - public static void main(String[] args) { - SpringApplication.run(UserApplication.class, args); - } - -} diff --git a/lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserController.java b/lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserController.java deleted file mode 100644 index e0e326a0c..000000000 --- a/lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserController.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.springboot.labs.lab08; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/user") -public class UserController { - - @Autowired - private StringRedisTemplate stringRedisTemplate; - - @GetMapping("/get_user_id") - public String getUserId(@RequestParam("token") String token) { - String userIdStr = stringRedisTemplate.opsForValue().get(token); - if (userIdStr != null) { -// return Integer.valueOf(userIdStr); - return userIdStr; - } - return null; - } - -} diff --git a/lab-08/src/main/resources/application.yaml b/lab-08/src/main/resources/application.yaml deleted file mode 100644 index d1491f05d..000000000 --- a/lab-08/src/main/resources/application.yaml +++ /dev/null @@ -1,22 +0,0 @@ -spring: - application: - name: user-application - # jpa - redis: - password: - database: 0 - port: 6379 - host: 127.0.0.1 - timeout: 0 - jedis: - pool: - max-wait: - max-idle: 8 - min-idle: 0 - - -# server -server: - port: 16003 - servlet: - context-path: /user-api/ diff --git "a/lab-08/\345\207\206\345\244\207\345\210\240\351\231\244" "b/lab-08/\345\207\206\345\244\207\345\210\240\351\231\244" deleted file mode 100644 index e69de29bb..000000000 diff --git a/lab-09/pom.xml b/lab-09/pom.xml deleted file mode 100644 index d941cab76..000000000 --- a/lab-09/pom.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - labs-parent - cn.iocoder.springboot.labs - 1.0-SNAPSHOT - - 4.0.0 - - lab-09 - - - 1.8 - 1.8 - - - diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/graph/DijkstraTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/graph/DijkstraTest.java deleted file mode 100644 index 030a57326..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/graph/DijkstraTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.graph; - -import java.util.LinkedList; -import java.util.List; - -public class DijkstraTest { - - public static class Graph { - - /** - * 顶点的个数 - */ - private int v; - /** - * 邻接表 - */ - private List[] adj; - - public Graph(int v) { - this.v = v; - adj = new LinkedList[v]; - for (int i = 0; i < v; i++) { - adj[i] = new LinkedList<>(); - } - } - - public void addEdge(int s, int t, int w) { - adj[s].add(new Edge(s, t, w)); - } - - } - - public static class Edge { - - /** - * 来源顶点 - */ - private int s; - /** - * 目标顶点 - */ - private int t; - /** - * 权重(距离) - */ - private int w; - - public Edge(int s, int t, int w) { - this.s = s; - this.t = t; - this.w = w; - } - - } - - public static class Vertex { - - /** - * 顶点编号 id - */ - private int id; - - /** - * 从起始顶点,到达此处的最短距离。 - */ - private int dist; - - } - - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/graph/Graph.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/graph/Graph.java deleted file mode 100644 index 57bfbf8c8..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/graph/Graph.java +++ /dev/null @@ -1,146 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.graph; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; -import java.util.concurrent.atomic.AtomicBoolean; - -public class Graph { - - /** - * 顶点的个数 - */ - private int v; - /** - * 邻接表 - */ - private List[] adj; - - public Graph(int v) { - this.v = v; - adj = new LinkedList[v]; - for (int i = 0; i < v; i++) { - adj[i] = new LinkedList<>(); - } - } - - public void addEdge(int s, int t) { - adj[s].add(t); - adj[t].add(s); - } - - public void print() { - for (int i = 0; i < v; i++) { - System.out.print(i + " :"); - System.out.println(adj[i]); - } - } - - public void bfs(int s, int t) { - if (s == t) { - throw new IllegalStateException("参数不合理"); - } - // 初始化已访问 - boolean[] visited = new boolean[v]; - visited[s] = true; - - // 当前走到的路径 - Queue queue = new LinkedList<>(); - queue.add(s); - - // 记录哪个节点走到这里。通过它,实现路径的记录 - int[] prev = new int[v]; - Arrays.fill(prev, -1); - - while (queue.size() != 0) { - int w = queue.poll(); - for (int i = 0; i < adj[w].size(); i++) { - int q = adj[w].get(i); - if (!visited[q]) { - // 记录是从 w 走到 q - prev[q] = w; - // 判断是否到达目的地 - if (q == t) { - print(prev, s, t); - return; - } - visited[q] = true; - queue.add(q); - } - } - } - } - - public void dfs(int s, int t) { - if (s == t) { - throw new IllegalStateException("参数不合理"); - } - // 创建,标记是否找到 - AtomicBoolean found = new AtomicBoolean(false); - - // 初始化已访问 - boolean[] visited = new boolean[v]; - - // 记录哪个节点走到这里。通过它,实现路径的记录 - int[] prev = new int[v]; - Arrays.fill(prev, -1); - - // dfs 遍历 - dfs(s, t, found, visited, prev); - - if (found.get()) { - print(prev, s, t); - } else { - System.out.println("未找到路径..."); - } - } - - private void dfs(int w, int t, AtomicBoolean found, boolean[] visited, int[] prev) { - // 判断是否已经找到 - if (found.get()) { - return; - } - - // 标记已完成 - visited[w] = true; - - // 判断是否到达目的地 - if (w == t) { - found.set(true); - return; - } - - // 遍历 - for (int i = 0; i < adj[w].size(); i++) { - int q = adj[w].get(i); - if (!visited[q]) { - // 记录是从 w 走到 q - prev[q] = w; - // 继续递归 - dfs(q, t, found, visited, prev); - } - } - } - - // 递归打印从 s 到 t 的点 - public void print(int[] prev, int s, int t) { - if (prev[t] != -1 && t != s) { - print(prev, s, prev[t]); - } - System.out.print(t + " "); - } - - public static void main(String[] args) { - Graph graph = new Graph(10); - graph.addEdge(1, 3); - graph.addEdge(3, 5); - graph.addEdge(5, 7); -// graph.addEdge(9, 6); -// graph.print(); -// graph.bfs(1, 7); - graph.dfs(1, 7); - - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Main.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Main.java deleted file mode 100644 index 6f552e852..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Main.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0035; - -public class Main { - - public static void main(String[] args) { -// new Solution01().solveNQueens(4); - new Solution02().solveNQueens(4); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Solution01.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Solution01.java deleted file mode 100644 index 2c801fb0e..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Solution01.java +++ /dev/null @@ -1,76 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0035; - -import java.util.ArrayList; -import java.util.List; - -class Solution01 { - - public List> solveNQueens(int n) { - if (n == 0) { - return new ArrayList<>(); - } - - // 初始化变量 - List> results = new ArrayList<>(); - int[] used = new int[n]; // 标记,指定层,使用的位置 - for (int i = 0; i < n; i++) { - used[i] = -1; - } - - // 递归 - gen(results, used, 0, n); - - // 返回结果 - return results; - } - - private void gen(List> results, int[] used, int index, int max) { - // 到达最大值,结束递归 - if (index == max) { - List result = new ArrayList<>(); - for (int i = 0; i < max; i++) { - StringBuilder str = new StringBuilder(); - for (int j = 0; j < max; j++) { - if (used[i] == j) { - str.append("Q"); - } else { - str.append("."); - } - } - result.add(str.toString()); - } - results.add(result); - return; - } - - // 递归 - for (int i = 0; i < max; i++) { // i 表示第几个位置 - boolean isOK = true; - // 判断该位置,是否可用 - for (int j = 0; j < index; j++) { - // 纵方法,判断 - if (used[j] == i) { - isOK = false; - break; - } - // 斜方法,判断 - int diff = index - j; // 判断差的层级 - if (used[j] + diff == i || used[j] - diff == i) { - isOK = false; - break; - } - } - // 如果不合法,continue - if (!isOK) { - continue; - } - // 标记已使用 - used[index] = i; - // 递归 - gen(results, used, index + 1, max); - // 标记未使用,继续循环 - used[index] = -1; - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Solution02.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Solution02.java deleted file mode 100644 index 9262c45c5..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0035/Solution02.java +++ /dev/null @@ -1,84 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0035; - -import java.util.ArrayList; -import java.util.List; - -/** - * 在 {@link Solution01} 的基础上,做一个优化 - */ -public class Solution02 { - - public List> solveNQueens(int n) { - if (n == 0) { - return new ArrayList<>(); - } - - // 初始化变量 - List> results = new ArrayList<>(); - int[] used = new int[n]; // 标记,指定层,使用的位置 - for (int i = 0; i < n; i++) { - used[i] = -1; - } - boolean[] usedCol = new boolean[n]; // 使用的列的标记 - boolean[] usedSum = new boolean[2 * n]; // x + y = c ,即“撇” 。 - boolean[] usedMinus = new boolean[2 * n]; // x - y = c ,即“捺” 。 - - - // 递归 - gen(results, used, usedCol, usedSum, usedMinus, 0, n); - - // 返回结果 - return results; - } - - private void gen(List> results, int[] used, boolean[] usedCol, boolean[] usedSum, boolean[] usedMinus, int index, int max) { - // 到达最大值,结束递归 - if (index == max) { - List result = new ArrayList<>(); - for (int i = 0; i < max; i++) { - StringBuilder str = new StringBuilder(); - for (int j = 0; j < max; j++) { - if (used[i] == j) { - str.append("Q"); - } else { - str.append("."); - } - } - result.add(str.toString()); - } - results.add(result); - return; - } - - // 递归 - for (int i = 0; i < max; i++) { // i 表示第几个位置 - boolean isOK = true; - // 判断该位置,是否可用 - if (usedCol[i]) { // 列已经使用 - continue; - } - int usedSumIndex = index + i; // “撇”已经使用 - if (usedSum[usedSumIndex]) { - continue; - } - int usedMinusIndex = max + index - i; // “捺”已经使用 - if (usedMinus[usedMinusIndex]) { - continue; - } - // 标记已使用 - used[index] = i; - usedCol[i] = true; - usedSum[usedSumIndex] = true; - usedMinus[usedMinusIndex] = true; - // 递归 - gen(results, used, usedCol, usedSum, usedMinus, index + 1, max); - // 标记未使用,继续循环 - used[index] = -1; - usedCol[i] = false; - usedSum[usedSumIndex] = false; - usedMinus[usedMinusIndex] = false; - - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0036/Solution01.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0036/Solution01.java deleted file mode 100644 index ee9e30344..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0036/Solution01.java +++ /dev/null @@ -1,76 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0036; - -public class Solution01 { - - private void reset(boolean[] flags) { - for (int i = 0; i < flags.length; i++) { - flags[i] = false; - } - } - - public boolean isValidSudoku(char[][] board) { - int n = 9; - int m = 3; - boolean[] flags = new boolean[n]; - - // 横线 - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - if (board[i][j] == '.') { - continue; - } - if (flags[board[i][j ] - '1']) { - return false; - } - flags[board[i][j ] - '1'] = true; - } - reset(flags); - } - - // 竖线 - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - if (board[j][i] == '.') { - continue; - } - if (flags[board[j][i ] - '1']) { - return false; - } - flags[board[j][i ] - '1'] = true; - } - reset(flags); - } - - // 每个方块 - for (int i = 0; i < n; i = i + m) { - for (int j = 0; j < n; j = j + m) { - for (int p = i; p < i + m; p++) { - for (int q = j; q < j + m; q++) { - if (board[p][q] == '.') { - continue; - } - if (flags[board[p][q] - '1']) { - return false; - } - flags[board[p][q] - '1'] = true; - } - } - reset(flags); - } - } - - return true; - } - - public static void main(String[] args) { - char[][] board = {{'.','.','.','.','5','.','.','1','.'},{'.','4','.','3','.','.','.','.','.'},{'.','.','.','.','.','3','.','.','1'},{'8','.','.','.','.','.','.','2','.'},{'.','.','2','.','7','.','.','.','.'},{'.','1','5','.','.','.','.','.','.'},{'.','.','.','.','.','2','.','.','.'},{'.','2','.','9','.','.','.','.','.'},{'.','.','4','.','.','.','.','.','.'}}; -// for (int i = 0; i < board.length; i++) { -// for (int j = 0; j < board[i].length; j++) { -// System.out.print(board[i][j] + "\t"); -// } -// System.out.println(); -// } - System.out.println(new Solution01().isValidSudoku(board)); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0036/Solution02.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0036/Solution02.java deleted file mode 100644 index 6d7fad1c9..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0036/Solution02.java +++ /dev/null @@ -1,64 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0036; - -public class Solution02 { - - private void reset(boolean[] flags) { - for (int i = 0; i < flags.length; i++) { - flags[i] = false; - } - } - - public boolean isValidSudoku(char[][] board) { - int n = 9; - int m = 3; -// boolean[] flags = new boolean[n]; - boolean[][] rows = new boolean[n][n]; - boolean[][] cols = new boolean[n][n]; - boolean[][] boxes = new boolean[n][n]; - - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - if (board[i][j] == '.') { - continue; - } - int number = board[i][j] - '1'; // 减 1 而不是 0 ,因为数组从 0 开始。 - // 行 - if (rows[i][number]) { - return false; - } - rows[i][number] = true; - // 列 - if (cols[j][number]) { - return false; - } - cols[j][number] = true; - // 小方格 - int boxIndex = i / m * m + j / m; - if (boxes[boxIndex][number]) { - return false; - } - boxes[boxIndex][number] = true; - } - } - - return true; - } - - public static void main(String[] args) { - if (false) { - char[][] board = {{'.', '.', '.', '.', '5', '.', '.', '1', '.'}, {'.', '4', '.', '3', '.', '.', '.', '.', '.'}, {'.', '.', '.', '.', '.', '3', '.', '.', '1'}, {'8', '.', '.', '.', '.', '.', '.', '2', '.'}, {'.', '.', '2', '.', '7', '.', '.', '.', '.'}, {'.', '1', '5', '.', '.', '.', '.', '.', '.'}, {'.', '.', '.', '.', '.', '2', '.', '.', '.'}, {'.', '2', '.', '9', '.', '.', '.', '.', '.'}, {'.', '.', '4', '.', '.', '.', '.', '.', '.'}}; -// for (int i = 0; i < board.length; i++) { -// for (int j = 0; j < board[i].length; j++) { -// System.out.print(board[i][j] + "\t"); -// } -// System.out.println(); -// } - System.out.println(new Solution02().isValidSudoku(board)); - } - if (true) { - char[][] board = {{'5','3','.','.','7','.','.','.','.'},{'6','.','.','1','9','5','.','.','.'},{'.','9','8','.','.','.','.','6','.'},{'8','.','.','.','6','.','.','.','3'},{'4','.','.','8','.','3','.','.','1'},{'7','.','.','.','2','.','.','.','6'},{'.','6','.','.','.','.','2','8','.'},{'.','.','.','4','1','9','.','.','5'},{'.','.','.','.','8','.','.','7','9'}}; - System.out.println(new Solution02().isValidSudoku(board)); - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0072/Solution.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0072/Solution.java deleted file mode 100644 index 4939ad34d..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0072/Solution.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0072; - -public class Solution { - - public int minDistance(String word1, String word2) { - // + 1 的原始是, - // 1. 字符串的长度可以是 0 。例如说,word1 为 abc ,word2 为空串。 - // 2. 而数组的下标,代表的是第几个字符串。 - // 所以需要 + 1 。 - int[][] dp = new int[word1.length() + 1][word2.length() + 1]; - - // 初始化 - for (int i = 0; i <= word1.length(); i++) { // i 变成 words2 0 的位置,就是意味着 words2 是空串,则需要不断删除 - dp[i][0] = i; - } - for (int j = 0; j <= word2.length(); j++) { // words[0] 变成 words2 j 的位置,就是意味着,需要不断添加。 - dp[0][j] = j; - } - - // dp - for (int i = 1; i <= word1.length(); i++) { - for (int j = 1; j <= word2.length(); j++) { - if (word1.charAt(i - 1) == word2.charAt(j - 1)) { // -1 的原因,正如上面所说 + 1 的原因,dp 的下标,对应 word 的下标 - 1 。 - dp[i][j] = dp[i - 1][j - 1]; - } else { - dp[i][j] = this.min( - dp[i - 1][j] + 1, // 删除 a[i] - dp[i][j - 1] + 1, // 插入 b[j] - dp[i - 1][j - 1] + 1 // 替换 a[i] 到 b[j] - ); - } - } - } - - return dp[word1.length()][word2.length()]; - } - - private int min(int a, int b, int c) { - return Math.min(Math.min(a, b), c); - } - - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.minDistance("horse", "ros")); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0120/Solution01.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0120/Solution01.java deleted file mode 100644 index 5f283097f..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0120/Solution01.java +++ /dev/null @@ -1,69 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0120; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * 自上而下,进行 DP - */ -public class Solution01 { - - public int minimumTotal(List> triangle) { - if (triangle == null || triangle.isEmpty()) { - return 0; - } - // 只有一层,就不要求解了 - if (triangle.size() == 1) { - return triangle.get(0).get(0); - } - - // 通过 ways ,记录最大路径 - int size = triangle.size(); - int[] ways = new int[triangle.get(size - 1).size()]; - Arrays.fill(ways, Integer.MAX_VALUE); - // 计算下一层的时候,临时使用 - int[] tmps = new int[ways.length]; - // 用于在最后一层,计算 ways 中的最小值。 - int min = Integer.MAX_VALUE; - - // 开始动态规划 - ways[0] = triangle.get(0).get(0); - tmps[0] = triangle.get(0).get(0); - for (int i = 1; i < size; i++) { - int levelSize = triangle.get(i).size(); - for (int j = 0; j < levelSize; j++) { - // 选取能到达当前节点的较小值 - int result; - if (j == 0) { - result = ways[j]; - } else if (j == levelSize - 1) { - result = ways[j - 1]; - } else { - result = Math.min(ways[j], ways[j - 1]); - } - // 记录当前节点需要的最小路径,到 tmps 中。 - tmps[j] = result + triangle.get(i).get(j); - // 如果是最后一层,开始计算最小值。 - if (i == size - 1) { - if (tmps[j] < min) { - min = tmps[j]; - } - } - } - System.arraycopy(tmps, 0, ways, 0, levelSize); - } - - return min; - } - - public static void main(String[] args) { - List> triangle = new ArrayList<>(); - triangle.add(Arrays.asList(2)); - triangle.add(Arrays.asList(3, 4)); - triangle.add(Arrays.asList(6, 5, 7)); - triangle.add(Arrays.asList(4, 1, 8, 3)); - System.out.println(new Solution01().minimumTotal(triangle)); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0120/Solution02.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0120/Solution02.java deleted file mode 100644 index c24a80092..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0120/Solution02.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0120; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * 自下而上,进行 DP - */ -public class Solution02 { - - public int minimumTotal(List> triangle) { - if (triangle == null || triangle.isEmpty()) { - return 0; - } - - // 通过 ways ,记录最大路径 - int size = triangle.size(); - int[] ways = new int[triangle.get(size - 1).size()]; - for (int j = 0; j < triangle.get(size - 1).size(); j++) { - ways[j] = triangle.get(size - 1).get(j); - } - - // 自下而上 DP - for (int i = size - 2; i >= 0; i--) { - for (int j = 0; j < triangle.get(i).size(); j++) { - ways[j] = Math.min(ways[j], ways[j + 1]) + triangle.get(i).get(j); - } - } - - return ways[0]; - } - - public static void main(String[] args) { - List> triangle = new ArrayList<>(); - triangle.add(Arrays.asList(2)); - triangle.add(Arrays.asList(3, 4)); - triangle.add(Arrays.asList(6, 5, 7)); - triangle.add(Arrays.asList(4, 1, 8, 3)); - System.out.println(new Solution02().minimumTotal(triangle)); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0123/Solution.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0123/Solution.java deleted file mode 100644 index d29768687..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0123/Solution.java +++ /dev/null @@ -1,68 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0123; - -public class Solution { - - public int maxProfit(int[] prices) { - if (prices == null || prices.length == 0) { - return 0; - } - int k = 2; // 最大交易次数,只能两次 - // 第一维度 k ,表示当前【买入股票】的次数; - // 第二维度 2 ,表示 0 - 未持有,1 - 持有 1 股 - // 值为最大利润 - int[][] dp = new int[k + 1][2]; - // 初始化第一个股票的处理 - dp[1][1] = -prices[0]; // 买入 - dp[2][1] = -prices[0]; // 买入 + 卖出 + 买入 - dp[0][1] = Integer.MIN_VALUE; // 相当于赋值为空,避免直接认为持有一股时,利润为 0 。 - - // 遍历,进行买卖 - for (int i = 1; i < prices.length; i++) { - for (int j = 0; j <= k; j++) { - // 尝试卖出 - dp[j][0] = Math.max(dp[j][0], dp[j][1] + prices[i]); - // 尝试买入 - if (j > 0) { - dp[j][1] = Math.max(dp[j][1], dp[j - 1][0] - prices[i]); - } - } - } - - return Math.max(dp[1][0], dp[2][0]); - } - -// public int maxProfit(int[] prices) { -// if (prices == null || prices.length == 0) { -// return 0; -// } -// int k = 2; // 最大交易次数,只能两次 -// // 第一维度 k ,表示当前【买入股票】的次数; -// // 第二维度 2 ,表示 0 - 未持有,1 - 持有 1 股 -// int[][][] dp = new int[prices.length][k + 1][2]; -// // 初始化第一个股票的处理 -// dp[0][1][1] = -prices[0]; // 买入 -//// dp[2][1] = -prices[0]; // 买入 + 卖出 + 买入 -// -// // 遍历,进行买卖 -// for (int i = 1; i < prices.length; i++) { -// for (int j = 0; j <= k; j++) { -// // 尝试卖出 -// dp[i][j][0] = Math.max(dp[i][j][0], dp[i][j][1] + prices[i]); -// // 尝试买入 -// if (j > 0) { -// dp[i][j][1] = Math.max(dp[i][j][1], dp[i][j - 1][0] - prices[i]); -// } -// } -// } -// -// return Math.max(dp[prices.length -1][1][0], dp[prices.length - 1][2][0]); -// } - - public static void main(String[] args) { - Solution solution = new Solution(); - System.out.println(solution.maxProfit(new int[]{3,3,5,0,0,3,1,4})); - System.out.println(solution.maxProfit(new int[]{1,2,3,4,5})); - System.out.println(solution.maxProfit(new int[]{7, 6, 4, 3, 1})); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0146/LRUCache.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0146/LRUCache.java deleted file mode 100644 index cb8f54d4e..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0146/LRUCache.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0146; - -import java.util.LinkedHashMap; -import java.util.Map; - -public class LRUCache { - - private Map cache; - - public LRUCache(int capacity) { - this.cache = new LinkedHashMap((int) Math.ceil(capacity / 0.75f) + 1, 0.75f, true) { - - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > capacity; - } - - }; - } - - public int get(int key) { - Integer val = cache.get(key); - return val != null ? val : -1; - } - - public void put(int key, int value) { - cache.put(key, value); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0146/LRUCache02.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0146/LRUCache02.java deleted file mode 100644 index 6bf72313b..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0146/LRUCache02.java +++ /dev/null @@ -1,147 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0146; - -import java.util.HashMap; -import java.util.Map; - -public class LRUCache02 { - - private class Node { - - private int key; - private int value; - private Node prev; - private Node next; - - public Node(int key, int value, Node prev, Node next) { - this.key = key; - this.value = value; - this.prev = prev; - this.next = next; - } - - } - - /** - * 容量 - */ - private int capacity; - /** - * 缓存 - */ - private Map cache; - /** - * 指向头 - */ - private Node head; - /** - * 指向尾. - * - * 最新的元素,放在尾部 - */ - private Node tail; - - public LRUCache02(int capacity) { - this.capacity = capacity; - this.cache = new HashMap<>(capacity, 1F); - } - - public int get(int key) { - Node node = this.getNode(key); - return node != null ? node.value : -1; - } - - public void put(int key, int value) { - Node node = getNode(key); - - // 获得到值,设置其值 - if (node != null) { - node.value = value; - return; - } - - // 移除最老访问的 - removeIfFull(); - - // 容量足够 - node = new Node(key, value, tail, null); - cache.put(key, node); - // 设置新的尾节点 - if (head == null) { - head = tail = node; - } else { - tail.next = node; - tail = node; - } - } - - private Node getNode(int key) { - // head 为空,说明无元素 - if (head == null) { - return null; - } - - // 获得元素 - Node node = cache.get(key); - if (node == null) { // 如果获得不到,返回空 - return null; - } - - // 如果尾部并未指向 node ,则重新指向 - if (node != tail) { - if (node == head) { - head = head.next; - head.prev = null; - } else { - node.next.prev = node.prev; - node.prev.next = node.next; - } - - // 添加到尾部 - node.prev = tail; - tail.next = node; - node.next = null; - tail = node; - } - - return node; - } - - private void removeIfFull() { - if (cache.size() < capacity) { - return; - } - - // 移除 cache - cache.remove(head.key); - // 更新新的 head - head = head.next; - if (head != null) { // 主要为了处理 capacity 为 1 的情况 - head.prev = null; - } - } - - public static void main(String[] args) { - if (false) { - LRUCache02 cache = new LRUCache02(2 /* 缓存容量 */); - - cache.put(1, 1); - cache.put(2, 2); - System.out.println(cache.get(1)); // 返回 1 - cache.put(3, 3); // 该操作会使得密钥 2 作废 - System.out.println(cache.get(2)); // 返回 -1 (未找到) - cache.put(4, 4); // 该操作会使得密钥 1 作废 - System.out.println(cache.get(1)); // 返回 -1 (未找到) - System.out.println(cache.get(3)); // 返回 3 - System.out.println(cache.get(4)); // 返回 4 - } - if (true) { - LRUCache02 cache = new LRUCache02(1 /* 缓存容量 */); - cache.put(2, 1); - System.out.println(cache.get(2)); // 返回 1 - cache.put(3, 2); - System.out.println(cache.get(2)); // 返回 - System.out.println(cache.get(3)); // 返回 - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution01.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution01.java deleted file mode 100644 index b957bdd68..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution01.java +++ /dev/null @@ -1,68 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0152; - -@Deprecated // 解法不对 -public class Solution01 { - - public int maxProduct(int[] nums) { - Integer max = Integer.MIN_VALUE; // 最大值 - Integer x = null; // 正数 - Integer y = null; // 负数 - - // 遍历 - for (int num : nums) { - if (num >= 0) { // 正数 - if (x == null) { - x = num; - } else { - if (num * x > x) { - x = num * x; - } else { - x = num; - } - } - if (y != null) { - if (num == 0) { - y = null; - } else { - y = y * num; - } - } - } else { // 负数 - if (y == null) { - if (x == null) { - y = num; - } else { - y = num * x; - x = null; - } - } else { - y = num * y; - if (y > 0) { - x = y; - y = num; - } - } - } - // 判断是否超过 - if (x != null && x > max) { - max = x; - } - if (y != null && y > max) { // 处理,整个数组只有一个负数的情况。 - max = y; - } - } - - return max; - } - - public static void main(String[] args) { - Solution01 solution = new Solution01(); -// System.out.println(solution.maxProduct(new int[]{2, 3, -2, -4})); -// System.out.println(solution.maxProduct(new int[]{2, 3, -2, 4})); -// System.out.println(solution.maxProduct(new int[]{-2, 0, 1})); -// System.out.println(solution.maxProduct(new int[]{0, 2})); -// System.out.println(solution.maxProduct(new int[]{2, -5, -2, -4, 3})); - System.out.println(solution.maxProduct(new int[]{-1, -2, -9, -6})); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution02.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution02.java deleted file mode 100644 index 08366ca49..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution02.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0152; - -/** - * dp 方程 - * - * dp1[i] = max(dp[i - 1] * nums[i], dp2[i -1] * nums[i], nums[i]) - * dp2[i] = min(dp[i - 1] * nums[i], dp2[i -1] * nums[i], nums[i]) - * - * 通过不断求,使用上当前数值时,能产生的最大值。 - * - * 注意,结果不是 dp1[n - 1] ,而是在这个过程中,产生的最大值。因为 nums 有负数的可能性,导致不一定使用上当前值,就一定是最大值。 - */ -public class Solution02 { - - public int maxProduct(int[] nums) { - // 最大值 - int max = nums[0]; - // 使用上当前位置的数,最大值。max 和 dp1 并不等价,因为使用上当前数字后,可能不一定大于 max - int[] dp1 = new int[nums.length]; - dp1[0] = nums[0]; - // 使用上当前位置的数,最小值。使用最小值的原因是,可以有机会负负得正 - int[] dp2 = new int[nums.length]; - dp2[0] = nums[0]; - - // 开始 dp - for (int i = 1; i < nums.length; i++) { - int num = nums[i]; - dp1[i] = max(dp1[i - 1] * num, // 如果 num 是正数的情况下,乘以 dp1,会变大 - dp2[i - 1] * num, // 如果 num 是负数的情况,乘以 dp2 ,可能反倒比 dp1 大。 - num); // 可能上面两个,乘了半天,还不如 - dp2[i] = min(dp1[i - 1] * num, dp2[i - 1] * num, num); // 同上面的想法 - // 求最大值 - max = Math.max(dp1[i], max); - } - - return max; - } - - private int min(int a, int b, int c) { - return Math.min(Math.min(a, b), c); - } - - private int max(int a, int b, int c) { - return Math.max(Math.max(a, b), c); - } - - public static void main(String[] args) { - Solution02 solution = new Solution02(); - System.out.println(solution.maxProduct(new int[]{2, 3, -2, -4})); - System.out.println(solution.maxProduct(new int[]{2, 3, -2, 4})); - System.out.println(solution.maxProduct(new int[]{-2, 0, 1})); - System.out.println(solution.maxProduct(new int[]{0, 2})); - System.out.println(solution.maxProduct(new int[]{2, -5, -2, -4, 3})); - System.out.println(solution.maxProduct(new int[]{-1, -2, -9, -6})); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution03.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution03.java deleted file mode 100644 index 8d898c7a3..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0152/Solution03.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0152; - -/** - * {@link Solution02} 的改进,不使用两个一维数组,而是直接使用两个变量。 - */ -public class Solution03 { - - public int maxProduct(int[] nums) { - // 最大值 - int max = nums[0]; - // 使用上当前位置的数,最大值。max 和 dp1 并不等价,因为使用上当前数字后,可能不一定大于 max - int dp1 = nums[0]; - // 使用上当前位置的数,最小值。使用最小值的原因是,可以有机会负负得正 - int dp2 = nums[0]; - - // 开始 dp - for (int i = 1; i < nums.length; i++) { - int num = nums[i]; - int[] results = minAndMax(dp1 * num, dp2* num, num); - dp1 = results[1]; - dp2 = results[0]; - // 求最大值 - max = Math.max(dp1, max); - } - - return max; - } - - private int[] minAndMax(int a, int b, int c) { - return new int[]{Math.min(Math.min(a, b), c), - Math.max(Math.max(a, b), c)}; - } - - public static void main(String[] args) { - Solution03 solution = new Solution03(); - System.out.println(solution.maxProduct(new int[]{2, 3, -2, -4})); - System.out.println(solution.maxProduct(new int[]{2, 3, -2, 4})); - System.out.println(solution.maxProduct(new int[]{-2, 0, 1})); - System.out.println(solution.maxProduct(new int[]{0, 2})); - System.out.println(solution.maxProduct(new int[]{2, -5, -2, -4, 3})); - System.out.println(solution.maxProduct(new int[]{-1, -2, -9, -6})); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0208/Trie.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0208/Trie.java deleted file mode 100644 index e30aa7e1e..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0208/Trie.java +++ /dev/null @@ -1,105 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0208; - -public class Trie { - - public class Node { - - private Node[] children; - private boolean end; - - public Node() { - children = new Node['z' - 'a' + 1]; - } - - } - - private Node node; - - /** Initialize your data structure here. */ - public Trie() { - node = new Node(); - } - - /** Inserts a word into the trie. */ - public void insert(String word) { - if (word == null || word.length() == 0) { - return; - } - - // 遍历,创建节点 - Node current = node; - for (int i = 0; i < word.length(); i++) { - int index = getIndex(word.charAt(i)); - Node next = current.children[index]; - if (next == null) { - next = new Node(); - current.children[index] = next; - } - current = next; - } - - // 标记结束 - current.end = true; - } - - /** Returns if the word is in the trie. */ - public boolean search(String word) { - if (word == null || word.length() == 0) { - return false; - } - - // 遍历,寻找节点 - Node current = node; - for (int i = 0; i < word.length(); i++) { - int index = getIndex(word.charAt(i)); - Node next = current.children[index]; - if (next == null) { - return false; - } - current = next; - } - - // 判断找到的节点,是否为根节点 - return current.end; - } - - /** Returns if there is any word in the trie that starts with the given prefix. */ - public boolean startsWith(String prefix) { - if (prefix == null || prefix.length() == 0) { - return false; - } - - // 遍历,寻找节点 - Node current = node; - for (int i = 0; i < prefix.length(); i++) { - int index = getIndex(prefix.charAt(i)); - Node next = current.children[index]; - if (next == null) { - return false; - } - current = next; - } - - // 结果找到 - return true; - } - - private int getIndex(char ch) { - return ch - 'a'; - } - - public static void main(String[] args) { - Trie trie = new Trie(); - - trie.insert("apple"); - System.out.println(trie.search("apple")); // 返回 true - System.out.println(trie.search("app")); // 返回 false - System.out.println(trie.startsWith("app")); // 返回 true - - trie.insert("app"); - System.out.println(trie.search("app")); // 返回 true - - System.out.println(trie.search("appled")); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0231/Solution01.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0231/Solution01.java deleted file mode 100644 index 781f9d67a..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0231/Solution01.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0231; - -public class Solution01 { - - public boolean isPowerOfTwo(int n) { - // 非正整数,非正整数 - if (n <= 0) { - return false; - } - - int mask = 1; - for (int i = 0; i < 32; i++) { - // 或运算,如果就是自己,说明是 2 的 n 次方 - if ((n | mask) == mask) { - return true; - } - - // mask 超过范围,说明就是不符合 - if (mask > n) { - return false; - } - - mask = mask << 1; - } - - return false; - } - - public static void main(String[] args) { - Solution01 solution = new Solution01(); - System.out.println(solution.isPowerOfTwo(1)); - System.out.println(solution.isPowerOfTwo(2)); - System.out.println(solution.isPowerOfTwo(3)); - System.out.println(solution.isPowerOfTwo(4)); - System.out.println(solution.isPowerOfTwo(5)); - System.out.println(solution.isPowerOfTwo(6)); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution01.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution01.java deleted file mode 100644 index aeb039427..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution01.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0235; - -import java.util.ArrayList; -import java.util.List; - -/** - * 寻找路径,然后匹配 - */ -public class Solution01 { - - public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { - // p 节点的路径 - List pNodes = new ArrayList<>(); - binarySearch(root, p, pNodes); - // q 节点的路径 - List qNodes = new ArrayList<>(); - binarySearch(root, q, qNodes); - - // 倒序,对比 - for (int i = pNodes.size() - 1; i >= 0; i--) { - TreeNode node = pNodes.get(i); - for (int j = qNodes.size() - 1; j >= 0; j--) { - TreeNode node2 = qNodes.get(j); - if (node.val == node2.val) { - return node; - } - } - } - return null; - } - - private void binarySearch(TreeNode root, TreeNode target, List nodes) { - if (root == null) { // 理论不存在,防御性 - return; - } - - // 添加到路径 - nodes.add(root); - - if (root.val == target.val) { - return; - } - if (root.val > target.val) { - binarySearch(root.left, target, nodes); - } else { - binarySearch(root.right, target, nodes); - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution02.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution02.java deleted file mode 100644 index 6db99c502..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution02.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0235; - -/** - * 递归求解父节点 - */ -public class Solution02 { - - public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { - if (p.val < root.val - && root.val > q.val) { // 因为 root.val 大于 q.val ,说明 root 的值过大,需要往左走 - return lowestCommonAncestor(root.left, p, q); - } else if (p.val > root.val // 因为 root.val 小于 p.val ,说明 root 的值过小,需要往右走 - && root.val < q.val) { - return lowestCommonAncestor(root.right, p, q); - } else { // 其他情况,root 都是符合条件的,例如说 root 的泛微在 p and q 之间(或者 q and p 之间)。 - // 为什么直接返回 root 就可以,因为如果不是最接近的父节点,p 和 q 要么在其左边,要么在其右边。 - return root; - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution03.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution03.java deleted file mode 100644 index 38326d63c..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/Solution03.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0235; - -/** - * {@link Solution02} 的改进,非递归方式。 - */ -public class Solution03 { - - public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { - while (true) { - if (p.val < root.val - && root.val > q.val) { // 因为 root.val 大于 q.val ,说明 root 的值过大,需要往左走 - root = root.left; - } else if (p.val > root.val // 因为 root.val 小于 p.val ,说明 root 的值过小,需要往右走 - && root.val < q.val) { - root = root.right; - } else { // 其他情况,root 都是符合条件的,例如说 root 的泛微在 p and q 之间(或者 q and p 之间)。 - return root; - } - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/TreeNode.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/TreeNode.java deleted file mode 100644 index 2f5137911..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0235/TreeNode.java +++ /dev/null @@ -1,11 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0235; - -public class TreeNode { - - int val; - TreeNode left; - TreeNode right; - - TreeNode(int x) { val = x; } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0300/Solution01.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0300/Solution01.java deleted file mode 100644 index c2d6d3136..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0300/Solution01.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0300; - -import java.util.Arrays; - -/** - * DP 实现,时间复杂度为 O(N^2) 。 - * - * DP 转换方程是: - * dp[i] = MAX(dp[i], dp[j] + 1) - * 其中,dp[i] 表示,截止目前,最大的上升的子序列 - */ -public class Solution01 { - - public int lengthOfLIS(int[] nums) { - if (nums.length == 0) { - return 0; - } - - int[] dps = new int[nums.length]; - Arrays.fill(dps, 1); // 都赋值为 1 先,因为自己是自己的递增。 - int result = 1; - - // dp - for (int i = 1; i < nums.length; i++) { - for (int j = 0; j < i; j++) { - if (nums[i] > nums[j]) { - dps[i] = Math.max(dps[i], dps[j] + 1); - } - } - result = Math.max(result, dps[i]); - } - - return result; - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0300/Solution02.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0300/Solution02.java deleted file mode 100644 index f89d3d2bb..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0300/Solution02.java +++ /dev/null @@ -1,81 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0300; - -import java.util.ArrayList; -import java.util.List; - -/** - * 二分 + 贪心 - */ -public class Solution02 { - - public int lengthOfLIS(int[] nums) { - if (nums.length == 0) { - return 0; - } - - List lis = new ArrayList<>(); // 上升序列 - for (int num : nums) { - int position = binarySearch(lis, num); - if (position >= lis.size()) { - lis.add(num); - } else { - lis.set(position, num); - } - } - - - return lis.size(); - } - - /** - * 获得比 num 第一大的值的位置 - * 如果有和 num 相等的,也返回 - * - * TODO 芋艿,后续,可以使用 Arrays.binarySearch() 简化。 - * - * @param lis - * @param num - * @return - */ - private int binarySearch(List lis, int num) { - int high = lis.size() - 1; - - // 判断,是否超过 - if (high < 0 || lis.get(high) < num) { - return lis.size(); - } - if (num < lis.get(0)) { - return 0; - } - - // 二分查找 - int low = 0; - while (low <= high) { - int mid = low + ((high - low) >> 1); - if (lis.get(mid) == num) { - return mid; - } else if (num < lis.get(mid)) { - if (lis.get(mid - 1) > num) { - return mid; - } else { - high = mid - 1; - } - } else { - if (lis.get(mid + 1) > num) { - return mid + 1; - } else { - low = mid + 1; - } - } - } - - throw new IllegalArgumentException("不可能出现"); - } - - public static void main(String[] args) { - Solution02 solution = new Solution02(); -// System.out.println(solution.lengthOfLIS(new int[]{10,9,2,5,3,7,101,18})); - System.out.println(solution.lengthOfLIS(new int[]{7,8,9,10,1,2,3,4,5,5})); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0703/KthLargest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0703/KthLargest.java deleted file mode 100644 index 15e1e93e6..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0703/KthLargest.java +++ /dev/null @@ -1,136 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0703; - -class KthLargest { - - /** - * 小顶堆 - */ - private int[] heap; - /** - * 堆的位置 - */ - private int heapIndex; - private int k; - - public KthLargest(int k, int[] nums) { - this.heap = new int[k + 1]; - this.heapIndex = 1; - this.k = k; - // 初始化 - for (int num : nums) { - add(num); - } - } - - public int add(int val) { - if (heapIndex <= k) { - // 赋值 - heap[heapIndex] = val; - heapIndex++; - - // 向上堆化 - heapifyUp(heapIndex - 1); - } else { - if (val > heap[1]) { // 大于最小值,才有资格加入其中。因为我们构建的 heap 是小顶堆,最上面存储的是第 k 大。 - // 赋值 - heap[1] = val; - - heapifyDown(1); - } - } - - return heap[1]; - } - -// private int remove0() { -// // 取头元素 -// int val = heap[1]; -// -// // 将尾巴设置到头 -// heap[1] = heap[heapIndex - 1]; -// heapIndex--; -// -// // 向下堆化 -// heapifyDown(1); -// -// return val; -// } - - public void heapifyUp(int index) { - while (index > 1) { // 注意,此处要大于 1 - int parent = index / 2; - if (heap[index] < heap[parent]) { - swap(index, parent); - index = parent; - } else { - break; - } - } - } - - private void heapifyDown(int index) { - while (true) { - int pos = index; - // 求子节点中,哪个 - if (index * 2 < heapIndex && heap[index * 2] < heap[index]) { - pos = index * 2; - } - if (index * 2 + 1 < heapIndex && heap[index * 2 + 1] < heap[pos]) { - pos = index * 2 + 1; - } - // 如果毫无变化,说明已经不需要继续向下 - if (pos == index) { - return; - } - // 交换 - swap(index, pos); - index = pos; - } - } - - private void swap(int i, int j) { - int tmp = heap[i]; - heap[i] = heap[j]; - heap[j] = tmp; - } - -// private int findMaxValueIndex() { -// int max = Integer.MIN_VALUE; -// int maxIndex = -1; -// for (int i = log2(heapIndex) * 2; i < heapIndex; i++) { // 从 log2(heapIndex) * 2 的原因是,从叶子节点开始。因为我们构建的是小顶堆,那么最大值必定在叶子节点上。 -// if (heap[i] > max) { -// max = heap[i]; -// maxIndex = i; -// } -// } -// return maxIndex; -// } -// -// private static int log2(int x) { -// return (int) (Math.log(x) / Math.log(2)); -// } - - public static void main(String[] args) { - if (false) { - int k = 3; - int[] nums = {4, 5, 8, 2}; - KthLargest kthLargest = new KthLargest(k, nums); - System.out.println(kthLargest.add(3)); - System.out.println(kthLargest.add(5)); - System.out.println(kthLargest.add(10)); - System.out.println(kthLargest.add(9)); - System.out.println(kthLargest.add(4)); - } - if (true) { - int k = 1; - int[] nums = {}; - KthLargest kthLargest = new KthLargest(k, nums); - System.out.println(kthLargest.add(-3)); - System.out.println(kthLargest.add(-2)); - System.out.println(kthLargest.add(-4)); - System.out.println(kthLargest.add(0)); - System.out.println(kthLargest.add(4)); - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0703/KthLargest2.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0703/KthLargest2.java deleted file mode 100644 index e49da2a0c..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/no0703/KthLargest2.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.leetcode.no0703; - -import java.util.PriorityQueue; -import java.util.Queue; - -class KthLargest2 { - - private Queue queue; - private int k; - - public KthLargest2(int k, int[] nums) { - queue = new PriorityQueue<>(k); - this.k = k; - // 初始化 - for (int num : nums) { - add(num); - } - } - - public int add(int val) { - if (queue.size() < k) { - // 赋值 - queue.add(val); - } else { - if (val > queue.peek()) { // 大于最小值,才有资格加入其中。因为我们构建的 heap 是小顶堆,最上面存储的是第 k 大。 - queue.poll(); - queue.add(val); - } - } - - return queue.peek(); - } - - public static void main(String[] args) { - if (true) { - int k = 3; - int[] nums = {4, 5, 8, 2}; - KthLargest2 kthLargest = new KthLargest2(k, nums); - System.out.println(kthLargest.add(3)); - System.out.println(kthLargest.add(5)); - System.out.println(kthLargest.add(10)); - System.out.println(kthLargest.add(9)); - System.out.println(kthLargest.add(4)); - } - if (false) { - int k = 1; - int[] nums = {}; - KthLargest2 kthLargest = new KthLargest2(k, nums); - System.out.println(kthLargest.add(-3)); - System.out.println(kthLargest.add(-2)); - System.out.println(kthLargest.add(-4)); - System.out.println(kthLargest.add(0)); - System.out.println(kthLargest.add(4)); - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/package-info.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/package-info.java deleted file mode 100644 index 5247f0a3f..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/leetcode/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * leetcode 题目解答 - */ -package cn.iocoder.springboot.labs.lab09.leetcode; diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/linkedlist/HuiWenLinkedListTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/linkedlist/HuiWenLinkedListTest.java deleted file mode 100644 index 4d412ac6c..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/linkedlist/HuiWenLinkedListTest.java +++ /dev/null @@ -1,110 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.linkedlist; - -import java.util.Objects; - -/** - * 判断单链表,是否为回文结构 - * - * 核心的逻辑是,顺序遍历,同时反向前半段。 - * - * 对应极客时间《06 | 链表(上):如何实现LRU缓存淘汰算法?》的思考题 - */ -public class HuiWenLinkedListTest { - - public static class Node { - - private Object data; - private Node next; - - public Object getData() { - return data; - } - - public Node setData(Object data) { - this.data = data; - return this; - } - - public Node getNext() { - return next; - } - - public Node setNext(Node next) { - this.next = next; - return this; - } - } - - public static void main(String[] args) { - huiwen01(); - huiwen02(); - } - - private static void huiwen01() { - Node node01 = new Node().setData("1"); - Node node02 = new Node().setData("2"); - Node node03 = new Node().setData("3"); - Node node04 = new Node().setData("4"); - Node node05 = new Node().setData("5"); - node01.next = node02; - node02.next = node03; - node03.next = node04; - node04.next = node05; - - assert !isHuiWen(node01); - } - - private static void huiwen02() { - Node node01 = new Node().setData("1"); - Node node02 = new Node().setData("2"); - Node node03 = new Node().setData("3"); - Node node04 = new Node().setData("2"); - Node node05 = new Node().setData("1"); - node01.next = node02; - node02.next = node03; - node03.next = node04; - node04.next = node05; - - assert isHuiWen(node01); - } - - private static boolean isHuiWen(Node head) { - // 如果不存在节点,或者是单节点,不然是回文 - if (head == null || head.next == null) { - return true; - } - - // 通过下面的逻辑,将链表的前半段,反转。 - Node slow = head; - Node fast = head; // fast 的用途,是能够保证只反向前半段 - Node prev = null; // 前半段的反向 - while (fast != null && fast.next != null) { - // fast 节点,按照自己的节奏,每次走 2 步。 - fast = fast.next.next; - // 创建 next 节点,记录 slow 真正下一个节点 - Node next = slow.next; - // 开始反转 - slow.next = prev; - prev = slow; - // 设置 slow 为真正的下一个节点 - slow = next; - } - - // 如果 fast 非空,说明 head 是基数个节点。此时,slow 需要跳过最中间的节点 - if (fast != null) { - slow = slow.next; - } - - // 开始对比 slow 和 prev - while (slow != null && prev != null) { - if (!Objects.equals(slow.data, prev.data)) { - return false; - } - slow = slow.next; - prev = prev.next; - } - - return true; - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/match/RabinKarp.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/match/RabinKarp.java deleted file mode 100644 index 80b2a53c3..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/match/RabinKarp.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.match; - -/** - * 参考 https://blog.csdn.net/jianke0503/article/details/79735928 文章 - * - * 实现 Rabin Karp 字符串查找 - */ -public class RabinKarp { - - // power 指数 - // base 计算超过范围,则返回 base - public static int find(String src, String target, int power, int base) { - // 计算长度 - int n = src.length(); - int m = target.length(); - - // target 的 hashcode - int targetCode = 0; - int mPower = 1; - for (int i = 0; i < m; i++) { - targetCode = (targetCode * power + target.charAt(i)) % base; - mPower = (mPower * power) % base; - } - - int srcCode = 0; - for (int i = 0; i < n; i++) { - srcCode = (srcCode * power + src.charAt(i)) % base; - if (i < m - 1) { // 不等于的原因是,i 是从 0 开始的。 - continue; - } - - if (i >= m) { // 此时,需要减掉头的 - srcCode = srcCode - ((src.charAt(i - m) * mPower) % base); - - // 避免减成负数 - if (srcCode < 0) { - srcCode = srcCode + base; - } - } - - if (srcCode == targetCode) { - if (src.substring(i - m + 1, i + 1).equals(target)) { - return i - m + 1; // + 1 的原因是,i 是从 0 开始,而 m 是从 1 开始。 - } - } - } - - return -1; - } - - public static void main(String[] args) { - String src = "2359023141526739921"; - String target = "5902"; - System.out.println(find(src, target, 31, 100)); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipList.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipList.java deleted file mode 100644 index 55cc79395..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipList.java +++ /dev/null @@ -1,114 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.search; - -import java.util.Random; - -/** - * 跳表的一种实现方法。 - * 跳表中存储的是正整数,并且存储的是不重复的。 - * - * From https://github.com/wangzheng0822/algo/blob/master/java/17_skiplist/SkipList.java - * - * Author:ZHENG - */ -@SuppressWarnings("Duplicates") -public class SkipList { - - private static final int MAX_LEVEL = 16; - - private int levelCount = 1; - - private Node head = new Node(); // 带头链表 - - private Random r = new Random(); - - public Node find(int value) { - Node p = head; - for (int i = levelCount - 1; i >= 0; --i) { - while (p.forwards[i] != null && p.forwards[i].data < value) { - p = p.forwards[i]; - } - } - - if (p.forwards[0] != null && p.forwards[0].data == value) { - return p.forwards[0]; - } else { - return null; - } - } - - public void insert(int value) { - int level = randomLevel(); - Node newNode = new Node(); - newNode.data = value; - newNode.maxLevel = level; - Node[] update = new Node[level]; - for (int i = 0; i < level; ++i) { - update[i] = head; - } - - // record every level largest value which smaller than insert value in update[] - Node p = head; - for (int i = level - 1; i >= 0; --i) { - while (p.forwards[i] != null && p.forwards[i].data < value) { - p = p.forwards[i]; - } - update[i] = p;// use update save node in search path - } - - // in search path node next node become new node forwords(next) - for (int i = 0; i < level; ++i) { - newNode.forwards[i] = update[i].forwards[i]; - update[i].forwards[i] = newNode; - } - - // update node hight - if (levelCount < level) levelCount = level; - } - - public void delete(int value) { - Node[] update = new Node[levelCount]; - Node p = head; - for (int i = levelCount - 1; i >= 0; --i) { - while (p.forwards[i] != null && p.forwards[i].data < value) { - p = p.forwards[i]; - } - update[i] = p; - } - - if (p.forwards[0] != null && p.forwards[0].data == value) { - for (int i = levelCount - 1; i >= 0; --i) { - if (update[i].forwards[i] != null && update[i].forwards[i].data == value) { - update[i].forwards[i] = update[i].forwards[i].forwards[i]; - } - } - } - } - - // 随机 level 次,如果是奇数层数 +1,防止伪随机 - private int randomLevel() { - int level = 1; - for (int i = 1; i < MAX_LEVEL; ++i) { - if (r.nextInt() % 2 == 1) { - level++; - } - } - - return level; - } - - public void printAll() { - Node p = head; - while (p.forwards[0] != null) { - System.out.print(p.forwards[0] + " "); - p = p.forwards[0]; - } - System.out.println(); - } - - public class Node { - private int data = -1; - private Node forwards[] = new Node[MAX_LEVEL]; - private int maxLevel = 0; - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipList2.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipList2.java deleted file mode 100644 index 66bb1f7fe..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipList2.java +++ /dev/null @@ -1,156 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.search; - -import java.util.Random; - -/** - * 参考 {@link SkipList} ,自己实现一遍跳表。 - * - * 通过 {@link Node} 的 forwards 数组实现,确实挺巧妙,代码量也非常精简。 - * - * 目前,网络上找到的 Java 跳表实现,主要是 https://sylvanassun.github.io/2017/12/31/2017-12-31-skip_list/ 这种。实现方式略有差别。 - * - * @author yunai - */ -@SuppressWarnings("Duplicates") -public class SkipList2 { - - private static final int MAX_LEVEL = 16; - - private Random random = new Random(); - - /** - * 总层级数 - */ - private int levelCount = 1; - - private Node head = new Node(null, MAX_LEVEL); - - public Node find(int value) { - // 自最上层索引,开始往下查询 - Node p = head; - for (int i = levelCount - 1; i >= 0; i--) { - while (p.forwards[i] != null && p.forwards[i].data < value) { // 这里看的会有点绕,第一次 for ,跳转到对应 i 层,后续的,就是第 i 层的不断向下指向 - p = p.forwards[i]; - } - } - - // 判断是否相等 - if (p.forwards[0] != null && p.forwards[0].data == value) { - return p.forwards[0]; - } - return null; - } - - public void insert(int value) { - // 创建 Node - int maxLevel = randomLevel(); - Node node = new Node(value, maxLevel); - - // 寻找每一层的指向 - Node[] update = new Node[maxLevel]; -// for (int i = 0; i < maxLevel; i++) { // 初始化 node 在一层的指向 。不需要,因为下面的 for 循环,一定会给 update 数组赋值。 -// update[i] = head; -// } - Node p = head; - for (int i = maxLevel - 1; i >= 0; i--) { - while (p.forwards[i] != null && p.forwards[i].data < value) { // 这里看的会有点绕,第一次 for ,跳转到对应 i 层,后续的,就是第 i 层的不断向下指向 - p = p.forwards[i]; - } - update[i] = p; - } - - // 设置指向 - for (int i = 0; i < maxLevel; i++) { - // 设置 node 在第 i 层,指向 update[i].forwards[i] - node.forwards[i] = update[i].forwards[i]; - // 将 update[i].forwards[i] 赋值成 node 。 - // 这样,就形成了 update[i].forwards[i] = node ,并且 node..forwards[i] = 原 update[i].forwards[i] 。可能有点绕,可以调试下 - update[i].forwards[i] = node; - } - - // 设置新的最高高度 - if (maxLevel > levelCount) { - levelCount = maxLevel; - } - } - - public void delete(int value) { - // 寻找一层对 value 应该 Node 的指向 - Node[] update = new Node[levelCount]; - Node p = head; - for (int i = levelCount - 1; i >= 0; i--) { - while (p.forwards[i] != null && p.forwards[i].data < value) { // 这里看的会有点绕,第一次 for ,跳转到对应 i 层,后续的,就是第 i 层的不断向下指向 - p = p.forwards[i]; - } - update[i] = p; - } - - // 如果找到指定节点 - if (p.forwards[0] != null && p.forwards[0].data == value) { - for (int i = levelCount - 1; i >= 0; i--) { - // 指定层,有符合 value 应该 Node 的指向,进行删除 - if (update[i].forwards[i] != null && update[i].forwards[i].data == value) { - update[i].forwards[i] = update[i].forwards[i].forwards[i]; - } - } - } - } - - private int randomLevel() { - return random.nextInt(MAX_LEVEL - 1) + 1; // 一定建立索引,避免直接添加到第 0 层。不然可能会丢失。 -// return random.nextInt(MAX_LEVEL); // 因为我们是从 1 层开始计数,可以看 levelCount 参数 - } - -// // 随机 level 次,如果是奇数层数 +1,防止伪随机 -// private int randomLevel() { -// int level = 1; -// for (int i = 1; i < MAX_LEVEL; ++i) { -// if (random.nextInt() % 2 == 1) { -// level++; -// } -// } -// -// return level; -// } - - /** - * 节点 - * - * 通过 {@link #forwards} 属性,记录在每一层的指向。 - * - * 注意,相同 {@link #data} ,在多层,通过 {@link #forwards} 属性来实现,而不是指向。 - */ - public class Node { - - // TODO 芋艿,如果想实现类似 HashMap 的功能,可以把 data 改成 key + value 。 - /** - * 数值 - */ - private Integer data; - - /** - * 最高层级 - */ - private int maxLevel; - /** - * 对指定层级的指向 - */ - private Node[] forwards; - - public Node(Integer data, int maxLevel) { - this.data = data; - this.maxLevel = maxLevel; - this.forwards = new Node[maxLevel]; -// this.forwards = new Node[MAX_LEVEL]; - } - - @Override - public String toString() { - return "Node{" + - "data=" + data + - ", maxLevel=" + maxLevel + - '}'; - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipListTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipListTest.java deleted file mode 100644 index 7c873fdac..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SkipListTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.search; - -public class SkipListTest { - - public static void main2(String[] args) { - SkipList skipList = new SkipList(); - skipList.insert(1); - skipList.insert(2); - skipList.insert(3); - skipList.insert(1); - skipList.insert(1); - skipList.insert(1); - skipList.delete(1); - skipList.printAll(); - } - - public static void main(String[] args) { - for (int i = 0; i < 10000; i++) { - SkipList2 skipList = new SkipList2(); -// SkipList skipList = new SkipList(); - // 测试添加 - skipList.insert(2); - skipList.insert(1); - - // 测试查询 - System.out.println(skipList.find(1) != null); - assert skipList.find(1) != null; - System.out.println(skipList.find(2) != null); - assert skipList.find(2) != null; - System.out.println(skipList.find(3) == null); // null - assert skipList.find(3) == null; - - // 测试删除 - skipList.delete(1); - System.out.println(skipList.find(1) == null); // null - assert skipList.find(1) == null; - System.out.println(skipList.find(2) != null); - assert skipList.find(2) != null; - } - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SquareTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SquareTest.java deleted file mode 100644 index 107c3f061..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/search/SquareTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.search; - -/** - * 使用二分查找,计算平方根。 - */ -public class SquareTest { - - public static void main(String[] args) { - double result = sqrt(5, 0.00001D); - System.out.println(result); - } - - // precision 表示精度 - private static double sqrt(int number, double precision) { - int rounds = 0; // 用于记录轮次,调试用途 - double low = 0; - double high = number; - while (low <= high) { - double middle = low + ((high - low) / 2); - double result = middle * middle; - System.out.println(String.format("第 %d 轮,结果:%f", ++rounds, middle)); - - double diff = number - result; - if (0 <= diff && diff <= precision) { - return middle; - } - if (result < number) { - low = middle; - } else if (result > number) { - high = middle; - } else { - throw new IllegalStateException("不可能出现"); - } - } - throw new IllegalStateException("必然有结果,还能求不出平方根"); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/BucketSorterTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/BucketSorterTest.java deleted file mode 100644 index 69cdc62b6..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/BucketSorterTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.sort; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Random; - -public class BucketSorterTest { - - public static void main(String[] args) { - Random random = new Random(); - int[] array = new int[1000]; - for (int i = 0; i < 1000; i++) { - array[i] = random.nextInt(10000); - } - bucketSort(array, 100); - } - - // bucketSize - 指的是每个 bucket 的大小 - public static void bucketSort(int[] array, int bucketSize) { - // 求最大最小值 - int max = Integer.MIN_VALUE; - int min = Integer.MAX_VALUE; - for (int value : array) { - if (value > max) { - max = value; - } - if (value < min) { - min = value; - } - } - - // 创建桶 - int bucketCounts = (max - min) / bucketSize + 1; // 这里后面要优化下,向上取整。例如说 101 / 10 ,理论来说,应该是 11 个木桶 - ArrayList> buckets = new ArrayList<>(bucketCounts); // 使用 ArrayList ,方便实现,减少扩容等等麻烦 - for (int i = 0; i < bucketCounts; i++) { - buckets.add(new ArrayList()); - } - - // 添加到桶中 - for (int value : array) { - buckets.get((value - min) / bucketSize).add(value); // -min ,因为它是起点 - } - - // 排序每个桶 - for (ArrayList bucket : buckets) { - Collections.sort(bucket); // 方便 - } - System.out.println(buckets); - - // 打印结果 - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/HeapSorterTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/HeapSorterTest.java deleted file mode 100644 index 979e24815..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/HeapSorterTest.java +++ /dev/null @@ -1,134 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.sort; - -import java.util.Arrays; - -/** - * 堆排序 - */ -public class HeapSorterTest { - - public static void main(String[] args) { - if (false) { - HeapSorter heapSorter = new HeapSorter(10); - heapSorter.insert(10); - heapSorter.insert(3); - heapSorter.insert(5); - heapSorter.insert(1); - heapSorter.insert(2); - heapSorter.insert(20); - System.out.println(Arrays.toString(heapSorter.heap)); - - heapSorter.remove(2); - System.out.println(Arrays.toString(heapSorter.heap)); - } - - if (true) { - int[] array = {0, 10, 3, 5, 1, 2, 20}; - HeapSorter heapSorter = HeapSorter.create(array, array.length - 1); -// System.out.println(Arrays.toString(heapSorter.heap)); - heapSorter.sort(); - } - } - - public static class HeapSorter { - - /** - * 堆 - */ - private int[] heap; - /** - * 容量 - */ - private int capacity; - /** - * 元素数量 - */ - private int count; - - public HeapSorter(int[] heap, int count) { - this.capacity = heap.length; - this.heap = heap; - this.count = count; - } - - public HeapSorter(int capacity) { - this.capacity = capacity; - this.heap = new int[capacity + 1]; // 因为 0 被占用了 - count = 0; - } - - public void insert(int value) { - if (count >= capacity) { - throw new IllegalStateException("容量已满"); - } - ++count; - heap[count] = value; - - // 自下向上堆化,如果大于父节点 - int index = count; - while (index >> 1 > 0 && heap[index] > heap[index >> 1]) { - swap(index, index >> 1); - index = index >> 1; - } - } - - public int remove(int pos) { - if (count == 0) { - throw new IllegalStateException("不存在最大值"); - } - int tmp = heap[pos]; - heap[pos] = heap[count]; - heap[count] = 0; // 置空,其实非必要。就是为了好看 - count--; - - heapify(heap, count, pos); - return tmp; - } - - /** - * 排序 - */ - public void sort() { - while (count > 1) { - System.out.println(remove(1)); - } - } - - private void swap(int i, int j) { - swap(heap, i, j); - } - - public static HeapSorter create(int[] heap, int count) { - for (int i = count / 2; i >= 1; i--) { - heapify(heap, count, i); - } - return new HeapSorter(heap, count); - } - - private static void heapify(int[] heap, int count, int pos) { - // 自伤向下, - while (true) { - int maxPos = pos; - if (pos * 2 <= count && heap[pos] < heap[pos * 2]) { - maxPos = pos * 2; - } - if (pos * 2 + 1 <= count && heap[maxPos] < heap[pos * 2 + 1]) { - maxPos = pos * 2 + 1; - } - // 判断相等,说明没变化 - if (maxPos == pos) { - return; - } - swap(heap, pos, maxPos); - } - } - - private static void swap(int[] heap, int i, int j) { - int tmp = heap[i]; - heap[i] = heap[j]; - heap[j] = tmp; - } - - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/MergeSorterTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/MergeSorterTest.java deleted file mode 100644 index e3f35ae0b..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/MergeSorterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.sort; - -import java.util.Arrays; - -/** - * 合并排序 - */ -public class MergeSorterTest { - - public static void main(String[] args) { - { - int[] array = new int[]{5, 4, 2, 3, 1, 2, 5, 2, 6}; - mergeSort(array); - } - } - - private static void mergeSort(int[] array) { - int[] tmpArray = new int[array.length]; - mergeSort(array, tmpArray, 0, array.length - 1); - - System.out.println(Arrays.toString(array)); - } - - private static void mergeSort(int[] array, int[] tmpArray, int low, int high) { - // 递归结束,如果 low 和 high 是相同的 - if (low >= high) { - return; - } - - // 折半,进行分解 - int middle = low + (high - low >> 1); // >> 1 等价于 / 2 - mergeSort(array, tmpArray, low, middle); - mergeSort(array, tmpArray, middle + 1, high); - - // 合并 - merge(array, tmpArray, low, middle, high); - } - - private static void merge(int[] array, int[] tmpArray, int low, int middle, int high) { - // 比较排序 - int highStart = middle + 1; - int lowStart = low; // 需要赋值出来,是为了避免 low 被修改 - int tmpArrayIndex = low; // tmpArray 的 index - while (lowStart <= middle && highStart <= high) { // 能够这么操作的原因是,每次递归,最终的结果都是有序的。所以就一直可以有序了。 - if (array[lowStart] > array[highStart]) { - tmpArray[tmpArrayIndex++] = array[highStart++]; - } else { - tmpArray[tmpArrayIndex++] = array[lowStart++]; - } - } - - // 将上述未赋值到 tmpArray 的,继续赋值进去 - while (lowStart <= middle) { - tmpArray[tmpArrayIndex++] = array[lowStart++]; - } - while (highStart <= high) { - tmpArray[tmpArrayIndex++] = array[highStart++]; - } - - // 将排序后的 tmpArrayIndex 赋值到 array 中,从 low 开始到 high 部分。 - System.arraycopy(tmpArray, low, array, low, high - low + 1); - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/QuickSorterTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/QuickSorterTest.java deleted file mode 100644 index 1aa68b6f3..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/QuickSorterTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.sort; - -import java.util.Arrays; - -/** - * 快速排序 - */ -public class QuickSorterTest { - - public static void main(String[] args) { - { - int[] array = new int[]{5, 4, 2, 3, 1, 2, 5, 2, 6}; -// int[] array = new int[]{6, 11, 8}; - quickSort(array); - } - } - - private static void quickSort(int[] array) { - quickSort(array, 0, array.length - 1); - - System.out.println(Arrays.toString(array)); - } - - private static void quickSort(int[] array, int low, int high) { - if (low >= high) { - return; - } - - // 寻找 partition 位置 -// int partitionIndex = partition(array, low, high); - int partitionIndex = partition02(array, low, high); - - // 递归排序 - quickSort(array, low, partitionIndex - 1); - quickSort(array, partitionIndex + 1, high); - } - - @SuppressWarnings("Duplicates") - public static int partition(int[] array, int low, int high) { - int partitionValue = array[high]; // 首先,选择 high 位置的值,作为 partitionValue 值 - int pos = low; - // 遍历 array 的 low 到 high 区间,将小于 partitionValue 值的部分,顺序放到 [0, pos) 范围内。最终,pos 我们会放 partitionValue 值。 - for (int i = low; i < high; i++) { - if (array[i] < partitionValue) { - // 进行交换 - swap(array, i, pos); - // pos + 1 ,用于下一个使用 - pos++; - } - } - - // 将 pos 我们会放 partitionValue 值。 - swap(array, pos, high); - - // 返回 partitionValue 所在位置 - return pos; - } - - - - private static void swap(int[] array, int pos1, int pos2) { - if (pos1 == pos2) { - return; - } - int tmp = array[pos1]; - array[pos1] = array[pos2]; - array[pos2] = tmp; - } - - // partition 的逻辑,基于 swap ,需要 3 次操作 - // partition02 的逻辑,基于赋值来做,只需要 1 次操作。相比来说,性能更好。 - // 当然,第一次看 partition02 的逻辑,可能会有点懵逼。大体的理解是,low 和 high 之间,被不断夹紧,把比 pivot 大的放到右侧,比 pivot 小的放到左侧。 - // 本质可以理解成: - // 1. pivot = arr[low]; =》 A -> B - // 2. arr[low] = arr[high]; =》 B -> C - // 3. arr[high] = arr[low]; =》 C -> D - // 4. 重复循环,我们最终找到真正的 D ,将 原 B ,也就是 A ,复制上去。 - private static int partition02(int[] arr, int low, int high) { - int pivot = arr[low]; //枢轴记录 - // 循环,达到 arr[low] 左边是比它小,右边是比它大。 - while (low < high) { // 实际上,最终 break 的条件是,low 和 high 相等。具体可以看里面的两个 while - while (low < high && arr[high] >= pivot) --high; // 因为 high 原来就在右侧,所以不需要移动 - arr[low] = arr[high]; // 交换比枢轴小的记录到左端 - - while (low < high && arr[low] <= pivot) ++low; // 因为 low 原来就在左侧,所以不需要移动 - arr[high] = arr[low]; // 交换比枢轴小的记录到右端 - } - //扫描完成,枢轴到位 - arr[low] = pivot; - //返回的是枢轴的位置 - return low; - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/RadixSorterTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/RadixSorterTest.java deleted file mode 100644 index 8fcdad729..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/RadixSorterTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.sort; - -import java.util.ArrayList; -import java.util.Arrays; - -/** - * 基数排序 - * - * 每个位的排序,通过桶排序实现,从而实现 k * O(n) 的复杂度 - */ -public class RadixSorterTest { - - public static void main(String[] args) { - int[] array = new int[]{ - 23, - 50, - 100, - 1, - 10, - 21, - 50, - }; - - radixSort(array); - } - - private static void radixSort(int[] array) { - int digits = getMaxDigits(array); - for (int digit = 0; digit < digits; digit++) { - radixSort(array, digit); - } - - System.out.println(Arrays.toString(array)); - } - - private static void radixSort(int[] array, int digit) { - // 用于后面,获得第 digit 位 - int base = (int) Math.pow(10, digit); - - // 创建桶 - int bucketCounts = 10; - ArrayList> buckets = new ArrayList<>(bucketCounts); - for (int i = 0; i < bucketCounts; i++) { - buckets.add(new ArrayList<>()); - } - - // 添加到桶中 - for (int value : array) { - int bucketIndex = value / base % bucketCounts; - buckets.get(bucketIndex).add(value); - } - - // 顺序输出,自然有序 - int index = 0; - for (ArrayList bucket : buckets) { - for (Integer value : bucket) { - array[index++] = value; - } - } - } - - private static int getMaxDigits(int[] array) { - int max = Integer.MIN_VALUE; - for (int value : array) { - if (value > max) { - max = value; - } - } - int digits = 0; - while (max > 0) { - digits++; - max = max / 10; - } - return digits; - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/TheFirstBigKTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/TheFirstBigKTest.java deleted file mode 100644 index 698cb1584..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/sort/TheFirstBigKTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.sort; - -import java.util.Arrays; - -/** - * 基于快速排序的方式,实现第 k 大的数 - */ -public class TheFirstBigKTest { - - public static void main(String[] args) { - { - int[] array = new int[]{5, 4, 2, 3, 1, 2, 5, 2, 6}; -// int[] array = new int[]{6, 11, 8}; -// quickSort(array, 1); -// quickSort(array, 2); -// quickSort(array, 3); -// quickSort(array, 4); - quickSort(array, 5); - } - } - - private static void quickSort(int[] array, int k) { - if (k > array.length) { - throw new IllegalStateException("k 不能大于最大数组"); - } - quickSort(array, k - 1, 0, array.length - 1); - - System.out.println(Arrays.toString(array)); - System.out.println("答案 k :" + array[k - 1]); - } - - private static void quickSort(int[] array, int k, int low, int high) { - if (low >= high) { - return; - } - - int partition = partition(array, low, high); - if (partition == k) { - return; - } - - if (partition < k) { - quickSort(array, k, partition + 1, high); - } else { - quickSort(array, k, low, partition - 1); - } - } - - @SuppressWarnings("Duplicates") - private static int partition(int[] array, int low, int high) { - int partitionValue = array[high]; // 首先,选择 high 位置的值,作为 partitionValue 值 - int pos = low; - // 遍历 array 的 low 到 high 区间,将小于 partitionValue 值的部分,顺序放到 [0, pos) 范围内。最终,pos 我们会放 partitionValue 值。 - for (int i = low; i < high; i++) { - if (array[i] < partitionValue) { - // 进行交换 - swap(array, i, pos); - // pos + 1 ,用于下一个使用 - pos++; - } - } - - // 将 pos 我们会放 partitionValue 值。 - swap(array, pos, high); - - // 返回 partitionValue 所在位置 - return pos; - } - - private static void swap(int[] array, int pos1, int pos2) { - if (pos1 == pos2) { - return; - } - int tmp = array[pos1]; - array[pos1] = array[pos2]; - array[pos2] = tmp; - } - -} diff --git a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/tree/MySQLBTreePlusTest.java b/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/tree/MySQLBTreePlusTest.java deleted file mode 100644 index 5e440f0c6..000000000 --- a/lab-09/src/main/java/cn/iocoder/springboot/labs/lab09/tree/MySQLBTreePlusTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package cn.iocoder.springboot.labs.lab09.tree; - -/** - * MySQL B+Tree - */ -public class MySQLBTreePlusTest { - - /** - * 非叶子节点 - */ - public static class Node { - - /** - * 5 叉树 - */ - public static int m = 5; - - /** - * 键值的数组 - * - * m - 1 的原因是,keywords 代表的是区间。 - * - * children[0] 的范围是 [ -无穷, keywords[0] ] - * children[1] 的泛微是 - */ - private int[] keywords = new int[m - 1]; - - /** - * 保存子节点的指针 - */ - private Node[] children = new Node[m]; - - } - - /** - * 叶子节点 - */ - public static class LeafNode { - - /** - * 假设每个叶子节点存储三个数据行的键值和数据地址信息 - */ - public static int k = 3; - - /** - * 数据行的键值 - * - * 不同于 {@link Node#keywords} ,这里表示的是具体值 - */ - private int[] keywords = new int[k]; - /** - * 数据航的地址值 - */ - private int[] dataAddresses = new int[k]; - - /** - * 前置的叶子节点,用于区间检索 - */ - private LeafNode prev; - /** - * 后置的叶子节点,用于区间检索 - */ - private LeafNode next; - - } - -} diff --git "a/lab-09/\345\207\206\345\244\207\345\210\240\351\231\244" "b/lab-09/\345\207\206\345\244\207\345\210\240\351\231\244" deleted file mode 100644 index e69de29bb..000000000 diff --git a/lab-10/pom.xml b/lab-10/pom.xml deleted file mode 100644 index 11aa51736..000000000 --- a/lab-10/pom.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - org.springframework.boot - spring-boot-starter-parent - 2.1.4.RELEASE - - - 4.0.0 - - lab-10 - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-actuator - - - - diff --git a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/Controller.java b/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/Controller.java deleted file mode 100644 index 30fafc3f2..000000000 --- a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/Controller.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.springboot.labs.lab10; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class Controller { - - @GetMapping("/hello") - public String hello() { -// System.out.println(Thread.currentThread().getName()); - return "world"; - } - - @GetMapping("/sleep") - public String sleep() throws InterruptedException { - Thread.sleep(100L); -// System.out.println(Thread.currentThread().getName()); - return "world"; - } - -} diff --git a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/SpringMVCApplication.java b/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/SpringMVCApplication.java deleted file mode 100644 index 51b8a3558..000000000 --- a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/SpringMVCApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.iocoder.springboot.labs.lab10; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringMVCApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringMVCApplication.class); - } - -} diff --git a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/TestListener.java b/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/TestListener.java deleted file mode 100644 index 6b1a96483..000000000 --- a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/TestListener.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.springboot.labs.lab10; - -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.stereotype.Component; - -@Component -public class TestListener implements ApplicationListener { - - @Override - public void onApplicationEvent(ApplicationEvent event) { - System.out.println("事件:" + event); - } - -} diff --git a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/UserHealthIndicator.java b/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/UserHealthIndicator.java deleted file mode 100644 index 21fd1cada..000000000 --- a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/UserHealthIndicator.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.springboot.labs.lab10; - -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.HealthIndicator; - -//@Component -public class UserHealthIndicator implements HealthIndicator { - - /** - * user监控 访问: http://localhost:8088/health - * - * @return 自定义Health监控 - */ - @Override - public Health health() { - return new Health.Builder().withDetail("usercount", 10) //自定义监控内容 - .withDetail("userstatus", "up").down().build(); - } - -} diff --git a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleConfiguration.java b/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleConfiguration.java deleted file mode 100644 index bf0162693..000000000 --- a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.springboot.labs.lab10.lifecycle; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class ServerLifeCycleConfiguration { - - @Bean - public ServerLifeCycleHealthIndicator serverLifeCycleHealthIndicator() { - return new ServerLifeCycleHealthIndicator(); - } - - @Bean - public ServerLifeCycleListener serverLifeCycleListener() { - return new ServerLifeCycleListener(this.serverLifeCycleHealthIndicator()); - } - -} diff --git a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleConfigurationProperties.java b/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleConfigurationProperties.java deleted file mode 100644 index 56f23e947..000000000 --- a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleConfigurationProperties.java +++ /dev/null @@ -1,8 +0,0 @@ -package cn.iocoder.springboot.labs.lab10.lifecycle; - -// TODO sleep 时长的配置 -public class ServerLifeCycleConfigurationProperties { - - - -} diff --git a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleHealthIndicator.java b/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleHealthIndicator.java deleted file mode 100644 index 4176daaa4..000000000 --- a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleHealthIndicator.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.springboot.labs.lab10.lifecycle; - -import org.springframework.boot.actuate.health.AbstractHealthIndicator; -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.Status; - -public class ServerLifeCycleHealthIndicator extends AbstractHealthIndicator { - - /** - * 服务状态 - * - * 启动阶段: - * 1. 项目初始启动时,状态为 OUT_OF_SERVICE 不提供服务。 - * 2. 服务启动完成(ApplicationReadyEvent)时,状态为 UP 启动。 - * 3. 服务启动失败(ApplicationFailedEvent)时,状态 DOWN 关闭。 - * - * 关闭阶段: - * 1. 服务开始关闭(ContextClosedEvent)时,状态为 OUT_OF_SERVICE 不提供服务。 - * 2. 因为服务关闭完成,不存在事件,所以暂时不处理。 - * - * 具体的状态变更,通过 - */ - private volatile Status status = Status.OUT_OF_SERVICE; - - @Override - protected void doHealthCheck(Health.Builder builder) { - builder.status(status); - } - - public void up() { - this.status = Status.UP; - } - - public void down() { - this.status = Status.DOWN; - } - - public void outOfService() { - this.status = Status.OUT_OF_SERVICE; - } - - public Status status() { - return this.status; - } - -} diff --git a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleListener.java b/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleListener.java deleted file mode 100644 index f8228e227..000000000 --- a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/ServerLifeCycleListener.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.iocoder.springboot.labs.lab10.lifecycle; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.context.event.ApplicationFailedEvent; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ContextClosedEvent; - -public class ServerLifeCycleListener implements ApplicationListener { - - private Logger logger = LoggerFactory.getLogger(getClass()); - - private ServerLifeCycleHealthIndicator healthIndicator; - - public ServerLifeCycleListener(ServerLifeCycleHealthIndicator healthIndicator) { - this.healthIndicator = healthIndicator; - } - - @Override - public void onApplicationEvent(ApplicationEvent event) { - if (event instanceof ApplicationReadyEvent) { - this.handleApplicationReadyEvent((ApplicationReadyEvent) event); - } else if (event instanceof ApplicationFailedEvent) { - this.handleApplicationFailedEvent((ApplicationFailedEvent) event); - } else if (event instanceof ContextClosedEvent) { - this.handleContextClosedEvent((ContextClosedEvent) event); - } - } - - @SuppressWarnings("unused") - private void handleApplicationReadyEvent(ApplicationReadyEvent event) { - healthIndicator.up(); - } - - @SuppressWarnings("unused") - private void handleApplicationFailedEvent(ApplicationFailedEvent event) { - healthIndicator.down(); - } - - @SuppressWarnings("unused") - private void handleContextClosedEvent(ContextClosedEvent event) { - // 标记不提供服务 - healthIndicator.outOfService(); - - // sleep 等待负载均衡完成健康检查 - for (int i = 0; i < 20; i++) { // TODO 20 需要配置 - logger.info("[handleContextClosedEvent][优雅关闭,第 {} sleep 等待负载均衡完成健康检查]", i); - try { - Thread.sleep(1000L); - } catch (InterruptedException ignore) { - } - } - } - -} diff --git a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/StatusController.java b/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/StatusController.java deleted file mode 100644 index d2d16b7c2..000000000 --- a/lab-10/src/main/java/cn/iocoder/springboot/labs/lab10/lifecycle/StatusController.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.springboot.labs.lab10.lifecycle; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.health.Status; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController // TODO rest 没生效,得排查下。 -@RequestMapping("/") // TODO 可配置 -public class StatusController { - - @Autowired - private ServerLifeCycleHealthIndicator serverLifeCycleHealthIndicator; - - @RequestMapping("/status") - public ResponseEntity status() { - Status status = serverLifeCycleHealthIndicator.status(); - // 成功 - if (Status.UP == status) { - return new ResponseEntity<>(status.getDescription(), HttpStatus.OK); - } - // 失败 - return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).body(status.getDescription()); - } - -} diff --git a/lab-10/src/main/resources/application.properties b/lab-10/src/main/resources/application.properties deleted file mode 100644 index 0eb258cba..000000000 --- a/lab-10/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -management.endpoint.health.show-details=always -server.port=9080 diff --git "a/lab-10/\345\207\206\345\244\207\345\210\240\351\231\244" "b/lab-10/\345\207\206\345\244\207\345\210\240\351\231\244" deleted file mode 100644 index e69de29bb..000000000 diff --git a/pom.xml b/pom.xml index 34dec6d87..241c217c6 100644 --- a/pom.xml +++ b/pom.xml @@ -18,9 +18,6 @@ - - - From f98d6ac3e63fd7d974ce7b5f6b1969f61df1aa7a Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Mon, 29 Jun 2020 19:27:21 +0800 Subject: [PATCH 02/29] =?UTF-8?q?IDEA=20=E7=83=AD=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- {lab-48 => lab-48-hot-swap}/lab-48-demo/pom.xml | 0 .../java/cn/iocoder/springboot/lab48/demo/DemoApplication.java | 0 .../springboot/lab48/demo/controller/DemoController.java | 0 {lab-48 => lab-48-hot-swap}/pom.xml | 2 +- ...\203\250\347\275\262\345\205\245\351\227\250\343\200\213.md" | 0 pom.xml | 2 +- 7 files changed, 3 insertions(+), 3 deletions(-) rename {lab-48 => lab-48-hot-swap}/lab-48-demo/pom.xml (100%) rename {lab-48 => lab-48-hot-swap}/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/DemoApplication.java (100%) rename {lab-48 => lab-48-hot-swap}/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/controller/DemoController.java (100%) rename {lab-48 => lab-48-hot-swap}/pom.xml (92%) rename "lab-48/\343\200\212\350\212\213\351\201\223 Spring Boot \347\203\255\351\203\250\347\275\262\345\205\245\351\227\250\343\200\213.md" => "lab-48-hot-swap/\343\200\212\350\212\213\351\201\223 Spring Boot \347\203\255\351\203\250\347\275\262\345\205\245\351\227\250\343\200\213.md" (100%) diff --git a/README.md b/README.md index 79e614ce7..fa9665440 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ ## 开发工具 -* [《芋道 Spring Boot 热部署入门》](http://www.iocoder.cn/Spring-Boot/hot-swap/?github) 对应 [lab-48](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-48) +* [《芋道 Spring Boot 热部署入门》](http://www.iocoder.cn/Spring-Boot/hot-swap/?github) 对应 [lab-48-hot-swap](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-48-hot-swap) * [《芋道 Spring Boot 消除冗余代码 Lombok 入门》](http://www.iocoder.cn/Spring-Boot/Lombok/?github) 对应 [lab-49](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-49) * [《芋道 Spring Boot 对象转换 MapStruct 入门》](http://www.iocoder.cn/Spring-Boot/MapStruct/?github) 对应 [lab-55](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-55) diff --git a/lab-48/lab-48-demo/pom.xml b/lab-48-hot-swap/lab-48-demo/pom.xml similarity index 100% rename from lab-48/lab-48-demo/pom.xml rename to lab-48-hot-swap/lab-48-demo/pom.xml diff --git a/lab-48/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/DemoApplication.java b/lab-48-hot-swap/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/DemoApplication.java similarity index 100% rename from lab-48/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/DemoApplication.java rename to lab-48-hot-swap/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/DemoApplication.java diff --git a/lab-48/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/controller/DemoController.java b/lab-48-hot-swap/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/controller/DemoController.java similarity index 100% rename from lab-48/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/controller/DemoController.java rename to lab-48-hot-swap/lab-48-demo/src/main/java/cn/iocoder/springboot/lab48/demo/controller/DemoController.java diff --git a/lab-48/pom.xml b/lab-48-hot-swap/pom.xml similarity index 92% rename from lab-48/pom.xml rename to lab-48-hot-swap/pom.xml index d4dc38d7a..3ecc26058 100644 --- a/lab-48/pom.xml +++ b/lab-48-hot-swap/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - lab-48 + lab-48-hot-swap pom diff --git "a/lab-48/\343\200\212\350\212\213\351\201\223 Spring Boot \347\203\255\351\203\250\347\275\262\345\205\245\351\227\250\343\200\213.md" "b/lab-48-hot-swap/\343\200\212\350\212\213\351\201\223 Spring Boot \347\203\255\351\203\250\347\275\262\345\205\245\351\227\250\343\200\213.md" similarity index 100% rename from "lab-48/\343\200\212\350\212\213\351\201\223 Spring Boot \347\203\255\351\203\250\347\275\262\345\205\245\351\227\250\343\200\213.md" rename to "lab-48-hot-swap/\343\200\212\350\212\213\351\201\223 Spring Boot \347\203\255\351\203\250\347\275\262\345\205\245\351\227\250\343\200\213.md" diff --git a/pom.xml b/pom.xml index 241c217c6..1127eda64 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ - + From 38fe54657c589c0729a91a18a4686cf36d65225c Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Thu, 2 Jul 2020 19:25:24 +0800 Subject: [PATCH 03/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=A4=E6=B5=81?= =?UTF-8?q?=E7=BE=A4=EF=BC=8C=E5=A4=AA=E5=A4=9A=E8=83=96=E5=8F=8B=E6=89=BE?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E5=B8=85=E6=B0=94=E7=9A=84=E6=88=91=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fa9665440..003525b31 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,17 @@ ![一间三连](http://static.iocoder.cn/github-star.jpg) -> ~~交流~~**装逼群**,请点击[传送门](http://www.iocoder.cn/mall-user-group/?vip&gitee),进行引导加入。**亲,一键三连啊** +> **亲,一键三连啊** + +# 交流群 + +扫码如下**二维码**,回复「艿艿」关键字。 + +可以添加 18 岁的我为好友,并拉你进一个~~交流~~**装逼群**。 + +![骚气的二维码](http://www.iooder.cn/images/common/erweima.jpg) + +😈 等后面,艿艿**头发**重新长一点出来,给旁友们录制点视频哈! # Spring Boot 专栏 From 67026716cf98db2368decc139c34901a0e60358c Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Thu, 2 Jul 2020 19:26:31 +0800 Subject: [PATCH 04/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=A4=E6=B5=81?= =?UTF-8?q?=E7=BE=A4=EF=BC=8C=E5=A4=AA=E5=A4=9A=E8=83=96=E5=8F=8B=E6=89=BE?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E5=B8=85=E6=B0=94=E7=9A=84=E6=88=91=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 003525b31..428f7de24 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ 可以添加 18 岁的我为好友,并拉你进一个~~交流~~**装逼群**。 -![骚气的二维码](http://www.iooder.cn/images/common/erweima.jpg) +![骚气的二维码](http://www.iocoder.cn/images/common/erweima.jpg) 😈 等后面,艿艿**头发**重新长一点出来,给旁友们录制点视频哈! From c85002f18bae09911dfa8676a9e0fcf46207edaa Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Tue, 4 Aug 2020 19:32:40 +0800 Subject: [PATCH 05/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20tars=20=E7=9A=84?= =?UTF-8?q?=E8=AE=A1=E5=88=92~=20=E6=9C=80=E8=BF=91=E5=9C=A8=E8=8A=B1?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=86=99=20onemall=20=E7=BE=8E=E6=BB=8B?= =?UTF-8?q?=E6=BB=8B=E3=80=82=20=E5=9D=90=E7=AD=89=20spring=20boot=202.4.X?= =?UTF-8?q?=20=E7=89=88=E6=9C=AC=EF=BC=8C=E8=BF=9B=E8=A1=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=A4=A7=E7=89=88=E6=9C=AC=E7=9A=84=E6=9B=B4=E6=96=B0?= =?UTF-8?q?~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ .../lab-68-demo21-resource-server-on-sso/pom.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 428f7de24..0181341f4 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ * [《芋道 Spring Boot SOFARPC 入门》](http://www.iocoder.cn/Spring-Boot/SOFARPC/?github) 对应 [lab-62](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-62) * [《芋道 Spring Boot Motan 入门》](http://www.iocoder.cn/Spring-Boot/Motan/?github) 对应 [lab-63](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-63) * 《芋道 Spring Boot RSocket 入门》计划中... +* 《芋道 Spring Boot Tars 入门》计划中... ## 数据访问 @@ -155,6 +156,7 @@ * [《芋道 Spring Boot 日志集成 Logging 入门》](http://www.iocoder.cn/Spring-Boot/Logging/?github) 对应 [lab-37](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-37) * [《芋道 Spring Boot 日志平台 ELK + Filebeat 入门》](http://www.iocoder.cn/Spring-Boot/ELK/?github) 对应 [lab-38](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-38) +* 《芋道 Spring Boot 日志平台 Loki 入门》计划中... ## 链路追踪 diff --git a/lab-68-spring-security-oauth/lab-68-demo21-resource-server-on-sso/pom.xml b/lab-68-spring-security-oauth/lab-68-demo21-resource-server-on-sso/pom.xml index 313426637..7d99f7f54 100644 --- a/lab-68-spring-security-oauth/lab-68-demo21-resource-server-on-sso/pom.xml +++ b/lab-68-spring-security-oauth/lab-68-demo21-resource-server-on-sso/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - lab-68-demo21-resource-server + lab-68-demo21-resource-server-on-sso From 69a9807e817baa88b24ebd952b3e7a99dbffe75e Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Wed, 9 Sep 2020 22:08:09 +0800 Subject: [PATCH 06/29] =?UTF-8?q?java=20=E5=90=84=E7=A7=8D=20proxy=20?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +++--- lab-69-proxy/lab-69-proxy-cglib/pom.xml | 22 ++++++++++++++++ .../springboot/labs/lab69/TestProxyMain.java | 19 ++++++++++++++ .../UserServiceMethodInterceptor.java | 17 ++++++++++++ .../labs/lab69/service/UserServiceImpl.java | 9 +++++++ lab-69-proxy/lab-69-proxy-jdk/pom.xml | 22 ++++++++++++++++ .../labs/lab69/GenerateProxyMain.java | 25 ++++++++++++++++++ .../springboot/labs/lab69/TestProxyMain.java | 26 +++++++++++++++++++ .../lab69/handler/UserServiceHandler.java | 24 +++++++++++++++++ .../labs/lab69/service/UserService.java | 7 +++++ .../labs/lab69/service/UserServiceImpl.java | 9 +++++++ lab-69-proxy/pom.xml | 20 ++++++++++++++ pom.xml | 2 ++ 13 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 lab-69-proxy/lab-69-proxy-cglib/pom.xml create mode 100644 lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/TestProxyMain.java create mode 100644 lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/intercept/UserServiceMethodInterceptor.java create mode 100644 lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserServiceImpl.java create mode 100644 lab-69-proxy/lab-69-proxy-jdk/pom.xml create mode 100644 lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/GenerateProxyMain.java create mode 100644 lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/TestProxyMain.java create mode 100644 lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/handler/UserServiceHandler.java create mode 100644 lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserService.java create mode 100644 lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserServiceImpl.java create mode 100644 lab-69-proxy/pom.xml diff --git a/README.md b/README.md index 0181341f4..9ee72fd2c 100644 --- a/README.md +++ b/README.md @@ -397,10 +397,10 @@ 如下是草稿目录,未来需要整理下 -# lab-9 - -记录阅读极客时间《数据结构与算法之美》的题目。 - # lab-50 Email 示例 + +# lab-69-proxy + +动态代理 diff --git a/lab-69-proxy/lab-69-proxy-cglib/pom.xml b/lab-69-proxy/lab-69-proxy-cglib/pom.xml new file mode 100644 index 000000000..c9d1e933d --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-cglib/pom.xml @@ -0,0 +1,22 @@ + + + + lab-69 + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-69-proxy-cglib + + + + cglib + cglib + 3.3.0 + + + + diff --git a/lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/TestProxyMain.java b/lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/TestProxyMain.java new file mode 100644 index 000000000..9885e9df6 --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/TestProxyMain.java @@ -0,0 +1,19 @@ +package cn.iocoder.springboot.labs.lab69; + +import cn.iocoder.springboot.labs.lab69.intercept.UserServiceMethodInterceptor; +import cn.iocoder.springboot.labs.lab69.service.UserServiceImpl; +import net.sf.cglib.proxy.Enhancer; + +public class TestProxyMain { + + public static void main(String[] args) { + // 创建 cglib 增强对象 + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(UserServiceImpl.class); // 设置父类 + enhancer.setCallback(new UserServiceMethodInterceptor()); + // 创建代理 + UserServiceImpl userService = (UserServiceImpl) enhancer.create(); + userService.create("yunai", "buzhidao"); + } + +} diff --git a/lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/intercept/UserServiceMethodInterceptor.java b/lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/intercept/UserServiceMethodInterceptor.java new file mode 100644 index 000000000..c607ee000 --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/intercept/UserServiceMethodInterceptor.java @@ -0,0 +1,17 @@ +package cn.iocoder.springboot.labs.lab69.intercept; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import java.lang.reflect.Method; + +public class UserServiceMethodInterceptor implements MethodInterceptor { + + public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + System.out.println("before invoke"); + Object ret = methodProxy.invokeSuper(object, args); + System.out.println("after invoke"); + return ret; + } + +} diff --git a/lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserServiceImpl.java b/lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserServiceImpl.java new file mode 100644 index 000000000..61a1f79f4 --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-cglib/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserServiceImpl.java @@ -0,0 +1,9 @@ +package cn.iocoder.springboot.labs.lab69.service; + +public class UserServiceImpl { + + public void create(String username, String password) { + System.out.println(String.format("登陆的用户名(%s) 密码(%s)", username, password)); + } + +} diff --git a/lab-69-proxy/lab-69-proxy-jdk/pom.xml b/lab-69-proxy/lab-69-proxy-jdk/pom.xml new file mode 100644 index 000000000..239401ba0 --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-jdk/pom.xml @@ -0,0 +1,22 @@ + + + + lab-69 + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-69-proxy-jdk + + + + commons-io + commons-io + 2.7 + + + + diff --git a/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/GenerateProxyMain.java b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/GenerateProxyMain.java new file mode 100644 index 000000000..1c57a1964 --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/GenerateProxyMain.java @@ -0,0 +1,25 @@ +package cn.iocoder.springboot.labs.lab69; + +import cn.iocoder.springboot.labs.lab69.service.UserServiceImpl; +import org.apache.commons.io.IOUtils; +import sun.misc.ProxyGenerator; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Proxy; + +/** + * 生成 JDK {@link Proxy} 的示例代码 + * + * 生成后,我们可以反编译查看具体的类 + */ +public class GenerateProxyMain { + + public static void main(String[] args) throws IOException { + // 生成字节码 + byte[] classFile = ProxyGenerator.generateProxyClass("$Proxy11", UserServiceImpl.class.getInterfaces()); + // 写入到磁盘 + IOUtils.write(classFile, new FileOutputStream("/Users/yunai/ls/$Proxy11.class")); + } + +} diff --git a/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/TestProxyMain.java b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/TestProxyMain.java new file mode 100644 index 000000000..b67f63793 --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/TestProxyMain.java @@ -0,0 +1,26 @@ +package cn.iocoder.springboot.labs.lab69; + +import cn.iocoder.springboot.labs.lab69.handler.UserServiceHandler; +import cn.iocoder.springboot.labs.lab69.service.UserService; +import cn.iocoder.springboot.labs.lab69.service.UserServiceImpl; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; + +/** + * 使用 JDK {@link Proxy} 实现一个动态代理的示例 + */ +public class TestProxyMain { + + public static void main(String[] args) { + // 创建 UserService 对象 + UserService userService = new UserServiceImpl(); + // JDK 处理器 + InvocationHandler handler = new UserServiceHandler(userService); + // 创建代理 + UserService userServiceProxy = (UserService) Proxy.newProxyInstance(TestProxyMain.class.getClassLoader(), userService.getClass().getInterfaces(), handler); + // 执行 + userServiceProxy.create("yunai", "buzhidao"); + } + +} diff --git a/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/handler/UserServiceHandler.java b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/handler/UserServiceHandler.java new file mode 100644 index 000000000..06d62cb19 --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/handler/UserServiceHandler.java @@ -0,0 +1,24 @@ +package cn.iocoder.springboot.labs.lab69.handler; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class UserServiceHandler implements InvocationHandler { + + /** + * 被代理的对象 + */ + private final Object object; + + public UserServiceHandler(Object object) { + this.object = object; + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + System.out.println("before invoke"); + Object ret = method.invoke(object, args); + System.out.println("after invoke"); + return ret; + } + +} diff --git a/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserService.java b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserService.java new file mode 100644 index 000000000..234b5dc48 --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserService.java @@ -0,0 +1,7 @@ +package cn.iocoder.springboot.labs.lab69.service; + +public interface UserService { + + void create(String username, String password); + +} diff --git a/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserServiceImpl.java b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserServiceImpl.java new file mode 100644 index 000000000..7bab724d2 --- /dev/null +++ b/lab-69-proxy/lab-69-proxy-jdk/src/main/java/cn/iocoder/springboot/labs/lab69/service/UserServiceImpl.java @@ -0,0 +1,9 @@ +package cn.iocoder.springboot.labs.lab69.service; + +public class UserServiceImpl implements UserService { + + public void create(String username, String password) { + System.out.println(String.format("登陆的用户名(%s) 密码(%s)", username, password)); + } + +} diff --git a/lab-69-proxy/pom.xml b/lab-69-proxy/pom.xml new file mode 100644 index 000000000..45f9b82d9 --- /dev/null +++ b/lab-69-proxy/pom.xml @@ -0,0 +1,20 @@ + + + + labs-parent + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-69 + pom + + lab-69-proxy-jdk + lab-69-proxy-cglib + + + + diff --git a/pom.xml b/pom.xml index 1127eda64..e9c2abdde 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,8 @@ + lab-69-proxy + From 7770689bea7fb70a575a439f64f27d506ba5fcc2 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 21 Nov 2020 12:48:08 +0800 Subject: [PATCH 07/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Swagger=20Dubbo=20?= =?UTF-8?q?=E5=88=B0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 + .../pom.xml | 60 +++++++++++++++++++ .../springdatarediswithjedis/Application.java | 8 +++ .../config/RedisConfiguration.java | 39 ++++++++++++ .../util/JSONUtil.java | 22 +++++++ .../src/main/resources/application.yml | 11 ++++ .../src/main/resources/redisson.yml | 0 .../springdatarediswithjedis/Test01.java | 47 +++++++++++++++ .../config/TestRedisConfiguration.java | 34 +++++++++++ lab-11-spring-data-redis/pom.xml | 1 + ...37\345\205\245\351\227\250\343\200\213.md" | 1 + pom.xml | 3 +- 12 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/pom.xml create mode 100644 lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/Application.java create mode 100644 lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/config/RedisConfiguration.java create mode 100644 lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/util/JSONUtil.java create mode 100644 lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/resources/application.yml create mode 100644 lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/resources/redisson.yml create mode 100644 lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/test/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/Test01.java create mode 100644 lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/test/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/config/TestRedisConfiguration.java create mode 100644 "lab-30/\343\200\212\350\212\213\351\201\223 Dubbo Swagger \345\277\253\351\200\237\345\205\245\351\227\250\343\200\213.md" diff --git a/README.md b/README.md index 9ee72fd2c..4211ecb18 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,7 @@ * [《芋道 Spring Cloud 服务网关 Spring Cloud Gateway 入门》](http://www.iocoder.cn/Spring-Cloud/Spring-Cloud-Gateway/?github) 对应 [labx-08-spring-cloud-gateway](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-08-spring-cloud-gateway) * [《芋道 Spring Cloud 链路追踪 SkyWalking 入门》](http://www.iocoder.cn/Spring-Cloud/SkyWalking/?github) 对应 [labx-14](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-14) * [《芋道 Dubbo Admin 快速入门》](http://www.iocoder.cn/Dubbo/Admin/?github) +* [《芋道 Dubbo Swagger 快速入门》](http://www.iocoder.cn/Dubbo/Swagger/?github) 对应 [swagger-dubbo](https://github.com/YunaiV/swagger-dubbo) # Spring Cloud 专栏 @@ -274,6 +275,7 @@ * [《芋道 Spring Boot Dubbo 入门》](http://www.iocoder.cn/Spring-Boot/Dubbo/?github) 对应 [lab-30](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-30) * [《芋道 Spring Cloud Alibaba 服务调用 Dubbo 入门》](http://www.iocoder.cn/Spring-Cloud-Alibaba/Dubbo/?github) 对应 [labx-07-spring-cloud-alibaba-dubbo](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-07-spring-cloud-alibaba-dubbo) * [《性能测试 —— Dubbo 基准测试》](http://www.iocoder.cn/Performance-Testing/Dubbo-benchmark/?github) +* [《芋道 Dubbo Swagger 快速入门》](http://www.iocoder.cn/Dubbo/Swagger/?github) 对应 [swagger-dubbo](https://github.com/YunaiV/swagger-dubbo) ## 注册中心 diff --git a/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/pom.xml b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/pom.xml new file mode 100644 index 000000000..2d50408c4 --- /dev/null +++ b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/pom.xml @@ -0,0 +1,60 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + 4.0.0 + + lab-07-spring-data-redis-unit-test + + + + + + org.redisson + redisson-spring-boot-starter + 3.11.3 + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.alibaba + fastjson + 1.2.61 + + + + + com.fasterxml.jackson.core + jackson-databind + + + + commons-io + commons-io + 2.6 + + + + + it.ozimov + embedded-redis + 0.7.2 + test + + + + + diff --git a/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/Application.java b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/Application.java new file mode 100644 index 000000000..ac6c60ce3 --- /dev/null +++ b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/Application.java @@ -0,0 +1,8 @@ +package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +//@EnableTransactionManagement +public class Application { +} diff --git a/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/config/RedisConfiguration.java b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/config/RedisConfiguration.java new file mode 100644 index 000000000..a78920725 --- /dev/null +++ b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/config/RedisConfiguration.java @@ -0,0 +1,39 @@ +package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.RedisSerializer; + +@Configuration +public class RedisConfiguration { + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory factory) { + // 创建 RedisTemplate 对象 + RedisTemplate template = new RedisTemplate<>(); + + // 设置开启事务支持 + template.setEnableTransactionSupport(true); + + // 设置 RedisConnection 工厂。😈 它就是实现多种 Java Redis 客户端接入的秘密工厂。感兴趣的胖友,可以自己去撸下。 + template.setConnectionFactory(factory); + + // 使用 String 序列化方式,序列化 KEY 。 + template.setKeySerializer(RedisSerializer.string()); + + // 使用 JSON 序列化方式(库是 Jackson ),序列化 VALUE 。 + template.setValueSerializer(RedisSerializer.json()); + return template; + } + + // Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); +// ObjectMapper objectMapper = new ObjectMapper();// <1> +//// objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); +//// objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); +// +// jackson2JsonRedisSerializer.setObjectMapper(objectMapper); +// template.setValueSerializer(jackson2JsonRedisSerializer); + +} diff --git a/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/util/JSONUtil.java b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/util/JSONUtil.java new file mode 100644 index 000000000..cea22f21a --- /dev/null +++ b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/util/JSONUtil.java @@ -0,0 +1,22 @@ +package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.util; + +import com.alibaba.fastjson.JSON; + +/** + * JSON 工具类 + */ +public class JSONUtil { + + public static T parseObject(String text, Class clazz) { + return JSON.parseObject(text, clazz); + } + + public static String toJSONString(Object javaObject) { + return JSON.toJSONString(javaObject); + } + + public static byte[] toJSONBytes(Object javaObject) { + return JSON.toJSONBytes(javaObject); + } + +} diff --git a/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/resources/application.yml b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/resources/application.yml new file mode 100644 index 000000000..742b2ad31 --- /dev/null +++ b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/resources/application.yml @@ -0,0 +1,11 @@ +spring: + # 对应 RedisProperties 类 + redis: + host: 127.0.0.1 + port: 6379 +# password: # Redis 服务器密码,默认为空。生产中,一定要设置 Redis 密码! + database: 0 # Redis 数据库号,默认为 0 。 + timeout: 0 # Redis 连接超时时间,单位:毫秒。 + # 对应 RedissonProperties 类 +# redisson: +# config: classpath:redisson.yml # 具体的每个配置项,见 org.redisson.config.Config 类。 diff --git a/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/resources/redisson.yml b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/main/resources/redisson.yml new file mode 100644 index 000000000..e69de29bb diff --git a/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/test/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/Test01.java b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/test/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/Test01.java new file mode 100644 index 000000000..98f573d2f --- /dev/null +++ b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/test/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/Test01.java @@ -0,0 +1,47 @@ +package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis; + +import cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.config.TestRedisConfiguration; +import org.junit.Assert; +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.dao.DataAccessException; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.core.RedisCallback; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestRedisConfiguration.class) +public class Test01 { + + @Autowired + private StringRedisTemplate stringRedisTemplate; + + @Autowired + private RedisTemplate redisTemplate; + +// @Autowired +// private RedisServer server; + + @Test + public void test01() { + // 写入 + stringRedisTemplate.opsForValue().set("yunai", "shuai"); + // 读取 + String value = stringRedisTemplate.opsForValue().get("yunai"); + Assert.assertEquals("值不匹配", "shuai", value); + + // 测试重启后读取 + redisTemplate.execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) throws DataAccessException { + connection.flushDb(); + return ""; + } + }); + } + +} diff --git a/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/test/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/config/TestRedisConfiguration.java b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/test/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/config/TestRedisConfiguration.java new file mode 100644 index 000000000..32086eef1 --- /dev/null +++ b/lab-11-spring-data-redis/lab-07-spring-data-redis-unit-test/src/test/java/cn/iocoder/springboot/labs/lab10/springdatarediswithjedis/config/TestRedisConfiguration.java @@ -0,0 +1,34 @@ +package cn.iocoder.springboot.labs.lab10.springdatarediswithjedis.config; + +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; +import org.springframework.boot.test.context.TestConfiguration; +import redis.embedded.RedisServer; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +@TestConfiguration +public class TestRedisConfiguration { + + private RedisServer redisServer; + + public TestRedisConfiguration(RedisProperties redisProperties) { + this.redisServer = new RedisServer(redisProperties.getPort()); + } + +// @Bean +// public RedisServer redisServer() { +// return redisServer; +// } + + @PostConstruct + public void postConstruct() { + redisServer.start(); + } + + @PreDestroy + public void preDestroy() { + redisServer.stop(); + } + +} diff --git a/lab-11-spring-data-redis/pom.xml b/lab-11-spring-data-redis/pom.xml index 7c6441236..4eb256c83 100644 --- a/lab-11-spring-data-redis/pom.xml +++ b/lab-11-spring-data-redis/pom.xml @@ -14,6 +14,7 @@ lab-07-spring-data-redis-with-jedis lab-07-spring-data-redis-with-redisson + lab-07-spring-data-redis-unit-test diff --git "a/lab-30/\343\200\212\350\212\213\351\201\223 Dubbo Swagger \345\277\253\351\200\237\345\205\245\351\227\250\343\200\213.md" "b/lab-30/\343\200\212\350\212\213\351\201\223 Dubbo Swagger \345\277\253\351\200\237\345\205\245\351\227\250\343\200\213.md" new file mode 100644 index 000000000..4be20bd8b --- /dev/null +++ "b/lab-30/\343\200\212\350\212\213\351\201\223 Dubbo Swagger \345\277\253\351\200\237\345\205\245\351\227\250\343\200\213.md" @@ -0,0 +1 @@ + diff --git a/pom.xml b/pom.xml index e9c2abdde..941039a93 100644 --- a/pom.xml +++ b/pom.xml @@ -76,8 +76,7 @@ - lab-69-proxy - + From 17a49ddae2b1ca0b8a3533d04b1bd1ba89db4cde Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 21 Nov 2020 16:37:47 +0800 Subject: [PATCH 08/29] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20JApiDocs=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab-24/lab-24-apidoc-japidocs/pom.xml | 31 +++++++++++ .../iocoder/springboot/lab24/Application.java | 13 +++++ .../springboot/lab24/TestJApiDocs.java | 22 ++++++++ .../lab24/controller/UserController.java | 52 +++++++++++++++++++ .../springboot/lab24/vo/UserCreateReqVO.java | 17 ++++++ .../springboot/lab24/vo/UserListReqVO.java | 13 +++++ .../springboot/lab24/vo/UserRespVO.java | 21 ++++++++ lab-24/pom.xml | 1 + pom.xml | 2 +- 9 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 lab-24/lab-24-apidoc-japidocs/pom.xml create mode 100644 lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/Application.java create mode 100644 lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/TestJApiDocs.java create mode 100644 lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/controller/UserController.java create mode 100644 lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserCreateReqVO.java create mode 100644 lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserListReqVO.java create mode 100644 lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserRespVO.java diff --git a/lab-24/lab-24-apidoc-japidocs/pom.xml b/lab-24/lab-24-apidoc-japidocs/pom.xml new file mode 100644 index 000000000..f1a946f4f --- /dev/null +++ b/lab-24/lab-24-apidoc-japidocs/pom.xml @@ -0,0 +1,31 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + 4.0.0 + + lab-24-apidoc-japidocs + + + + + org.springframework.boot + spring-boot-starter-web + + + + + io.github.yedaxia + japidocs + 1.4.4 + + + + + diff --git a/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/Application.java b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/Application.java new file mode 100644 index 000000000..cc795da46 --- /dev/null +++ b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/Application.java @@ -0,0 +1,13 @@ +package cn.iocoder.springboot.lab24; + +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/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/TestJApiDocs.java b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/TestJApiDocs.java new file mode 100644 index 000000000..fdeab6e54 --- /dev/null +++ b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/TestJApiDocs.java @@ -0,0 +1,22 @@ +package cn.iocoder.springboot.lab24; + +import io.github.yedaxia.apidocs.Docs; +import io.github.yedaxia.apidocs.DocsConfig; +import io.github.yedaxia.apidocs.plugin.markdown.MarkdownDocPlugin; + +public class TestJApiDocs { + + public static void main(String[] args) { + // 1. 创建生成文档的配置 + DocsConfig config = new DocsConfig(); + config.setProjectPath("/Users/yunai/Java/SpringBoot-Labs/lab-24/lab-24-apidoc-japidocs"); // 项目所在目录 + config.setDocsPath("/Users/yunai/Downloads/"); // 生成 HTML 接口文档的目标目录 + config.setAutoGenerate(true); // 是否给所有 Controller 生成接口文档 + config.setProjectName("示例项目"); // 项目名 + config.setApiVersion("V1.0"); // API 版本号 + config.addPlugin(new MarkdownDocPlugin()); // 使用 MD 插件,额外生成 MD 格式的接口文档 + // 2. 执行生成 HTML 接口文档 + Docs.buildHtmlDocs(config); + } + +} diff --git a/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/controller/UserController.java b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/controller/UserController.java new file mode 100644 index 000000000..da67b9808 --- /dev/null +++ b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/controller/UserController.java @@ -0,0 +1,52 @@ +package cn.iocoder.springboot.lab24.controller; + +import cn.iocoder.springboot.lab24.vo.UserCreateReqVO; +import cn.iocoder.springboot.lab24.vo.UserListReqVO; +import cn.iocoder.springboot.lab24.vo.UserRespVO; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 用户 API + */ +@RestController +@RequestMapping("/api/user/") +public class UserController { + + + /** + * 获得用户列表 + * + * @param listReqVO 列表筛选条件 + * @return 用户列表 + */ + @GetMapping("list") + public List list(UserListReqVO listReqVO){ + return null; + } + + /** + * 保存用户 + * + * @param createReqVO 创建用户信息 + * @return 用户编号 + */ + @PostMapping("save") + public Integer saveUser(@RequestBody UserCreateReqVO createReqVO){ + return 1; + } + + /** + * 删除指定编号的用户 + * + * @param id 用户编号 + * @return 是否成功 + */ + @DeleteMapping("delete") + public Boolean deleteUser(@RequestParam Long id){ + return true; + } + + +} diff --git a/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserCreateReqVO.java b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserCreateReqVO.java new file mode 100644 index 000000000..c5e82c8f8 --- /dev/null +++ b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserCreateReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.springboot.lab24.vo; + +/** + * 用户创建请求 VO + */ +public class UserCreateReqVO { + + /** + * 昵称 + */ + private String nickname; + /** + * 年龄 + */ + private Integer age; + +} diff --git a/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserListReqVO.java b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserListReqVO.java new file mode 100644 index 000000000..cb0f28624 --- /dev/null +++ b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserListReqVO.java @@ -0,0 +1,13 @@ +package cn.iocoder.springboot.lab24.vo; + +/** + * 用户列表请求 VO + */ +public class UserListReqVO { + + /** + * 昵称,模糊匹配 + */ + private String nickname; + +} diff --git a/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserRespVO.java b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserRespVO.java new file mode 100644 index 000000000..2dda156c4 --- /dev/null +++ b/lab-24/lab-24-apidoc-japidocs/src/main/java/cn/iocoder/springboot/lab24/vo/UserRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.springboot.lab24.vo; + +/** + * 用户响应 VO + */ +public class UserRespVO { + + /** + * 用户编号 + */ + private Integer id; + /** + * 昵称 + */ + private String nickname; + /** + * 年龄 + */ + private Integer age; + +} diff --git a/lab-24/pom.xml b/lab-24/pom.xml index e312a1268..1c5c69a04 100644 --- a/lab-24/pom.xml +++ b/lab-24/pom.xml @@ -14,6 +14,7 @@ lab-24-apidoc-swagger lab-24-apidoc-swagger-knife4j + lab-24-apidoc-japidocs diff --git a/pom.xml b/pom.xml index 941039a93..e37f78976 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ - + lab-24 From ce180d38f8fa80446f609c4e1567df092fc4f77b Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 21 Nov 2020 21:29:26 +0800 Subject: [PATCH 09/29] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20JApiDocs=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + ...346\241\243 JApiDocs \345\205\245\351\227\250\343\200\213.md" | 1 + 2 files changed, 2 insertions(+) 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 JApiDocs \345\205\245\351\227\250\343\200\213.md" diff --git a/README.md b/README.md index 4211ecb18..e5be0dddf 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ * [《芋道 Spring Boot WebSocket 入门》](http://www.iocoder.cn/Spring-Boot/WebSocket/?github) 对应 [lab-25](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-25) * [《性能测试 —— 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) ## RPC 开发 diff --git "a/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 JApiDocs \345\205\245\351\227\250\343\200\213.md" "b/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 JApiDocs \345\205\245\351\227\250\343\200\213.md" new file mode 100644 index 000000000..c502e16b4 --- /dev/null +++ "b/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 JApiDocs \345\205\245\351\227\250\343\200\213.md" @@ -0,0 +1 @@ + From c39d559f528182b12ef16521d9ea74c19b922943 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 28 Nov 2020 10:47:28 +0800 Subject: [PATCH 10/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Swagger=20Starter=20?= =?UTF-8?q?=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-24/lab-24-apidoc-swagger-starter/pom.xml | 30 ++++++++ .../iocoder/springboot/lab24/Application.java | 13 ++++ .../lab24/config/SwaggerConfiguration.java | 41 +++++++++++ .../lab24/controller/UserController.java | 68 +++++++++++++++++++ .../springboot/lab24/dto/UserAddDTO.java | 32 +++++++++ .../springboot/lab24/dto/UserUpdateDTO.java | 43 ++++++++++++ .../iocoder/springboot/lab24/vo/UserVO.java | 32 +++++++++ .../src/main/resources/application.yaml | 5 ++ lab-24/pom.xml | 1 + 9 files changed, 265 insertions(+) create mode 100644 lab-24/lab-24-apidoc-swagger-starter/pom.xml create mode 100644 lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/Application.java create mode 100644 lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/config/SwaggerConfiguration.java create mode 100644 lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/controller/UserController.java create mode 100644 lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/dto/UserAddDTO.java create mode 100644 lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/dto/UserUpdateDTO.java create mode 100644 lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/vo/UserVO.java create mode 100644 lab-24/lab-24-apidoc-swagger-starter/src/main/resources/application.yaml diff --git a/lab-24/lab-24-apidoc-swagger-starter/pom.xml b/lab-24/lab-24-apidoc-swagger-starter/pom.xml new file mode 100644 index 000000000..91dbbee69 --- /dev/null +++ b/lab-24/lab-24-apidoc-swagger-starter/pom.xml @@ -0,0 +1,30 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 2.2.11.RELEASE + + + 4.0.0 + + lab-24-apidoc-swagger-starter + + + + + org.springframework.boot + spring-boot-starter-web + + + + + io.springfox + springfox-boot-starter + 3.0.0 + + + + diff --git a/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/Application.java b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/Application.java new file mode 100644 index 000000000..cc795da46 --- /dev/null +++ b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/Application.java @@ -0,0 +1,13 @@ +package cn.iocoder.springboot.lab24; + +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/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/config/SwaggerConfiguration.java b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/config/SwaggerConfiguration.java new file mode 100644 index 000000000..1cc1fddd4 --- /dev/null +++ b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/config/SwaggerConfiguration.java @@ -0,0 +1,41 @@ +package cn.iocoder.springboot.lab24.config; + +import org.springframework.context.annotation.Bean; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +//@Configuration +// @EnableSwagger2 无需使用该注解 +public class SwaggerConfiguration { + + @Bean + public Docket createRestApi() { + // 创建 Docket 对象 + return new Docket(DocumentationType.SWAGGER_2) // 文档类型,使用 Swagger2 + .apiInfo(this.apiInfo()) // 设置 API 信息 + // 扫描 Controller 包路径,获得 API 接口 + .select() + .apis(RequestHandlerSelectors.basePackage("cn.iocoder.springboot.lab24.controller")) + .paths(PathSelectors.any()) + // 构建出 Docket 对象 + .build(); + } + + /** + * 创建 API 信息 + */ + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("测试接口文档示例") + .description("我是一段描述") + .version("1.0.0") // 版本号 + .contact(new Contact("芋艿", "http://www.iocoder.cn", "zhijiantianya@gmail.com")) // 联系人 + .build(); + } + +} diff --git a/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/controller/UserController.java b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/controller/UserController.java new file mode 100644 index 000000000..6ed0a76f4 --- /dev/null +++ b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/controller/UserController.java @@ -0,0 +1,68 @@ +package cn.iocoder.springboot.lab24.controller; + +import cn.iocoder.springboot.lab24.dto.UserAddDTO; +import cn.iocoder.springboot.lab24.dto.UserUpdateDTO; +import cn.iocoder.springboot.lab24.vo.UserVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +@RestController +@RequestMapping("/users") +@Api(tags = "用户 API 接口") +public class UserController { + + @GetMapping("/list") + @ApiOperation(value = "查询用户列表", notes = "目前仅仅是作为测试,所以返回用户全列表") + public List list() { + // 查询列表 + List result = new ArrayList<>(); + result.add(new UserVO().setId(1).setUsername("yudaoyuanma")); + result.add(new UserVO().setId(2).setUsername("woshiyutou")); + result.add(new UserVO().setId(3).setUsername("chifanshuijiao")); + // 返回列表 + return result; + } + + @GetMapping("/get") + @ApiOperation("获得指定用户编号的用户") + @ApiImplicitParam(name = "id", value = "用户编号", paramType = "query", dataTypeClass = Integer.class, required = true, example = "1024") + public UserVO get(@RequestParam("id") Integer id) { + // 查询并返回用户 + return new UserVO().setId(id).setUsername(UUID.randomUUID().toString()); + } + + @PostMapping("add") + @ApiOperation("添加用户") + public Integer add(UserAddDTO addDTO) { + // 插入用户记录,返回编号 + Integer returnId = UUID.randomUUID().hashCode(); + // 返回用户编号 + return returnId; + } + + @PostMapping("/update") + @ApiOperation("更新指定用户编号的用户") + public Boolean update(UserUpdateDTO updateDTO) { + // 更新用户记录 + Boolean success = true; + // 返回更新是否成功 + return success; + } + + @PostMapping("/delete") + @ApiOperation(value = "删除指定用户编号的用户") + @ApiImplicitParam(name = "id", value = "用户编号", paramType = "query", dataTypeClass = Integer.class, required = true, example = "1024") + public Boolean delete(@RequestParam("id") Integer id) { + // 删除用户记录 + Boolean success = false; + // 返回是否更新成功 + return success; + } + +} diff --git a/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/dto/UserAddDTO.java b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/dto/UserAddDTO.java new file mode 100644 index 000000000..af181e690 --- /dev/null +++ b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/dto/UserAddDTO.java @@ -0,0 +1,32 @@ +package cn.iocoder.springboot.lab24.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel("用户添加 DTO") +public class UserAddDTO { + + @ApiModelProperty(value = "账号", required = true, example = "yudaoyuanma") + private String username; + @ApiModelProperty(value = "密码", required = true, example = "nicai") + private String password; + + public String getUsername() { + return username; + } + + public UserAddDTO setUsername(String username) { + this.username = username; + return this; + } + + public String getPassword() { + return password; + } + + public UserAddDTO setPassword(String password) { + this.password = password; + return this; + } + +} diff --git a/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/dto/UserUpdateDTO.java b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/dto/UserUpdateDTO.java new file mode 100644 index 000000000..3c92aeb8b --- /dev/null +++ b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/dto/UserUpdateDTO.java @@ -0,0 +1,43 @@ +package cn.iocoder.springboot.lab24.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel("用户更新 DTO") +public class UserUpdateDTO { + + @ApiModelProperty(value = "用户编号", required = true, example = "1024") + private Integer id; + @ApiModelProperty(value = "账号", required = true, example = "yudaoyuanma") + private String username; + @ApiModelProperty(value = "密码", required = true, example = "nicai") + private String password; + + public Integer getId() { + return id; + } + + public UserUpdateDTO setId(Integer id) { + this.id = id; + return this; + } + + public String getUsername() { + return username; + } + + public UserUpdateDTO setUsername(String username) { + this.username = username; + return this; + } + + public String getPassword() { + return password; + } + + public UserUpdateDTO setPassword(String password) { + this.password = password; + return this; + } + +} diff --git a/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/vo/UserVO.java b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/vo/UserVO.java new file mode 100644 index 000000000..4917916d9 --- /dev/null +++ b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/vo/UserVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.springboot.lab24.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel("用户 VO") +public class UserVO { + + @ApiModelProperty(value = "用户编号", required = true, example = "1024") + private Integer id; + @ApiModelProperty(value = "账号", required = true, example = "yudaoyuanma") + private String username; + + public Integer getId() { + return id; + } + + public UserVO setId(Integer id) { + this.id = id; + return this; + } + + public String getUsername() { + return username; + } + + public UserVO setUsername(String username) { + this.username = username; + return this; + } + +} diff --git a/lab-24/lab-24-apidoc-swagger-starter/src/main/resources/application.yaml b/lab-24/lab-24-apidoc-swagger-starter/src/main/resources/application.yaml new file mode 100644 index 000000000..c4573845e --- /dev/null +++ b/lab-24/lab-24-apidoc-swagger-starter/src/main/resources/application.yaml @@ -0,0 +1,5 @@ +# 对应 SpringfoxConfigurationProperties 配置类 +springfox: + documentation: + swagger-ui: + enabled: true # 是否开启 Swagger UI 功能。默认为 true diff --git a/lab-24/pom.xml b/lab-24/pom.xml index 1c5c69a04..7d0bf03c5 100644 --- a/lab-24/pom.xml +++ b/lab-24/pom.xml @@ -15,6 +15,7 @@ lab-24-apidoc-swagger lab-24-apidoc-swagger-knife4j lab-24-apidoc-japidocs + lab-24-apidoc-swagger-starter From b8e503e4a319d6033524f82910b7f6493c994659 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 28 Nov 2020 19:02:58 +0800 Subject: [PATCH 11/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Swagger=20Starter=20?= =?UTF-8?q?=E7=9A=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../iocoder/springboot/lab24/config/SwaggerConfiguration.java | 3 ++- ...43 Swagger Starter \345\205\245\351\227\250\343\200\213.md" | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) 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 Swagger Starter \345\205\245\351\227\250\343\200\213.md" diff --git a/README.md b/README.md index e5be0dddf..d04471af9 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ * [《芋道 Spring Boot WebFlux 入门》](http://www.iocoder.cn/Spring-Boot/WebFlux/?github) 对应 [lab-27](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-27) * [《芋道 Spring Boot 分布式 Session 入门》](http://www.iocoder.cn/Spring-Boot/Distributed-Session/?github) 对应 [lab-26](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-26) * [《芋道 Spring Boot API 接口文档 Swagger 入门》](http://www.iocoder.cn/Spring-Boot/Swagger/?github) 对应 [lab-24](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-24) +* [《芋道 Spring Boot API 接口文档 Swagger Starter 入门》](http://www.iocoder.cn/Spring-Boot/Swagger-Starter/?github) 对应 [lab-24](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-24) * [《芋道 Spring Boot 参数校验 Validation 入门》](http://www.iocoder.cn/Spring-Boot/Validation/?github) 对应 [lab-22](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-22) * [《芋道 Spring Boot WebSocket 入门》](http://www.iocoder.cn/Spring-Boot/WebSocket/?github) 对应 [lab-25](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-25) * [《性能测试 —— 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) diff --git a/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/config/SwaggerConfiguration.java b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/config/SwaggerConfiguration.java index 1cc1fddd4..5ddcef502 100644 --- a/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/config/SwaggerConfiguration.java +++ b/lab-24/lab-24-apidoc-swagger-starter/src/main/java/cn/iocoder/springboot/lab24/config/SwaggerConfiguration.java @@ -1,6 +1,7 @@ package cn.iocoder.springboot.lab24.config; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; @@ -9,7 +10,7 @@ import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; -//@Configuration +@Configuration // @EnableSwagger2 无需使用该注解 public class SwaggerConfiguration { diff --git "a/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 Swagger Starter \345\205\245\351\227\250\343\200\213.md" "b/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 Swagger Starter \345\205\245\351\227\250\343\200\213.md" new file mode 100644 index 000000000..e080075c0 --- /dev/null +++ "b/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 Swagger Starter \345\205\245\351\227\250\343\200\213.md" @@ -0,0 +1 @@ + From 7ceb2933f5cd8bb4db4f16d2442b0c8dd6359a3f Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 12 Dec 2020 11:59:56 +0800 Subject: [PATCH 12/29] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20screw=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-70-db-doc/lab-70-db-doc-screw-01/pom.xml | 37 ++++++++ .../src/main/java/ScrewMain.java | 84 +++++++++++++++++++ lab-70-db-doc/pom.xml | 19 +++++ pom.xml | 3 +- 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 lab-70-db-doc/lab-70-db-doc-screw-01/pom.xml create mode 100644 lab-70-db-doc/lab-70-db-doc-screw-01/src/main/java/ScrewMain.java create mode 100644 lab-70-db-doc/pom.xml diff --git a/lab-70-db-doc/lab-70-db-doc-screw-01/pom.xml b/lab-70-db-doc/lab-70-db-doc-screw-01/pom.xml new file mode 100644 index 000000000..16c284de1 --- /dev/null +++ b/lab-70-db-doc/lab-70-db-doc-screw-01/pom.xml @@ -0,0 +1,37 @@ + + + + lab-70-db-doc + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-70-db-doc-screw-01 + + + + + + + cn.smallbun.screw + screw-core + 1.0.5 + + + + + com.zaxxer + HikariCP + 3.4.5 + + + mysql + mysql-connector-java + 8.0.22 + + + + diff --git a/lab-70-db-doc/lab-70-db-doc-screw-01/src/main/java/ScrewMain.java b/lab-70-db-doc/lab-70-db-doc-screw-01/src/main/java/ScrewMain.java new file mode 100644 index 000000000..64b11c354 --- /dev/null +++ b/lab-70-db-doc/lab-70-db-doc-screw-01/src/main/java/ScrewMain.java @@ -0,0 +1,84 @@ +import cn.smallbun.screw.core.Configuration; +import cn.smallbun.screw.core.engine.EngineConfig; +import cn.smallbun.screw.core.engine.EngineFileType; +import cn.smallbun.screw.core.engine.EngineTemplateType; +import cn.smallbun.screw.core.execute.DocumentationExecute; +import cn.smallbun.screw.core.process.ProcessConfig; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +import javax.sql.DataSource; +import java.util.Arrays; +import java.util.Collections; + +public class ScrewMain { + + private static final String DB_URL = "jdbc:mysql://400-infra.server.iocoder.cn:3306"; + private static final String DB_NAME = "mall_system"; + private static final String DB_USERNAME = "root"; + private static final String DB_PASSWORD = "3WLiVUBEwTbvAfsh"; + + private static final String FILE_OUTPUT_DIR = "/Users/yunai/screw_test"; + private static final EngineFileType FILE_OUTPUT_TYPE = EngineFileType.HTML; // 可以设置 WORD 或者 Markdown 格式 + private static final String DOC_FILE_NAME = "数据库文档"; + private static final String DOC_VERSION = "1.0.0"; + private static final String DOC_DESCRIPTION = "文档描述"; + + public static void main(String[] args) { + // 创建 screw 的配置 + Configuration config = Configuration.builder() + .version(DOC_VERSION) // 版本 + .description(DOC_DESCRIPTION) // 描述 + .dataSource(buildDataSource()) // 数据源 + .engineConfig(buildEngineConfig()) // 引擎配置 + .produceConfig(buildProcessConfig()) // 处理配置 + .build(); + + // 执行 screw,生成数据库文档 + new DocumentationExecute(config).execute(); + } + + /** + * 创建数据源 + */ + private static DataSource buildDataSource() { + // 创建 HikariConfig 配置类 + HikariConfig hikariConfig = new HikariConfig(); + hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver"); + hikariConfig.setJdbcUrl(DB_URL + "/" + DB_NAME); + hikariConfig.setUsername(DB_USERNAME); + hikariConfig.setPassword(DB_PASSWORD); + hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息 + // 创建数据源 + return new HikariDataSource(hikariConfig); + } + + /** + * 创建 screw 的引擎配置 + */ + private static EngineConfig buildEngineConfig() { + return EngineConfig.builder() + .fileOutputDir(FILE_OUTPUT_DIR) // 生成文件路径 + .openOutputDir(false) // 打开目录 + .fileType(FILE_OUTPUT_TYPE) // 文件类型 + .produceType(EngineTemplateType.freemarker) // 文件类型 + .fileName(DOC_FILE_NAME) // 自定义文件名称 + .build(); + } + + /** + * 创建 screw 的处理配置,一般可忽略 + * 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置 + */ + private static ProcessConfig buildProcessConfig() { + return ProcessConfig.builder() + .designatedTableName(Collections.emptyList()) // 根据名称指定表生成 + .designatedTablePrefix(Collections.emptyList()) //根据表前缀生成 + .designatedTableSuffix(Collections.emptyList()) // 根据表后缀生成 + .ignoreTableName(Arrays.asList("test_user", "test_group")) // 忽略表名 + .ignoreTablePrefix(Collections.singletonList("test_")) // 忽略表前缀 + .ignoreTableSuffix(Collections.singletonList("_test")) // 忽略表后缀 + .build(); + } + +} diff --git a/lab-70-db-doc/pom.xml b/lab-70-db-doc/pom.xml new file mode 100644 index 000000000..926091822 --- /dev/null +++ b/lab-70-db-doc/pom.xml @@ -0,0 +1,19 @@ + + + + labs-parent + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-70-db-doc + pom + + + lab-70-db-doc-screw-01 + + + diff --git a/pom.xml b/pom.xml index e37f78976..29ec927c3 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ - lab-24 + @@ -77,6 +77,7 @@ + lab-70-db-doc From ab27b89a71011809bb0d5c58b23b8bf8dbf8a5be Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 12 Dec 2020 20:07:52 +0800 Subject: [PATCH 13/29] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20screw=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-70-db-doc/lab-70-db-doc-screw-01/pom.xml | 2 - .../src/main/java/ScrewMain.java | 2 +- lab-70-db-doc/lab-70-db-doc-screw-02/pom.xml | 60 +++++++++++++++++++ lab-70-db-doc/pom.xml | 1 + 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 lab-70-db-doc/lab-70-db-doc-screw-02/pom.xml diff --git a/lab-70-db-doc/lab-70-db-doc-screw-01/pom.xml b/lab-70-db-doc/lab-70-db-doc-screw-01/pom.xml index 16c284de1..9274e03a5 100644 --- a/lab-70-db-doc/lab-70-db-doc-screw-01/pom.xml +++ b/lab-70-db-doc/lab-70-db-doc-screw-01/pom.xml @@ -11,8 +11,6 @@ lab-70-db-doc-screw-01 - - diff --git a/lab-70-db-doc/lab-70-db-doc-screw-01/src/main/java/ScrewMain.java b/lab-70-db-doc/lab-70-db-doc-screw-01/src/main/java/ScrewMain.java index 64b11c354..9066c7a65 100644 --- a/lab-70-db-doc/lab-70-db-doc-screw-01/src/main/java/ScrewMain.java +++ b/lab-70-db-doc/lab-70-db-doc-screw-01/src/main/java/ScrewMain.java @@ -19,7 +19,7 @@ public class ScrewMain { private static final String DB_PASSWORD = "3WLiVUBEwTbvAfsh"; private static final String FILE_OUTPUT_DIR = "/Users/yunai/screw_test"; - private static final EngineFileType FILE_OUTPUT_TYPE = EngineFileType.HTML; // 可以设置 WORD 或者 Markdown 格式 + private static final EngineFileType FILE_OUTPUT_TYPE = EngineFileType.HTML; // 可以设置 Word 或者 Markdown 格式 private static final String DOC_FILE_NAME = "数据库文档"; private static final String DOC_VERSION = "1.0.0"; private static final String DOC_DESCRIPTION = "文档描述"; diff --git a/lab-70-db-doc/lab-70-db-doc-screw-02/pom.xml b/lab-70-db-doc/lab-70-db-doc-screw-02/pom.xml new file mode 100644 index 000000000..1cbcc0718 --- /dev/null +++ b/lab-70-db-doc/lab-70-db-doc-screw-02/pom.xml @@ -0,0 +1,60 @@ + + + + lab-70-db-doc + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-70-db-doc-screw-02 + + + + + cn.smallbun.screw + screw-maven-plugin + 1.0.5 + + + + com.zaxxer + HikariCP + 3.4.5 + + + mysql + mysql-connector-java + 8.0.22 + + + + + com.mysql.cj.jdbc.Driver + jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_system + root + 3WLiVUBEwTbvAfsh + + HTML + 数据库文档 + 测试文档名称 + 数据库文档生成 + ${project.version} + false + freemarker + + + + compile + + run + + + + + + + + diff --git a/lab-70-db-doc/pom.xml b/lab-70-db-doc/pom.xml index 926091822..1efc92b6f 100644 --- a/lab-70-db-doc/pom.xml +++ b/lab-70-db-doc/pom.xml @@ -14,6 +14,7 @@ lab-70-db-doc-screw-01 + lab-70-db-doc-screw-02 From 86723d75a99f43b6b671f2dd9fa207b3d40ef5f1 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 12 Dec 2020 22:04:57 +0800 Subject: [PATCH 14/29] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20screw=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-70-db-doc/lab-70-db-doc-screw-03/pom.xml | 40 +++++++++++ .../src/main/java/ScrewMain.java | 72 +++++++++++++++++++ lab-70-db-doc/pom.xml | 1 + 3 files changed, 113 insertions(+) create mode 100644 lab-70-db-doc/lab-70-db-doc-screw-03/pom.xml create mode 100644 lab-70-db-doc/lab-70-db-doc-screw-03/src/main/java/ScrewMain.java diff --git a/lab-70-db-doc/lab-70-db-doc-screw-03/pom.xml b/lab-70-db-doc/lab-70-db-doc-screw-03/pom.xml new file mode 100644 index 000000000..bdeee8947 --- /dev/null +++ b/lab-70-db-doc/lab-70-db-doc-screw-03/pom.xml @@ -0,0 +1,40 @@ + + + + lab-70-db-doc + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-70-db-doc-screw-03 + + + + + cn.smallbun.screw + screw-core + 1.0.5 + + + cn.smallbun.screw + screw-extension + 1.0.5 + + + + + com.zaxxer + HikariCP + 3.4.5 + + + mysql + mysql-connector-java + 8.0.22 + + + + diff --git a/lab-70-db-doc/lab-70-db-doc-screw-03/src/main/java/ScrewMain.java b/lab-70-db-doc/lab-70-db-doc-screw-03/src/main/java/ScrewMain.java new file mode 100644 index 000000000..3a144630f --- /dev/null +++ b/lab-70-db-doc/lab-70-db-doc-screw-03/src/main/java/ScrewMain.java @@ -0,0 +1,72 @@ +import cn.smallbun.screw.core.Configuration; +import cn.smallbun.screw.core.engine.EngineConfig; +import cn.smallbun.screw.core.engine.EngineFileType; +import cn.smallbun.screw.core.engine.EngineTemplateType; +import cn.smallbun.screw.core.execute.DocumentationExecute; +import cn.smallbun.screw.core.process.ProcessConfig; +import cn.smallbun.screw.extension.pojo.PojoConfiguration; +import cn.smallbun.screw.extension.pojo.execute.PojoExecute; +import cn.smallbun.screw.extension.pojo.strategy.HumpNameStrategy; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +import javax.sql.DataSource; +import java.util.Arrays; +import java.util.Collections; + +public class ScrewMain { + + private static final String DB_URL = "jdbc:mysql://400-infra.server.iocoder.cn:3306"; + private static final String DB_NAME = "mall_system"; + private static final String DB_USERNAME = "root"; + private static final String DB_PASSWORD = "3WLiVUBEwTbvAfsh"; + + private static final String FILE_OUTPUT_DIR = "/Users/yunai/screw_test"; + private static final String JAVA_CLASS_PACKAGE = "cn.iocoder.dataobject"; + + public static void main(String[] args) { + // 创建 screw 的配置 + PojoConfiguration config = PojoConfiguration.builder() + .path(FILE_OUTPUT_DIR) // 生成 POJO 相关的目录 + .packageName(JAVA_CLASS_PACKAGE) // 包名 + .nameStrategy(new HumpNameStrategy()) // 包名策略 + .useLombok(false) // 是否使用 Lombok + .dataSource(buildDataSource()) // 数据源 + .processConfig(buildProcessConfig()) // 处理配置 + .build(); + + // 执行 screw,生成 POJO 实体类 + new PojoExecute(config).execute(); + } + + /** + * 创建数据源 + */ + private static DataSource buildDataSource() { + // 创建 HikariConfig 配置类 + HikariConfig hikariConfig = new HikariConfig(); + hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver"); + hikariConfig.setJdbcUrl(DB_URL + "/" + DB_NAME); + hikariConfig.setUsername(DB_USERNAME); + hikariConfig.setPassword(DB_PASSWORD); + hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息 + // 创建数据源 + return new HikariDataSource(hikariConfig); + } + + /** + * 创建 screw 的处理配置,一般可忽略 + * 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置 + */ + private static ProcessConfig buildProcessConfig() { + return ProcessConfig.builder() + .designatedTableName(Collections.emptyList()) // 根据名称指定表生成 + .designatedTablePrefix(Collections.emptyList()) //根据表前缀生成 + .designatedTableSuffix(Collections.emptyList()) // 根据表后缀生成 + .ignoreTableName(Arrays.asList("test_user", "test_group")) // 忽略表名 + .ignoreTablePrefix(Collections.singletonList("test_")) // 忽略表前缀 + .ignoreTableSuffix(Collections.singletonList("_test")) // 忽略表后缀 + .build(); + } + +} diff --git a/lab-70-db-doc/pom.xml b/lab-70-db-doc/pom.xml index 1efc92b6f..55f7b46cf 100644 --- a/lab-70-db-doc/pom.xml +++ b/lab-70-db-doc/pom.xml @@ -15,6 +15,7 @@ lab-70-db-doc-screw-01 lab-70-db-doc-screw-02 + lab-70-db-doc-screw-03 From 8652a4c4f511fc84595c75abb81684bf132ace28 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 12 Dec 2020 22:58:13 +0800 Subject: [PATCH 15/29] =?UTF-8?q?=E3=80=8A=E8=8A=8B=E9=81=93=20Spring=20Bo?= =?UTF-8?q?ot=20=E6=95=B0=E6=8D=AE=E8=A1=A8=E7=BB=93=E6=9E=84=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E3=80=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../lab-70-db-doc-screw-03/src/main/java/ScrewMain.java | 5 ----- ...3\223\346\236\204\346\226\207\346\241\243\343\200\213.md" | 1 + 3 files changed, 2 insertions(+), 5 deletions(-) create mode 100644 "lab-70-db-doc/\343\200\212\350\212\213\351\201\223 Spring Boot \346\225\260\346\215\256\350\241\250\347\273\223\346\236\204\346\226\207\346\241\243\343\200\213.md" diff --git a/README.md b/README.md index d04471af9..be9cac702 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ * [《芋道 Spring Boot 多数据源(读写分离)入门》](http://www.iocoder.cn/Spring-Boot/dynamic-datasource/?github) 对应 [lab-17](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-17) * [《芋道 Spring Boot 分库分表入门》](http://www.iocoder.cn/Spring-Boot/sharding-datasource/?github) 对应 [lab-18](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-18) * [《芋道 Spring Boot 数据库版本管理入门》](http://www.iocoder.cn/Spring-Boot/database-version-control/?github) 对应 [lab-20](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-20) +* [《芋道 Spring Boot 数据表结构文档》](http://www.iocoder.cn/Spring-Boot/DB-Doc-screw/?github) 对应 [lab-70-db-doc](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-70-db-doc) **非关系数据库** diff --git a/lab-70-db-doc/lab-70-db-doc-screw-03/src/main/java/ScrewMain.java b/lab-70-db-doc/lab-70-db-doc-screw-03/src/main/java/ScrewMain.java index 3a144630f..ddc65ef89 100644 --- a/lab-70-db-doc/lab-70-db-doc-screw-03/src/main/java/ScrewMain.java +++ b/lab-70-db-doc/lab-70-db-doc-screw-03/src/main/java/ScrewMain.java @@ -1,8 +1,3 @@ -import cn.smallbun.screw.core.Configuration; -import cn.smallbun.screw.core.engine.EngineConfig; -import cn.smallbun.screw.core.engine.EngineFileType; -import cn.smallbun.screw.core.engine.EngineTemplateType; -import cn.smallbun.screw.core.execute.DocumentationExecute; import cn.smallbun.screw.core.process.ProcessConfig; import cn.smallbun.screw.extension.pojo.PojoConfiguration; import cn.smallbun.screw.extension.pojo.execute.PojoExecute; diff --git "a/lab-70-db-doc/\343\200\212\350\212\213\351\201\223 Spring Boot \346\225\260\346\215\256\350\241\250\347\273\223\346\236\204\346\226\207\346\241\243\343\200\213.md" "b/lab-70-db-doc/\343\200\212\350\212\213\351\201\223 Spring Boot \346\225\260\346\215\256\350\241\250\347\273\223\346\236\204\346\226\207\346\241\243\343\200\213.md" new file mode 100644 index 000000000..b8566f54e --- /dev/null +++ "b/lab-70-db-doc/\343\200\212\350\212\213\351\201\223 Spring Boot \346\225\260\346\215\256\350\241\250\347\273\223\346\236\204\346\226\207\346\241\243\343\200\213.md" @@ -0,0 +1 @@ + From bfc48cf06e81801b66c723cb591fd6231cf6d198 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 19 Dec 2020 20:03:29 +0800 Subject: [PATCH 16/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20IDEA=20HTTP=20Client?= =?UTF-8?q?=20=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lab-71-idea-http-client/pom.xml | 23 +++++++++ .../iocoder/springboot/lab71/Application.java | 13 +++++ .../lab71/controller/UserController.http | 18 +++++++ .../lab71/controller/UserController.java | 50 +++++++++++++++++++ .../springboot/lab71/vo/UserUpdateVO.java | 43 ++++++++++++++++ lab-71-http-debug/pom.xml | 18 +++++++ pom.xml | 3 +- 7 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 lab-71-http-debug/lab-71-idea-http-client/pom.xml create mode 100644 lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/Application.java create mode 100644 lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.http create mode 100644 lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java create mode 100644 lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/vo/UserUpdateVO.java create mode 100644 lab-71-http-debug/pom.xml diff --git a/lab-71-http-debug/lab-71-idea-http-client/pom.xml b/lab-71-http-debug/lab-71-idea-http-client/pom.xml new file mode 100644 index 000000000..04b29abd9 --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/pom.xml @@ -0,0 +1,23 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 2.2.1.RELEASE + + + 4.0.0 + + lab-71-idea-http-client + + + + + org.springframework.boot + spring-boot-starter-web + + + + diff --git a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/Application.java b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/Application.java new file mode 100644 index 000000000..ba31cf786 --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/Application.java @@ -0,0 +1,13 @@ +package cn.iocoder.springboot.lab71; + +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/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.http b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.http new file mode 100644 index 000000000..0b6862587 --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.http @@ -0,0 +1,18 @@ +### 测试 /user/login:登陆成功 +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +### 测试 /user/get-current:获取成功 +GET http://127.0.0.1:8080/user/get-current +Authorization: token001 + +### 测试 /user/update:更新成功 +POST http://127.0.0.1:8080/user/update +Content-Type: application/json + +{ + "nickname": "我是昵称", + "gender": 1 +} diff --git a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java new file mode 100644 index 000000000..48c994511 --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java @@ -0,0 +1,50 @@ +package cn.iocoder.springboot.lab71.controller; + +import cn.iocoder.springboot.lab71.vo.UserUpdateVO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.Map; + +/** + * 用户 Controller + * + * 示例代码,纯粹为了演示。 + */ +@RestController +public class UserController { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @PostMapping("/user/login") + public Map login(@RequestParam("username") String username, + @RequestParam("password") String password) { + if ("yudaoyuanma".equals(username) && "123456".equals(password)) { + Map tokenMap = new HashMap<>(); + tokenMap.put("userId", 1); + tokenMap.put("token", "token001"); + return tokenMap; + } + throw new RuntimeException("小朋友,你的账号密码不正确哟!"); + } + + @GetMapping("/user/get-current") + public Map getCurrentUser(@RequestHeader("Authorization") String authorization) { + if ("token001".equals(authorization)) { + Map userInfo = new HashMap<>(); + userInfo.put("id", 1); + userInfo.put("gender", 1); + return userInfo; + } + throw new RuntimeException("小朋友,你没有登录哟!"); + } + + @PostMapping("/user/update") + public Boolean update(@RequestBody UserUpdateVO updateVO) { + logger.info("[update][收到更新请求:{}]", updateVO.toString()); + return true; + } + +} diff --git a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/vo/UserUpdateVO.java b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/vo/UserUpdateVO.java new file mode 100644 index 000000000..49eee053f --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/vo/UserUpdateVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.springboot.lab71.vo; + +/** + * 用户更新 VO + */ +public class UserUpdateVO { + + /** + * 昵称 + */ + private String nickname; + /** + * 性别 + */ + private Integer gender; + + public String getNickname() { + return nickname; + } + + public UserUpdateVO setNickname(String nickname) { + this.nickname = nickname; + return this; + } + + public Integer getGender() { + return gender; + } + + public UserUpdateVO setGender(Integer gender) { + this.gender = gender; + return this; + } + + @Override + public String toString() { + return "UserUpdateVO{" + + "nickname='" + nickname + '\'' + + ", gender=" + gender + + '}'; + } + +} diff --git a/lab-71-http-debug/pom.xml b/lab-71-http-debug/pom.xml new file mode 100644 index 000000000..74afc145f --- /dev/null +++ b/lab-71-http-debug/pom.xml @@ -0,0 +1,18 @@ + + + + labs-parent + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-71-http-debug + pom + + lab-71-idea-http-client + + + diff --git a/pom.xml b/pom.xml index 29ec927c3..c976242b6 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ - lab-70-db-doc + @@ -111,6 +111,7 @@ + lab-71-http-debug From 5c3eb270018b9b95563f0eb55070fb473a4b80b6 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 20 Dec 2020 02:31:58 +0800 Subject: [PATCH 17/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20IDEA=20HTTP=20Client?= =?UTF-8?q?=20=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + httpRequests/2020-12-20T004250.200.json | 4 + httpRequests/2020-12-20T004328.500.json | 7 + httpRequests/2020-12-20T004337.200.json | 4 + httpRequests/2020-12-20T004347.200.json | 4 + httpRequests/2020-12-20T004347.500.json | 7 + httpRequests/2020-12-20T004358.200.json | 4 + httpRequests/2020-12-20T004358.500.json | 7 + httpRequests/2020-12-20T004401.200.json | 4 + httpRequests/2020-12-20T004401.500.json | 7 + httpRequests/2020-12-20T004538.200.json | 4 + httpRequests/2020-12-20T004547.500.json | 7 + httpRequests/2020-12-20T004638.500.json | 7 + httpRequests/2020-12-20T004645.500.json | 7 + httpRequests/2020-12-20T004809.200.json | 4 + httpRequests/2020-12-20T004813.500.json | 7 + httpRequests/2020-12-20T010724.200.json | 4 + httpRequests/2020-12-20T010738.200.json | 4 + httpRequests/2020-12-20T010809.200.json | 4 + httpRequests/2020-12-20T010823.500.json | 7 + httpRequests/2020-12-20T010840.200.json | 4 + httpRequests/2020-12-20T011020.500.json | 7 + httpRequests/2020-12-20T011347.500.json | 7 + httpRequests/2020-12-20T011526.200.json | 4 + httpRequests/2020-12-20T011530.200.json | 5 + httpRequests/2020-12-20T011541.400.json | 7 + httpRequests/2020-12-20T011551.500.json | 7 + httpRequests/2020-12-20T011556.200.json | 5 + httpRequests/2020-12-20T011628-1.200.json | 5 + httpRequests/2020-12-20T011628.200.json | 4 + httpRequests/2020-12-20T011646.200.json | 4 + httpRequests/2020-12-20T011650.200.json | 4 + httpRequests/2020-12-20T011653.500.json | 7 + httpRequests/2020-12-20T011818.200.json | 4 + httpRequests/2020-12-20T011843.200.json | 4 + httpRequests/2020-12-20T011847.500.json | 7 + httpRequests/2020-12-20T012507.200.json | 4 + httpRequests/2020-12-20T012510.200.json | 5 + httpRequests/2020-12-20T012527.200.json | 5 + httpRequests/2020-12-20T012540.400.json | 7 + httpRequests/2020-12-20T012544.200.json | 5 + httpRequests/2020-12-20T012703.500.json | 7 + httpRequests/2020-12-20T012708.200.json | 4 + httpRequests/2020-12-20T012710.200.json | 5 + httpRequests/2020-12-20T013544.200.json | 5 + httpRequests/2020-12-20T013552.200.json | 4 + httpRequests/2020-12-20T013558.500.json | 7 + httpRequests/2020-12-20T013845.200.json | 4 + httpRequests/2020-12-20T014019.200.json | 5 + httpRequests/2020-12-20T021415.200.json | 4 + httpRequests/http-client.cookies | 1 + httpRequests/http-requests-log.http | 410 ++++++++++++++++++ ...\346\241\243\345\220\215\347\247\260.html" | 21 + .../http-client.env.json | 8 + .../http-client.private.env.json | 12 + .../lab71/controller/UserController.http | 3 +- .../lab71/controller/UserController.java | 9 +- .../lab71/controller/UserController2.http | 19 + .../lab71/controller/UserController3.http | 25 ++ .../lab71/controller/UserController4.http | 13 + ...\350\257\225 IDEA HTTP Client\343\200\213" | 1 + 61 files changed, 779 insertions(+), 3 deletions(-) create mode 100644 httpRequests/2020-12-20T004250.200.json create mode 100644 httpRequests/2020-12-20T004328.500.json create mode 100644 httpRequests/2020-12-20T004337.200.json create mode 100644 httpRequests/2020-12-20T004347.200.json create mode 100644 httpRequests/2020-12-20T004347.500.json create mode 100644 httpRequests/2020-12-20T004358.200.json create mode 100644 httpRequests/2020-12-20T004358.500.json create mode 100644 httpRequests/2020-12-20T004401.200.json create mode 100644 httpRequests/2020-12-20T004401.500.json create mode 100644 httpRequests/2020-12-20T004538.200.json create mode 100644 httpRequests/2020-12-20T004547.500.json create mode 100644 httpRequests/2020-12-20T004638.500.json create mode 100644 httpRequests/2020-12-20T004645.500.json create mode 100644 httpRequests/2020-12-20T004809.200.json create mode 100644 httpRequests/2020-12-20T004813.500.json create mode 100644 httpRequests/2020-12-20T010724.200.json create mode 100644 httpRequests/2020-12-20T010738.200.json create mode 100644 httpRequests/2020-12-20T010809.200.json create mode 100644 httpRequests/2020-12-20T010823.500.json create mode 100644 httpRequests/2020-12-20T010840.200.json create mode 100644 httpRequests/2020-12-20T011020.500.json create mode 100644 httpRequests/2020-12-20T011347.500.json create mode 100644 httpRequests/2020-12-20T011526.200.json create mode 100644 httpRequests/2020-12-20T011530.200.json create mode 100644 httpRequests/2020-12-20T011541.400.json create mode 100644 httpRequests/2020-12-20T011551.500.json create mode 100644 httpRequests/2020-12-20T011556.200.json create mode 100644 httpRequests/2020-12-20T011628-1.200.json create mode 100644 httpRequests/2020-12-20T011628.200.json create mode 100644 httpRequests/2020-12-20T011646.200.json create mode 100644 httpRequests/2020-12-20T011650.200.json create mode 100644 httpRequests/2020-12-20T011653.500.json create mode 100644 httpRequests/2020-12-20T011818.200.json create mode 100644 httpRequests/2020-12-20T011843.200.json create mode 100644 httpRequests/2020-12-20T011847.500.json create mode 100644 httpRequests/2020-12-20T012507.200.json create mode 100644 httpRequests/2020-12-20T012510.200.json create mode 100644 httpRequests/2020-12-20T012527.200.json create mode 100644 httpRequests/2020-12-20T012540.400.json create mode 100644 httpRequests/2020-12-20T012544.200.json create mode 100644 httpRequests/2020-12-20T012703.500.json create mode 100644 httpRequests/2020-12-20T012708.200.json create mode 100644 httpRequests/2020-12-20T012710.200.json create mode 100644 httpRequests/2020-12-20T013544.200.json create mode 100644 httpRequests/2020-12-20T013552.200.json create mode 100644 httpRequests/2020-12-20T013558.500.json create mode 100644 httpRequests/2020-12-20T013845.200.json create mode 100644 httpRequests/2020-12-20T014019.200.json create mode 100644 httpRequests/2020-12-20T021415.200.json create mode 100644 httpRequests/http-client.cookies create mode 100644 httpRequests/http-requests-log.http create mode 100644 "lab-70-db-doc/lab-70-db-doc-screw-02/doc/\346\265\213\350\257\225\346\226\207\346\241\243\345\220\215\347\247\260.html" create mode 100644 lab-71-http-debug/lab-71-idea-http-client/http-client.env.json create mode 100644 lab-71-http-debug/lab-71-idea-http-client/http-client.private.env.json create mode 100644 lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController2.http create mode 100644 lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController3.http create mode 100644 lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController4.http create mode 100644 "lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213" diff --git a/README.md b/README.md index be9cac702..d0fa02e16 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,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 接口调试 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/httpRequests/2020-12-20T004250.200.json b/httpRequests/2020-12-20T004250.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T004250.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T004328.500.json b/httpRequests/2020-12-20T004328.500.json new file mode 100644 index 000000000..644fcf6ad --- /dev/null +++ b/httpRequests/2020-12-20T004328.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T16:43:28.332+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T004337.200.json b/httpRequests/2020-12-20T004337.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T004337.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T004347.200.json b/httpRequests/2020-12-20T004347.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T004347.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T004347.500.json b/httpRequests/2020-12-20T004347.500.json new file mode 100644 index 000000000..cf826d14a --- /dev/null +++ b/httpRequests/2020-12-20T004347.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T16:43:47.777+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T004358.200.json b/httpRequests/2020-12-20T004358.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T004358.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T004358.500.json b/httpRequests/2020-12-20T004358.500.json new file mode 100644 index 000000000..0a04daa9d --- /dev/null +++ b/httpRequests/2020-12-20T004358.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T16:43:58.210+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T004401.200.json b/httpRequests/2020-12-20T004401.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T004401.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T004401.500.json b/httpRequests/2020-12-20T004401.500.json new file mode 100644 index 000000000..6b8986c38 --- /dev/null +++ b/httpRequests/2020-12-20T004401.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T16:44:01.275+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T004538.200.json b/httpRequests/2020-12-20T004538.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T004538.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T004547.500.json b/httpRequests/2020-12-20T004547.500.json new file mode 100644 index 000000000..a13aef28a --- /dev/null +++ b/httpRequests/2020-12-20T004547.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T16:45:47.364+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T004638.500.json b/httpRequests/2020-12-20T004638.500.json new file mode 100644 index 000000000..6c69c53ad --- /dev/null +++ b/httpRequests/2020-12-20T004638.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T16:46:38.505+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T004645.500.json b/httpRequests/2020-12-20T004645.500.json new file mode 100644 index 000000000..ff38c72d9 --- /dev/null +++ b/httpRequests/2020-12-20T004645.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T16:46:45.875+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T004809.200.json b/httpRequests/2020-12-20T004809.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T004809.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T004813.500.json b/httpRequests/2020-12-20T004813.500.json new file mode 100644 index 000000000..c1b0a3eb3 --- /dev/null +++ b/httpRequests/2020-12-20T004813.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T16:48:13.674+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T010724.200.json b/httpRequests/2020-12-20T010724.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T010724.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T010738.200.json b/httpRequests/2020-12-20T010738.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T010738.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T010809.200.json b/httpRequests/2020-12-20T010809.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T010809.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T010823.500.json b/httpRequests/2020-12-20T010823.500.json new file mode 100644 index 000000000..731dc2e72 --- /dev/null +++ b/httpRequests/2020-12-20T010823.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:08:23.036+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T010840.200.json b/httpRequests/2020-12-20T010840.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T010840.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T011020.500.json b/httpRequests/2020-12-20T011020.500.json new file mode 100644 index 000000000..f503745d6 --- /dev/null +++ b/httpRequests/2020-12-20T011020.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:10:20.615+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你的账号密码不正确哟!", + "path": "/user/login" +} diff --git a/httpRequests/2020-12-20T011347.500.json b/httpRequests/2020-12-20T011347.500.json new file mode 100644 index 000000000..9cfba0e4c --- /dev/null +++ b/httpRequests/2020-12-20T011347.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:13:47.777+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你没有登录哟!", + "path": "/user/get-current" +} diff --git a/httpRequests/2020-12-20T011526.200.json b/httpRequests/2020-12-20T011526.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T011526.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T011530.200.json b/httpRequests/2020-12-20T011530.200.json new file mode 100644 index 000000000..fadf0411e --- /dev/null +++ b/httpRequests/2020-12-20T011530.200.json @@ -0,0 +1,5 @@ +{ + "gender": 1, + "nickname": "芋道源码", + "id": 1 +} diff --git a/httpRequests/2020-12-20T011541.400.json b/httpRequests/2020-12-20T011541.400.json new file mode 100644 index 000000000..15edabcae --- /dev/null +++ b/httpRequests/2020-12-20T011541.400.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:15:40.992+0000", + "status": 400, + "error": "Bad Request", + "message": "Missing request header 'Authorization' for method parameter of type String", + "path": "/user/get-current" +} diff --git a/httpRequests/2020-12-20T011551.500.json b/httpRequests/2020-12-20T011551.500.json new file mode 100644 index 000000000..5d2c5e84d --- /dev/null +++ b/httpRequests/2020-12-20T011551.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:15:51.919+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你没有登录哟!", + "path": "/user/get-current" +} diff --git a/httpRequests/2020-12-20T011556.200.json b/httpRequests/2020-12-20T011556.200.json new file mode 100644 index 000000000..fadf0411e --- /dev/null +++ b/httpRequests/2020-12-20T011556.200.json @@ -0,0 +1,5 @@ +{ + "gender": 1, + "nickname": "芋道源码", + "id": 1 +} diff --git a/httpRequests/2020-12-20T011628-1.200.json b/httpRequests/2020-12-20T011628-1.200.json new file mode 100644 index 000000000..fadf0411e --- /dev/null +++ b/httpRequests/2020-12-20T011628-1.200.json @@ -0,0 +1,5 @@ +{ + "gender": 1, + "nickname": "芋道源码", + "id": 1 +} diff --git a/httpRequests/2020-12-20T011628.200.json b/httpRequests/2020-12-20T011628.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T011628.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T011646.200.json b/httpRequests/2020-12-20T011646.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T011646.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T011650.200.json b/httpRequests/2020-12-20T011650.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T011650.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T011653.500.json b/httpRequests/2020-12-20T011653.500.json new file mode 100644 index 000000000..0e2e8459f --- /dev/null +++ b/httpRequests/2020-12-20T011653.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:16:53.489+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你没有登录哟!", + "path": "/user/get-current" +} diff --git a/httpRequests/2020-12-20T011818.200.json b/httpRequests/2020-12-20T011818.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T011818.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T011843.200.json b/httpRequests/2020-12-20T011843.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T011843.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T011847.500.json b/httpRequests/2020-12-20T011847.500.json new file mode 100644 index 000000000..722c8464d --- /dev/null +++ b/httpRequests/2020-12-20T011847.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:18:47.862+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你没有登录哟!", + "path": "/user/get-current" +} diff --git a/httpRequests/2020-12-20T012507.200.json b/httpRequests/2020-12-20T012507.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T012507.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T012510.200.json b/httpRequests/2020-12-20T012510.200.json new file mode 100644 index 000000000..fadf0411e --- /dev/null +++ b/httpRequests/2020-12-20T012510.200.json @@ -0,0 +1,5 @@ +{ + "gender": 1, + "nickname": "芋道源码", + "id": 1 +} diff --git a/httpRequests/2020-12-20T012527.200.json b/httpRequests/2020-12-20T012527.200.json new file mode 100644 index 000000000..fadf0411e --- /dev/null +++ b/httpRequests/2020-12-20T012527.200.json @@ -0,0 +1,5 @@ +{ + "gender": 1, + "nickname": "芋道源码", + "id": 1 +} diff --git a/httpRequests/2020-12-20T012540.400.json b/httpRequests/2020-12-20T012540.400.json new file mode 100644 index 000000000..98226c043 --- /dev/null +++ b/httpRequests/2020-12-20T012540.400.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:25:40.604+0000", + "status": 400, + "error": "Bad Request", + "message": "Missing request header 'Authorization' for method parameter of type String", + "path": "/user/get-current" +} diff --git a/httpRequests/2020-12-20T012544.200.json b/httpRequests/2020-12-20T012544.200.json new file mode 100644 index 000000000..fadf0411e --- /dev/null +++ b/httpRequests/2020-12-20T012544.200.json @@ -0,0 +1,5 @@ +{ + "gender": 1, + "nickname": "芋道源码", + "id": 1 +} diff --git a/httpRequests/2020-12-20T012703.500.json b/httpRequests/2020-12-20T012703.500.json new file mode 100644 index 000000000..02fa3b6db --- /dev/null +++ b/httpRequests/2020-12-20T012703.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:27:03.272+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你没有登录哟!", + "path": "/user/get-current" +} diff --git a/httpRequests/2020-12-20T012708.200.json b/httpRequests/2020-12-20T012708.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T012708.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T012710.200.json b/httpRequests/2020-12-20T012710.200.json new file mode 100644 index 000000000..fadf0411e --- /dev/null +++ b/httpRequests/2020-12-20T012710.200.json @@ -0,0 +1,5 @@ +{ + "gender": 1, + "nickname": "芋道源码", + "id": 1 +} diff --git a/httpRequests/2020-12-20T013544.200.json b/httpRequests/2020-12-20T013544.200.json new file mode 100644 index 000000000..fadf0411e --- /dev/null +++ b/httpRequests/2020-12-20T013544.200.json @@ -0,0 +1,5 @@ +{ + "gender": 1, + "nickname": "芋道源码", + "id": 1 +} diff --git a/httpRequests/2020-12-20T013552.200.json b/httpRequests/2020-12-20T013552.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T013552.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T013558.500.json b/httpRequests/2020-12-20T013558.500.json new file mode 100644 index 000000000..2f50b5a68 --- /dev/null +++ b/httpRequests/2020-12-20T013558.500.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2020-12-19T17:35:58.033+0000", + "status": 500, + "error": "Internal Server Error", + "message": "小朋友,你没有登录哟!", + "path": "/user/get-current" +} diff --git a/httpRequests/2020-12-20T013845.200.json b/httpRequests/2020-12-20T013845.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T013845.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/2020-12-20T014019.200.json b/httpRequests/2020-12-20T014019.200.json new file mode 100644 index 000000000..fadf0411e --- /dev/null +++ b/httpRequests/2020-12-20T014019.200.json @@ -0,0 +1,5 @@ +{ + "gender": 1, + "nickname": "芋道源码", + "id": 1 +} diff --git a/httpRequests/2020-12-20T021415.200.json b/httpRequests/2020-12-20T021415.200.json new file mode 100644 index 000000000..2f407b874 --- /dev/null +++ b/httpRequests/2020-12-20T021415.200.json @@ -0,0 +1,4 @@ +{ + "userId": 1, + "token": "token001" +} diff --git a/httpRequests/http-client.cookies b/httpRequests/http-client.cookies new file mode 100644 index 000000000..edfe326f9 --- /dev/null +++ b/httpRequests/http-client.cookies @@ -0,0 +1 @@ +# domain path name value date diff --git a/httpRequests/http-requests-log.http b/httpRequests/http-requests-log.http new file mode 100644 index 000000000..0c9102bef --- /dev/null +++ b/httpRequests/http-requests-log.http @@ -0,0 +1,410 @@ +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T021415.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token001 + +<> 2020-12-20T014019.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T013845.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: 1 + +<> 2020-12-20T013558.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T013552.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token001 + +<> 2020-12-20T013544.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token001 + +<> 2020-12-20T012710.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T012708.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: {{token_from_server}} + +<> 2020-12-20T012703.500.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: {{token_from_server}} + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token001 + +<> 2020-12-20T012544.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true + +<> 2020-12-20T012540.400.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token001 + +<> 2020-12-20T012527.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token001 + +<> 2020-12-20T012510.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T012507.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: 1 + +<> 2020-12-20T011847.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T011843.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T011818.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: 0 + +<> 2020-12-20T011653.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T011650.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T011646.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token001 + +<> 2020-12-20T011628-1.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T011628.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token001 + +<> 2020-12-20T011556.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: {{token_from_server1}} + +<> 2020-12-20T011551.500.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true + +<> 2020-12-20T011541.400.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token001 + +<> 2020-12-20T011530.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T011526.200.json + +### + +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: token002 + +<> 2020-12-20T011347.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T011020.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T010840.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T010823.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T010809.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T010738.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T010724.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T004813.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T004809.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T004645.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T004638.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T004547.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T004538.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T004401.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T004401.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T004358.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T004358.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T004347.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T004347.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T004337.200.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +<> 2020-12-20T004328.500.json + +### + +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +<> 2020-12-20T004250.200.json + +### + diff --git "a/lab-70-db-doc/lab-70-db-doc-screw-02/doc/\346\265\213\350\257\225\346\226\207\346\241\243\345\220\215\347\247\260.html" "b/lab-70-db-doc/lab-70-db-doc-screw-02/doc/\346\265\213\350\257\225\346\226\207\346\241\243\345\220\215\347\247\260.html" new file mode 100644 index 000000000..a85a67aa7 --- /dev/null +++ "b/lab-70-db-doc/lab-70-db-doc-screw-02/doc/\346\265\213\350\257\225\346\226\207\346\241\243\345\220\215\347\247\260.html" @@ -0,0 +1,21 @@ +数据库文档

数据库文档

数据库名:mall_system
文档版本:1.0-SNAPSHOT
文档描述:数据库文档生成
序号表名说明
1admin管理员
2admin_department部门
3oauth2_access_token访问令牌
4oauth2_refresh_token刷新令牌
5permission_admin_role管理员角色
6permission_resource资源
7permission_role角色
8permission_role_resource角色资源
9system_access_log系统访问日志
10system_data_dict数据字典
11system_error_code错误码
12system_exception_log系统异常日志
13_operation_log操作日志
返回目录表名:admin
说明:管理员
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY管理员编号
2namevarchar100NN真实名字
3avatarvarchar2550YN头像
4department_idint100YN部门id
5statustinyint40NN在职状态
6usernamevarchar160NN登陆账号
7passwordvarchar2550NN加密后的密码
8password_saltvarchar640NN密码的盐
9create_admin_idint100NN创建管理员编号
10create_ipvarchar320NN创建 IP
11create_timedatetime190NNCURRENT_TIMESTAMP创建时间
12update_timedatetime190NNCURRENT_TIMESTAMP最后更新时间
返回目录表名:admin_department
说明:部门
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY部门编号
2namevarchar1000NN部门名称
3sortint100NN0排序字段
4pidint100NN0父级部门编号
5create_timetimestamp190NNCURRENT_TIMESTAMP创建时间
6update_timetimestamp190NNCURRENT_TIMESTAMP更新时间
7deletedbit10NNb'0'删除标记
返回目录表名:oauth2_access_token
说明:访问令牌
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idvarchar320NY访问令牌
2user_idint100NN用户编号
3user_typetinyint40NN用户类型
4refresh_tokenvarchar320NN刷新令牌
5expires_timedatetime190NN过期时间
6create_ipvarchar320NN创建 IP
7create_timedatetime190NNCURRENT_TIMESTAMP创建时间
8update_timedatetime190NNCURRENT_TIMESTAMP最后更新时间
9deletedbit10NNb'0'是否删除
返回目录表名:oauth2_refresh_token
说明:刷新令牌
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idvarchar320NY编号,刷新令牌
2user_idint100NN用户编号
3user_typetinyint40NN用户类型
4expires_timedatetime190NN过期时间
5create_ipvarchar320NN创建 IP
6create_timedatetime190NNCURRENT_TIMESTAMP创建时间
7update_timedatetime190NNCURRENT_TIMESTAMP最后更新时间
8deletedbit10NNb'0'是否删除
返回目录表名:permission_admin_role
说明:管理员角色
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY编号
2admin_idint100NN管理员编号
3role_idint100NN角色编号
4create_timedatetime190NNCURRENT_TIMESTAMP创建时间
5update_timedatetime190NNCURRENT_TIMESTAMP更新时间
6deletedbit10YNb'0'是否删除
返回目录表名:permission_resource
说明:资源
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY资源编号
2namevarchar500NN菜单名
3permissionvarchar2550YN权限标识
4typeint100NN资源类型
5sortint100NN排序
6pidint100NN0父级资源编号(外键:{@link ResourceDO#id})
7routevarchar500YN前端路由
8iconvarchar500YN菜单图标
9viewvarchar500YN前端界面
10create_admin_idint100NN创建管理员编号
11create_timedatetime190NNCURRENT_TIMESTAMP添加时间
12update_timedatetime190NNCURRENT_TIMESTAMP更新时间
13deletedbit10NNb'0'是否删除
返回目录表名:permission_role
说明:角色
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY角色编号
2namevarchar500NN角色名
3codevarchar500YN角色编码
4typetinyint40NN角色类型
5create_admin_idint100NN创建管理员编号
6create_timedatetime190NNCURRENT_TIMESTAMP创建时间
7update_timedatetime190YNCURRENT_TIMESTAMP最后更新时间
8deletedbit10NNb'0'是否删除
返回目录表名:permission_role_resource
说明:角色资源
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY编号
2role_idint100NN-1角色编号(外键:{@link RoleDO}
3resource_idint100NN-1资源编号
4create_timedatetime190NNCURRENT_TIMESTAMP创建时间
5update_timedatetime190NNCURRENT_TIMESTAMP更新时间
6deletedbit10NNb'0'是否删除
返回目录表名:system_access_log
说明:系统访问日志
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY编号
2user_idint100YN用户编号
3user_typetinyint40YN用户类型
4trace_idvarchar640YN链路追踪编号
5application_namevarchar500NN应用名
6urivarchar40960NN访问地址
7query_stringvarchar40960NN参数
8methodvarchar500NNhttp 方法
9user_agentvarchar10240NNuserAgent
10ipvarchar500NNip
11start_timedatetime190NN请求时间
12response_timeint100NN响应时长 -- 毫秒级
13error_codeint100NN错误码
14error_messagevarchar5120YN错误提示
15create_timedatetime190NNCURRENT_TIMESTAMP创建时间
16update_timedatetime190NNCURRENT_TIMESTAMP最后更新时间
返回目录表名:system_data_dict
说明:数据字典
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY编号
2enum_valuevarchar500NN大类枚举值
3valuevarchar500NN小类数值
4display_namevarchar500NN展示名
5sortint100NN-1排序值
6memovarchar500YN备注
7create_timedatetime190NNCURRENT_TIMESTAMP创建时间
8update_timedatetime190NNCURRENT_TIMESTAMP最后更新时间
9deletedbit10NNb'0'是否删除
返回目录表名:system_error_code
说明:错误码
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY错误码编号
2codeint100NN0错误码编码
3messagevarchar2550NN错误码错误提示
4typetinyint40NN错误码类型
5groupvarchar640NN错误码分组
6memovarchar2550YN错误码备注
7create_timedatetime190NNCURRENT_TIMESTAMP创建时间
8update_timedatetime190NNCURRENT_TIMESTAMP最后更新时间
9deletedbit10NNb'0'是否删除
返回目录表名:system_exception_log
说明:系统异常日志
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY编号
2user_idint100YN用户编号
3user_typetinyint40YN用户类型
4trace_idvarchar640NN链路追踪编号 + * + * 一般来说,通过链路追踪编号,可以将访问日志,错误日志,链路追踪日志,logger 打印日志等,结合在一起,从而进行排错。
5application_namevarchar500NN应用名 + * + * 目前读取 spring.application.name
6urivarchar40960NN访问地址
7query_stringvarchar40960NN参数
8methodvarchar500NNhttp 方法
9user_agentvarchar10240NNuserAgent
10ipvarchar500NNip
11exception_timedatetime190NN异常发生时间
12exception_namevarchar1280NN异常名 + * + * {@link Throwable#getClass()} 的类全名
13exception_messagetext655350NN异常导致的消息 + * + * {@link cn.iocoder.common.framework.util.ExceptionUtil#getMessage(Throwable)}
14exception_root_cause_messagetext655350NN异常导致的根消息 + * + * {@link cn.iocoder.common.framework.util.ExceptionUtil#getRootCauseMessage(Throwable)}
15exception_stack_tracetext655350NN异常的栈轨迹 + * + * {@link cn.iocoder.common.framework.util.ExceptionUtil#getServiceException(Exception)}
16exception_class_namevarchar5120NN异常发生的类全名 + * + * {@link StackTraceElement#getClassName()}
17exception_file_namevarchar5120NN异常发生的类文件 + * + * {@link StackTraceElement#getFileName()}
18exception_method_namevarchar5120NN异常发生的方法名 + * + * {@link StackTraceElement#getMethodName()}
19exception_line_numberint100NN异常发生的方法所在行 + * + * {@link StackTraceElement#getLineNumber()}
20process_statustinyint40NN0处理状态
21process_timedatetime190YN处理时间
22process_admin_idint100YN处理管理员编号
23create_timedatetime190NNCURRENT_TIMESTAMP创建时间
24update_timedatetime190NNCURRENT_TIMESTAMP最后更新时间
返回目录表名:_operation_log
说明:操作日志
数据列:
序号名称数据类型长度小数位允许空值主键默认值说明
1idint100NY编号
2trace_idvarchar640YN链路追踪编号
3account_idint100NN-1账号编号
4application_namevarchar500YN应用名
5urivarchar40960NN访问地址
6paramsvarchar40960NN参数
7methodvarchar500NNhttp 方法
8user_agentvarchar10240NNuserAgent
9ipvarchar500NNip
10start_timedatetime190NN请求时间
11response_timeint100NN响应时长 -- 毫秒级
12msgvarchar2550YN日志消息
13statusbit10NN操作状态
14operatorvarchar640YN创建者
15create_timedatetime190NN创建时间
\ No newline at end of file diff --git a/lab-71-http-debug/lab-71-idea-http-client/http-client.env.json b/lab-71-http-debug/lab-71-idea-http-client/http-client.env.json new file mode 100644 index 000000000..f35e8548b --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/http-client.env.json @@ -0,0 +1,8 @@ +{ + "local": { + "baseUrl": "http://127.0.0.1:8080" + }, + "dev": { + "baseUrl": "http://192.168.100.200:8080" + } +} diff --git a/lab-71-http-debug/lab-71-idea-http-client/http-client.private.env.json b/lab-71-http-debug/lab-71-idea-http-client/http-client.private.env.json new file mode 100644 index 000000000..813df3c93 --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/http-client.private.env.json @@ -0,0 +1,12 @@ +{ + "local": { + "username": "yudaoyuanma", + "password": "123456", + "token": "token001" + }, + "dev": { + "username": "yutou", + "password": "buzhidao", + "token": "aoteman" + } +} diff --git a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.http b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.http index 0b6862587..ecbc592b8 100644 --- a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.http +++ b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.http @@ -5,7 +5,7 @@ Content-Type: application/x-www-form-urlencoded username=yudaoyuanma&password=123456 ### 测试 /user/get-current:获取成功 -GET http://127.0.0.1:8080/user/get-current +GET http://127.0.0.1:8080/user/get-current?full=true Authorization: token001 ### 测试 /user/update:更新成功 @@ -16,3 +16,4 @@ Content-Type: application/json "nickname": "我是昵称", "gender": 1 } + diff --git a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java index 48c994511..549868bfd 100644 --- a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java +++ b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java @@ -31,11 +31,16 @@ public Map login(@RequestParam("username") String username, } @GetMapping("/user/get-current") - public Map getCurrentUser(@RequestHeader("Authorization") String authorization) { + public Map getCurrentUser(@RequestHeader("Authorization") String authorization, + @RequestParam("full") boolean full) { if ("token001".equals(authorization)) { Map userInfo = new HashMap<>(); userInfo.put("id", 1); - userInfo.put("gender", 1); + // full 为 true 时,获得完整信息 + if (full) { + userInfo.put("nickname", "芋道源码"); + userInfo.put("gender", 1); + } return userInfo; } throw new RuntimeException("小朋友,你没有登录哟!"); diff --git a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController2.http b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController2.http new file mode 100644 index 000000000..69d2cd561 --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController2.http @@ -0,0 +1,19 @@ +### 测试 /user/login:登陆成功 +POST {{baseUrl}}/user/login +Content-Type: application/x-www-form-urlencoded + +username={{username}}&password={{password}} + +### 测试 /user/get-current:获取成功 +GET {{baseUrl}}/user/get-current?full=true +Authorization: {{token}} + +### 测试 /user/update:更新成功 +POST {{baseUrl}}/user/update +Content-Type: application/json + +{ + "nickname": "我是昵称", + "gender": 1 +} + diff --git a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController3.http b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController3.http new file mode 100644 index 000000000..79a3dee0d --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController3.http @@ -0,0 +1,25 @@ +### 001 测试 /user/login:登陆成功 +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +> {% +client.test("验证登陆成功", function (){ + client.assert(response.status === 200, "响应状态应该是 200,结果是 " + response.status) + client.assert(response.body.userId === 1, "响应的 userId 应该是 1,结果是 " + response.body.userId) + client.assert(response.body.token === "token001", "响应的 token 应该是 token001,记过是 " + response.body.token) +}); +%} + +### 002 测试 /user/login:登陆失败,密码不正确 +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=buzhidao + +> {% +client.test("验证登陆失败", function (){ + client.assert(response.status === 200, "响应状态应该是 200,结果是 " + response.status) +}); +%} diff --git a/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController4.http b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController4.http new file mode 100644 index 000000000..ae43973f3 --- /dev/null +++ b/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController4.http @@ -0,0 +1,13 @@ +### 测试 /user/login:登陆成功 +POST http://127.0.0.1:8080/user/login +Content-Type: application/x-www-form-urlencoded + +username=yudaoyuanma&password=123456 + +> {% +client.global.set("token_from_server", response.body.token) +%} + +### 测试 /user/get-current:获取成功 +GET http://127.0.0.1:8080/user/get-current?full=true +Authorization: {{token_from_server}} diff --git "a/lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213" "b/lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213" new file mode 100644 index 000000000..c0b4e4a68 --- /dev/null +++ "b/lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213" @@ -0,0 +1 @@ +http://www.iocoder.cn/Spring-Boot/IDEA-HTTP-Client/?github From 81755e2ce7fac3a5f7d73481aa782790d0dab55e Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 20 Dec 2020 02:47:22 +0800 Subject: [PATCH 18/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20IDEA=20HTTP=20Client?= =?UTF-8?q?=20=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213" | 1 - ...\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213.md" | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 "lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213" create mode 100644 "lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213.md" diff --git "a/lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213" "b/lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213" deleted file mode 100644 index c0b4e4a68..000000000 --- "a/lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213" +++ /dev/null @@ -1 +0,0 @@ -http://www.iocoder.cn/Spring-Boot/IDEA-HTTP-Client/?github diff --git "a/lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213.md" "b/lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213.md" new file mode 100644 index 000000000..05d591744 --- /dev/null +++ "b/lab-71-http-debug/\343\200\212\350\212\213\351\201\223 Spring Boot API \346\216\245\345\217\243\350\260\203\350\257\225 IDEA HTTP Client\343\200\213.md" @@ -0,0 +1 @@ + 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 19/29] =?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 20/29] =?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 21/29] =?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 22/29] =?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 23/29] =?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 24/29] =?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 25/29] =?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 26/29] =?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 27/29] =?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 28/29] =?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 29/29] 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