From ef859f7324c8dc40819acb72bd4d360b041b3bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Wed, 3 Mar 2021 17:42:27 +0800 Subject: [PATCH 01/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8MongoDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter6-1/pom.xml | 55 +++++++++++++++++++ .../chapter61/Chapter61Application.java | 13 +++++ .../java/com/didispace/chapter61/User.java | 47 ++++++++++++++++ .../didispace/chapter61/UserRepository.java | 14 +++++ .../src/main/resources/application.properties | 3 + .../didispace/chapter61/ApplicationTests.java | 42 ++++++++++++++ 2.x/pom.xml | 8 ++- 7 files changed, 180 insertions(+), 2 deletions(-) create mode 100755 2.x/chapter6-1/pom.xml create mode 100755 2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java create mode 100644 2.x/chapter6-1/src/main/java/com/didispace/chapter61/User.java create mode 100644 2.x/chapter6-1/src/main/java/com/didispace/chapter61/UserRepository.java create mode 100644 2.x/chapter6-1/src/main/resources/application.properties create mode 100755 2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java diff --git a/2.x/chapter6-1/pom.xml b/2.x/chapter6-1/pom.xml new file mode 100755 index 00000000..ede613c5 --- /dev/null +++ b/2.x/chapter6-1/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + + com.didispace + chapter6-1 + 0.0.1-SNAPSHOT + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java new file mode 100755 index 00000000..184a48eb --- /dev/null +++ b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java @@ -0,0 +1,13 @@ +package com.didispace.chapter61; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Chapter61Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter61Application.class, args); + } + +} diff --git a/2.x/chapter6-1/src/main/java/com/didispace/chapter61/User.java b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/User.java new file mode 100644 index 00000000..4a4f4186 --- /dev/null +++ b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/User.java @@ -0,0 +1,47 @@ +package com.didispace.chapter61; + +import org.springframework.data.annotation.Id; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + */ +public class User { + + @Id + private Long id; + + private String username; + private Integer age; + + public User(Long id, String username, Integer age) { + this.id = id; + this.username = username; + this.age = age; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } +} diff --git a/2.x/chapter6-1/src/main/java/com/didispace/chapter61/UserRepository.java b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/UserRepository.java new file mode 100644 index 00000000..f1336f96 --- /dev/null +++ b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/UserRepository.java @@ -0,0 +1,14 @@ +package com.didispace.chapter61; + +import org.springframework.data.mongodb.repository.MongoRepository; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + */ +public interface UserRepository extends MongoRepository { + + User findByUsername(String username); + +} diff --git a/2.x/chapter6-1/src/main/resources/application.properties b/2.x/chapter6-1/src/main/resources/application.properties new file mode 100644 index 00000000..65cdd338 --- /dev/null +++ b/2.x/chapter6-1/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.data.mongodb.uri=mongodb://name:pass@localhost:27017/test + + diff --git a/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java b/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java new file mode 100755 index 00000000..bf2fd268 --- /dev/null +++ b/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java @@ -0,0 +1,42 @@ +package com.didispace.chapter61; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = Chapter61Application.class) +public class ApplicationTests { + + @Autowired + private UserRepository userRepository; + + @Before + public void setUp() { + userRepository.deleteAll(); + } + + @Test + public void test() throws Exception { + userRepository.deleteAll(); + + // 创建三个User,并验证User总数 + userRepository.save(new User(1L, "didi", 30)); + userRepository.save(new User(2L, "mama", 40)); + userRepository.save(new User(3L, "kaka", 50)); + Assert.assertEquals(3, userRepository.findAll().size()); + + // 删除一个User,再验证User总数 + User u = userRepository.findById(1L).get(); + userRepository.delete(u); + Assert.assertEquals(2, userRepository.findAll().size()); + + // 删除一个User,再验证User总数 + u = userRepository.findByUsername("mama"); + userRepository.delete(u); + Assert.assertEquals(1, userRepository.findAll().size()); + + } + +} diff --git a/2.x/pom.xml b/2.x/pom.xml index e7db22a7..df920fc0 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -58,12 +58,16 @@ chapter5-4 - - + + chapter6-1 + + + + From 94ededc59d2ef67346226a81391b08848e853603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Wed, 3 Mar 2021 17:50:30 +0800 Subject: [PATCH 02/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E5=BF=AB=E9=80=9F=E5=85=A5=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/didispace/chapter11/Chapter11ApplicationTests.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/2.x/chapter1-1/src/test/java/com/didispace/chapter11/Chapter11ApplicationTests.java b/2.x/chapter1-1/src/test/java/com/didispace/chapter11/Chapter11ApplicationTests.java index 79cbf107..e39db87a 100644 --- a/2.x/chapter1-1/src/test/java/com/didispace/chapter11/Chapter11ApplicationTests.java +++ b/2.x/chapter1-1/src/test/java/com/didispace/chapter11/Chapter11ApplicationTests.java @@ -2,10 +2,8 @@ import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -15,7 +13,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringRunner.class) @SpringBootTest public class Chapter11ApplicationTests { From 3961ad214110b37a75a133c56526ace7d6ea0904 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Wed, 3 Mar 2021 21:24:58 +0800 Subject: [PATCH 03/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8MongoDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter6-1/pom.xml | 1 - .../java/com/didispace/chapter61/Chapter61Application.java | 6 +++--- 2.x/chapter6-1/src/main/resources/application.properties | 2 +- .../test/java/com/didispace/chapter61/ApplicationTests.java | 5 +++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/2.x/chapter6-1/pom.xml b/2.x/chapter6-1/pom.xml index ede613c5..7037b09e 100755 --- a/2.x/chapter6-1/pom.xml +++ b/2.x/chapter6-1/pom.xml @@ -51,5 +51,4 @@ - diff --git a/2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java index 184a48eb..dfd534eb 100755 --- a/2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java +++ b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java @@ -6,8 +6,8 @@ @SpringBootApplication public class Chapter61Application { - public static void main(String[] args) { - SpringApplication.run(Chapter61Application.class, args); - } + public static void main(String[] args) { + SpringApplication.run(Chapter61Application.class, args); + } } diff --git a/2.x/chapter6-1/src/main/resources/application.properties b/2.x/chapter6-1/src/main/resources/application.properties index 65cdd338..0e2f083f 100644 --- a/2.x/chapter6-1/src/main/resources/application.properties +++ b/2.x/chapter6-1/src/main/resources/application.properties @@ -1,3 +1,3 @@ -spring.data.mongodb.uri=mongodb://name:pass@localhost:27017/test +spring.data.mongodb.uri=mongodb://localhost:27017/test diff --git a/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java b/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java index bf2fd268..74d0d87f 100755 --- a/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java +++ b/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java @@ -3,9 +3,12 @@ import org.junit.Assert; import org.junit.Before; 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; +@RunWith(SpringRunner.class) @SpringBootTest(classes = Chapter61Application.class) public class ApplicationTests { @@ -19,8 +22,6 @@ public void setUp() { @Test public void test() throws Exception { - userRepository.deleteAll(); - // 创建三个User,并验证User总数 userRepository.save(new User(1L, "didi", 30)); userRepository.save(new User(2L, "mama", 40)); From da35cc88eb15f02f8b4b1b483f9a0732fd53b422 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Wed, 3 Mar 2021 22:18:09 +0800 Subject: [PATCH 04/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8MongoDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 7 ++++ 2.x/README_zh.md | 9 ++++- 2.x/chapter6-1/pom.xml | 2 +- .../java/com/didispace/chapter61/User.java | 33 +++---------------- .../didispace/chapter61/ApplicationTests.java | 22 ++++--------- 5 files changed, 27 insertions(+), 46 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index eef9aef7..2b23ceba 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -77,6 +77,7 @@ - [Spring Boot 2.x基础教程:Swagger接口分类与各元素排序问题详解](http://blog.didispace.com/spring-boot-learning-21-2-4/) - [Spring Boot 2.x基础教程:Swagger静态文档的生成](http://blog.didispace.com/spring-boot-learning-21-2-5/) - [Spring Boot 2.x基础教程:找回启动日志中的请求路径列表](http://blog.didispace.com/spring-boot-learning-21-2-6/) +- [Spring Boot 2.x基础教程:使用SpringFox 3生成Swagger文档](http://blog.didispace.com/spring-boot-learning-21-2-7/) ### 数据访问 @@ -102,12 +103,18 @@ - [Spring Boot 2.x基础教程:使用EhCache缓存集群](http://blog.didispace.com/spring-boot-learning-21-5-3/) - [Spring Boot 2.x基础教程:使用集中式缓存Redis](http://blog.didispace.com/spring-boot-learning-21-5-4/) +**其他常见存储的使用** + +- [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) + + ### Web开发 - [Spring Boot 2.x基础教程:使用 Thymeleaf开发Web页面](http://blog.didispace.com/spring-boot-learning-21-4-1/) - [Spring Boot 2.x基础教程:使用 ECharts 绘制各种华丽的数据图表](http://blog.didispace.com/spring-boot-learning-21-4-2/) - [Spring Boot 2.x基础教程:实现文件上传](http://blog.didispace.com/spring-boot-learning-21-4-3/) - [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) +- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) ## 版本资讯 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index b7a36e10..7c1b84a6 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -70,7 +70,7 @@ - [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/) - [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) -### Web开发 +### API开发 - [Spring Boot 2.x基础教程:构建RESTful API与单元测试](http://blog.didispace.com/spring-boot-learning-21-2-1/) - [Spring Boot 2.x基础教程:使用Swagger2构建强大的API文档](http://blog.didispace.com/spring-boot-learning-21-2-2/) @@ -78,6 +78,7 @@ - [Spring Boot 2.x基础教程:Swagger接口分类与各元素排序问题详解](http://blog.didispace.com/spring-boot-learning-21-2-4/) - [Spring Boot 2.x基础教程:Swagger静态文档的生成](http://blog.didispace.com/spring-boot-learning-21-2-5/) - [Spring Boot 2.x基础教程:找回启动日志中的请求路径列表](http://blog.didispace.com/spring-boot-learning-21-2-6/) +- [Spring Boot 2.x基础教程:使用SpringFox 3生成Swagger文档](http://blog.didispace.com/spring-boot-learning-21-2-7/) ### 数据访问 @@ -103,12 +104,18 @@ - [Spring Boot 2.x基础教程:使用EhCache缓存集群](http://blog.didispace.com/spring-boot-learning-21-5-3/) - [Spring Boot 2.x基础教程:使用集中式缓存Redis](http://blog.didispace.com/spring-boot-learning-21-5-4/) +**其他常见存储的使用** + +- [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) + ### Web开发 - [Spring Boot 2.x基础教程:使用 Thymeleaf开发Web页面](http://blog.didispace.com/spring-boot-learning-21-4-1/) - [Spring Boot 2.x基础教程:使用 ECharts 绘制各种华丽的数据图表](http://blog.didispace.com/spring-boot-learning-21-4-2/) - [Spring Boot 2.x基础教程:实现文件上传](http://blog.didispace.com/spring-boot-learning-21-4-3/) - [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) +- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) + ## 版本资讯 diff --git a/2.x/chapter6-1/pom.xml b/2.x/chapter6-1/pom.xml index 7037b09e..7c21c138 100755 --- a/2.x/chapter6-1/pom.xml +++ b/2.x/chapter6-1/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.4.1 diff --git a/2.x/chapter6-1/src/main/java/com/didispace/chapter61/User.java b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/User.java index 4a4f4186..e94f10c0 100644 --- a/2.x/chapter6-1/src/main/java/com/didispace/chapter61/User.java +++ b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/User.java @@ -1,5 +1,7 @@ package com.didispace.chapter61; +import lombok.AllArgsConstructor; +import lombok.Data; import org.springframework.data.annotation.Id; /** @@ -7,6 +9,8 @@ * @version 1.0.0 * @blog http://blog.didispace.com */ +@Data +@AllArgsConstructor public class User { @Id @@ -15,33 +19,4 @@ public class User { private String username; private Integer age; - public User(Long id, String username, Integer age) { - this.id = id; - this.username = username; - this.age = age; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public Integer getAge() { - return age; - } - - public void setAge(Integer age) { - this.age = age; - } } diff --git a/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java b/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java index 74d0d87f..e1ee421a 100755 --- a/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java +++ b/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java @@ -1,43 +1,35 @@ package com.didispace.chapter61; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = Chapter61Application.class) public class ApplicationTests { @Autowired private UserRepository userRepository; - @Before - public void setUp() { - userRepository.deleteAll(); - } - @Test public void test() throws Exception { + userRepository.deleteAll(); + // 创建三个User,并验证User总数 userRepository.save(new User(1L, "didi", 30)); userRepository.save(new User(2L, "mama", 40)); userRepository.save(new User(3L, "kaka", 50)); - Assert.assertEquals(3, userRepository.findAll().size()); + Assertions.assertEquals(3, userRepository.findAll().size()); // 删除一个User,再验证User总数 User u = userRepository.findById(1L).get(); userRepository.delete(u); - Assert.assertEquals(2, userRepository.findAll().size()); + Assertions.assertEquals(2, userRepository.findAll().size()); // 删除一个User,再验证User总数 u = userRepository.findByUsername("mama"); userRepository.delete(u); - Assert.assertEquals(1, userRepository.findAll().size()); - + Assertions.assertEquals(1, userRepository.findAll().size()); } } From 00343765edab50391df75bdffd1e9865a0add542 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Sun, 23 May 2021 18:11:26 +0800 Subject: [PATCH 05/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A2.5=E7=89=88=E6=9C=AC=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-13/.gitignore | 29 ++++++++++ 2.x/chapter3-13/pom.xml | 58 +++++++++++++++++++ .../chapter313/Chapter313Application.java | 13 +++++ .../src/main/resources/application.properties | 15 +++++ .../src/main/resources/schema-all.sql | 18 ++++++ .../chapter31/Chapter31ApplicationTests.java | 17 ++++++ 2.x/pom.xml | 1 + 7 files changed, 151 insertions(+) create mode 100644 2.x/chapter3-13/.gitignore create mode 100644 2.x/chapter3-13/pom.xml create mode 100644 2.x/chapter3-13/src/main/java/com/didispace/chapter313/Chapter313Application.java create mode 100644 2.x/chapter3-13/src/main/resources/application.properties create mode 100644 2.x/chapter3-13/src/main/resources/schema-all.sql create mode 100644 2.x/chapter3-13/src/test/java/com/didispace/chapter31/Chapter31ApplicationTests.java diff --git a/2.x/chapter3-13/.gitignore b/2.x/chapter3-13/.gitignore new file mode 100644 index 00000000..153c9335 --- /dev/null +++ b/2.x/chapter3-13/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/2.x/chapter3-13/pom.xml b/2.x/chapter3-13/pom.xml new file mode 100644 index 00000000..b9728f16 --- /dev/null +++ b/2.x/chapter3-13/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.0 + + + + com.didispace + chapter3-1(2.5+) + 0.0.1-SNAPSHOT + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + mysql + mysql-connector-java + + + + org.projectlombok + lombok + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter3-13/src/main/java/com/didispace/chapter313/Chapter313Application.java b/2.x/chapter3-13/src/main/java/com/didispace/chapter313/Chapter313Application.java new file mode 100644 index 00000000..88768410 --- /dev/null +++ b/2.x/chapter3-13/src/main/java/com/didispace/chapter313/Chapter313Application.java @@ -0,0 +1,13 @@ +package com.didispace.chapter313; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Chapter313Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter313Application.class, args); + } + +} diff --git a/2.x/chapter3-13/src/main/resources/application.properties b/2.x/chapter3-13/src/main/resources/application.properties new file mode 100644 index 00000000..225ddd22 --- /dev/null +++ b/2.x/chapter3-13/src/main/resources/application.properties @@ -0,0 +1,15 @@ +spring.datasource.url=jdbc:mysql://localhost:3306/test +spring.datasource.username=root +spring.datasource.password= +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + +# Spring Boot 2.5.0 init schema & data +spring.sql.init.username=root +spring.sql.init.password= +spring.sql.init.schema-locations=classpath*:schema-all.sql +#spring.sql.init.enabled=true +#spring.sql.init.data-locations=classpath*: +#spring.sql.init.encoding=UTF-8 +#spring.sql.init.separator=; +#spring.sql.init.continue-on-error=true + diff --git a/2.x/chapter3-13/src/main/resources/schema-all.sql b/2.x/chapter3-13/src/main/resources/schema-all.sql new file mode 100644 index 00000000..cdbe26c1 --- /dev/null +++ b/2.x/chapter3-13/src/main/resources/schema-all.sql @@ -0,0 +1,18 @@ +create table test.user_info +( + id int unsigned auto_increment comment '用户id' + primary key, + open_id varchar(255) default '' null comment '微信小程序openid', + nick_name varchar(255) default '' null comment '微信名', + head_img varchar(255) default '' null comment '微信头像', + sex varchar(255) default '' null comment '性别', + phone varchar(255) default '' null comment '手机', + province varchar(255) default '' null comment '注册地址:省', + city varchar(255) default '' null comment '注册地址:城市', + country varchar(255) default '' null comment '注册地址:县/区', + status tinyint unsigned default 0 not null comment '是否标记删除 0:否 1:是', + create_time datetime not null comment '创建时间', + update_time datetime not null comment '更新时间' +) + comment '用户表'; + diff --git a/2.x/chapter3-13/src/test/java/com/didispace/chapter31/Chapter31ApplicationTests.java b/2.x/chapter3-13/src/test/java/com/didispace/chapter31/Chapter31ApplicationTests.java new file mode 100644 index 00000000..e65f6029 --- /dev/null +++ b/2.x/chapter3-13/src/test/java/com/didispace/chapter31/Chapter31ApplicationTests.java @@ -0,0 +1,17 @@ +package com.didispace.chapter31; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + + +@SpringBootTest +public class Chapter31ApplicationTests { + + + @Test + public void test() throws Exception { + + + } + +} diff --git a/2.x/pom.xml b/2.x/pom.xml index df920fc0..68da28f3 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -40,6 +40,7 @@ chapter3-10 chapter3-11 chapter3-12 + chapter3-13 From aa19c6e723bad1ab2f020e8f17b601e3a3000ef7 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Sun, 23 May 2021 18:21:51 +0800 Subject: [PATCH 06/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A2.5=E7=89=88=E6=9C=AC=E5=90=8E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E7=9A=84=E5=8F=98=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 3 +++ 2.x/README_zh.md | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/2.x/README.md b/2.x/README.md index 2b23ceba..3834483f 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -96,6 +96,8 @@ - [Spring Boot 2.x基础教程:使用Flyway管理数据库版本](http://blog.didispace.com/spring-boot-learning-24-3-11/) - [Spring Boot 2.x基础教程:使用JTA实现分布式事务](http://blog.didispace.com/spring-boot-learning-24-3-12/) +- [Spring Boot 2.x基础教程:2.5版本后数据脚本初始化的变动](http://blog.didispace.com/spring-boot-learning-25-3-13/) + **加速利器:各种缓存的使用** - [Spring Boot 2.x基础教程:进程内缓存的使用与Cache注解详解](http://blog.didispace.com/spring-boot-learning-21-5-1/) @@ -134,6 +136,7 @@ - [Spring Boot 2.3.2 发布,解决 Too many open files 导致的应用宕机问题](http://blog.didispace.com/spring-boot-2-3-2-release/) - [Spring Boot 2.4.0 正式发布!全新的配置处理机制,拥抱云原生!](http://blog.didispace.com/spring-boot-2-4-0-ga/) - [Spring Boot 2.4.1 发布,修正大量2.4全新配置机制的Bug](http://blog.didispace.com/spring-boot-2-4-1-release/) +- [Spring Boot 2.5.0 发布:支持Java16、Gradle 7、Datasource初始化调整](https://blog.didispace.com/spring-boot-2-5-0-release/) ## 我的公众号 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 7c1b84a6..dda26e79 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -97,6 +97,8 @@ - [Spring Boot 2.x基础教程:使用Flyway管理数据库版本](http://blog.didispace.com/spring-boot-learning-24-3-11/) - [Spring Boot 2.x基础教程:使用JTA实现分布式事务](http://blog.didispace.com/spring-boot-learning-24-3-12/) +- [Spring Boot 2.x基础教程:2.5版本后数据脚本初始化的变动](http://blog.didispace.com/spring-boot-learning-25-3-13/) + **加速利器:各种缓存的使用** - [Spring Boot 2.x基础教程:进程内缓存的使用与Cache注解详解](http://blog.didispace.com/spring-boot-learning-21-5-1/) @@ -108,6 +110,8 @@ - [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) + + ### Web开发 - [Spring Boot 2.x基础教程:使用 Thymeleaf开发Web页面](http://blog.didispace.com/spring-boot-learning-21-4-1/) @@ -135,6 +139,7 @@ - [Spring Boot 2.3.2 发布,解决 Too many open files 导致的应用宕机问题](http://blog.didispace.com/spring-boot-2-3-2-release/) - [Spring Boot 2.4.0 正式发布!全新的配置处理机制,拥抱云原生!](http://blog.didispace.com/spring-boot-2-4-0-ga/) - [Spring Boot 2.4.1 发布,修正大量2.4全新配置机制的Bug](http://blog.didispace.com/spring-boot-2-4-1-release/) +- [Spring Boot 2.5.0 发布:支持Java16、Gradle 7、Datasource初始化调整](https://blog.didispace.com/spring-boot-2-5-0-release/) ## 推荐内容 From 5d3fb25e3ef95a3cff33494931036e095d50e383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Wed, 2 Jun 2021 16:09:41 +0800 Subject: [PATCH 07/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A2.5=E7=89=88=E6=9C=AC=E5=90=8E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E7=9A=84=E5=8F=98=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-13/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter3-13/pom.xml b/2.x/chapter3-13/pom.xml index b9728f16..8fecff2e 100644 --- a/2.x/chapter3-13/pom.xml +++ b/2.x/chapter3-13/pom.xml @@ -11,7 +11,7 @@ com.didispace - chapter3-1(2.5+) + chapter3-13 0.0.1-SNAPSHOT From 6c3633e3426c9ed85bb8af41a24c1ec89bce08b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Wed, 16 Jun 2021 14:10:54 +0800 Subject: [PATCH 08/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E5=A6=82=E4=BD=95=E6=89=A9=E5=B1=95?= =?UTF-8?q?XML=E6=A0=BC=E5=BC=8F=E7=9A=84=E8=AF=B7=E6=B1=82=E5=92=8C?= =?UTF-8?q?=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 13 ++++- 2.x/README_zh.md | 10 +++- 2.x/chapter2-8/pom.xml | 56 +++++++++++++++++++ .../chapter28/Chapter28Application.java | 18 ++++++ .../java/com/didispace/chapter28/User.java | 26 +++++++++ .../didispace/chapter28/UserController.java | 27 +++++++++ .../src/main/resources/application.properties | 0 2.x/pom.xml | 3 +- 8 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 2.x/chapter2-8/pom.xml create mode 100755 2.x/chapter2-8/src/main/java/com/didispace/chapter28/Chapter28Application.java create mode 100755 2.x/chapter2-8/src/main/java/com/didispace/chapter28/User.java create mode 100755 2.x/chapter2-8/src/main/java/com/didispace/chapter28/UserController.java create mode 100755 2.x/chapter2-8/src/main/resources/application.properties diff --git a/2.x/README.md b/2.x/README.md index 3834483f..c22d7d01 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -4,7 +4,7 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) +**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) **如何支持**: @@ -69,7 +69,7 @@ - [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/) - [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) -### Web开发 +### API开发 - [Spring Boot 2.x基础教程:构建RESTful API与单元测试](http://blog.didispace.com/spring-boot-learning-21-2-1/) - [Spring Boot 2.x基础教程:使用Swagger2构建强大的API文档](http://blog.didispace.com/spring-boot-learning-21-2-2/) @@ -78,6 +78,7 @@ - [Spring Boot 2.x基础教程:Swagger静态文档的生成](http://blog.didispace.com/spring-boot-learning-21-2-5/) - [Spring Boot 2.x基础教程:找回启动日志中的请求路径列表](http://blog.didispace.com/spring-boot-learning-21-2-6/) - [Spring Boot 2.x基础教程:使用SpringFox 3生成Swagger文档](http://blog.didispace.com/spring-boot-learning-21-2-7/) +- [Spring Boot 2.x基础教程:如何扩展XML格式的请求和响应](http://blog.didispace.com/spring-boot-learning-21-2-8/) ### 数据访问 @@ -109,7 +110,6 @@ - [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) - ### Web开发 - [Spring Boot 2.x基础教程:使用 Thymeleaf开发Web页面](http://blog.didispace.com/spring-boot-learning-21-4-1/) @@ -118,6 +118,13 @@ - [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) - [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) +### 常见问题 + +- [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) +- [为什么启动时候API路径都没了?](http://blog.didispace.com/spring-boot-learning-21-2-6/) +- [使用Java 8中LocalDate等时间日期类的问题解决](http://blog.didispace.com/Spring-Boot-And-Feign-Use-localdate/) +- [Request header is too large 如何解决?](https://blog.didispace.com/request-header-is-too-large/) + ## 版本资讯 ### 1.x到2.x diff --git a/2.x/README_zh.md b/2.x/README_zh.md index dda26e79..5d195321 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -4,7 +4,7 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) +**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) **如何支持**: 1. 关注我的公众号”**程序猿DD**“ @@ -79,6 +79,7 @@ - [Spring Boot 2.x基础教程:Swagger静态文档的生成](http://blog.didispace.com/spring-boot-learning-21-2-5/) - [Spring Boot 2.x基础教程:找回启动日志中的请求路径列表](http://blog.didispace.com/spring-boot-learning-21-2-6/) - [Spring Boot 2.x基础教程:使用SpringFox 3生成Swagger文档](http://blog.didispace.com/spring-boot-learning-21-2-7/) +- [Spring Boot 2.x基础教程:如何扩展XML格式的请求和响应](http://blog.didispace.com/spring-boot-learning-21-2-8/) ### 数据访问 @@ -120,6 +121,13 @@ - [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) - [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) +### 常见问题 + +- [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) +- [为什么启动时候API路径都没了?](http://blog.didispace.com/spring-boot-learning-21-2-6/) +- [使用Java 8中LocalDate等时间日期类的问题解决](http://blog.didispace.com/Spring-Boot-And-Feign-Use-localdate/) +- [Request header is too large 如何解决?](https://blog.didispace.com/request-header-is-too-large/) + ## 版本资讯 diff --git a/2.x/chapter2-8/pom.xml b/2.x/chapter2-8/pom.xml new file mode 100644 index 00000000..e2746409 --- /dev/null +++ b/2.x/chapter2-8/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + com.didispace + Chapter2-8 + 1.0.0 + jar + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + + org.projectlombok + lombok + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/2.x/chapter2-8/src/main/java/com/didispace/chapter28/Chapter28Application.java b/2.x/chapter2-8/src/main/java/com/didispace/chapter28/Chapter28Application.java new file mode 100755 index 00000000..6577db14 --- /dev/null +++ b/2.x/chapter2-8/src/main/java/com/didispace/chapter28/Chapter28Application.java @@ -0,0 +1,18 @@ +package com.didispace.chapter28; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + */ +@SpringBootApplication +public class Chapter28Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter28Application.class, args); + } + +} diff --git a/2.x/chapter2-8/src/main/java/com/didispace/chapter28/User.java b/2.x/chapter2-8/src/main/java/com/didispace/chapter28/User.java new file mode 100755 index 00000000..5c035bd4 --- /dev/null +++ b/2.x/chapter2-8/src/main/java/com/didispace/chapter28/User.java @@ -0,0 +1,26 @@ +package com.didispace.chapter28; + + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@JacksonXmlRootElement(localName = "User") +public class User { + + @JacksonXmlProperty(localName = "name") + private String name; + @JacksonXmlProperty(localName = "age") + private Integer age; + +} diff --git a/2.x/chapter2-8/src/main/java/com/didispace/chapter28/UserController.java b/2.x/chapter2-8/src/main/java/com/didispace/chapter28/UserController.java new file mode 100755 index 00000000..055b4042 --- /dev/null +++ b/2.x/chapter2-8/src/main/java/com/didispace/chapter28/UserController.java @@ -0,0 +1,27 @@ +package com.didispace.chapter28; + +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +/** + * + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + * + */ +@Controller +public class UserController { + + @PostMapping(value = "/user", + consumes = MediaType.APPLICATION_XML_VALUE, + produces = MediaType.APPLICATION_XML_VALUE) + @ResponseBody + public User create(@RequestBody User user) { + user.setName("didispace.com : " + user.getName()); + user.setAge(user.getAge() + 100); + return user; + } + +} \ No newline at end of file diff --git a/2.x/chapter2-8/src/main/resources/application.properties b/2.x/chapter2-8/src/main/resources/application.properties new file mode 100755 index 00000000..e69de29b diff --git a/2.x/pom.xml b/2.x/pom.xml index 68da28f3..9b88b0d4 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -25,7 +25,8 @@ chapter2-5 chapter2-6 chapter2-7 - + chapter2-8 + chapter3-1 From 40c3a236e1d47ef3eb24ce86e3caac979064f05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Wed, 16 Jun 2021 14:24:30 +0800 Subject: [PATCH 09/97] update group --- 1.x/README.md | 2 +- 1.x/README_zh.md | 2 +- README.md | 2 +- README_zh.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/1.x/README.md b/1.x/README.md index 4abf6dda..e5f191c2 100644 --- a/1.x/README.md +++ b/1.x/README.md @@ -4,7 +4,7 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) +**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) **如何支持**: 1. 关注我的公众号”**程序猿DD**“ diff --git a/1.x/README_zh.md b/1.x/README_zh.md index 4f9e75c1..b23d4a16 100644 --- a/1.x/README_zh.md +++ b/1.x/README_zh.md @@ -4,7 +4,7 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) +**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) **如何支持**: 1. 关注我的公众号”**程序猿DD**“ diff --git a/README.md b/README.md index 77d729ee..64bc8e36 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) +**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) **如何支持**: 1. 关注我的公众号”**程序猿DD**“ diff --git a/README_zh.md b/README_zh.md index 0c0946db..0eb939df 100644 --- a/README_zh.md +++ b/README_zh.md @@ -4,7 +4,7 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) +**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) **如何支持**: 1. 关注我的公众号”**程序猿DD**“ From 768fc9fc551fe72add74592551ccf9d04d446173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 17 Jun 2021 17:22:01 +0800 Subject: [PATCH 10/97] 1 --- 2.x/README_zh.md | 2 +- 2.x/chapter6-2/pom.xml | 58 +++++++++++++++++++ .../chapter62/Chapter62Application.java | 13 +++++ .../java/com/didispace/chapter62/Person.java | 22 +++++++ .../didispace/chapter62/PersonRepository.java | 10 ++++ .../src/main/resources/application.properties | 4 ++ .../didispace/chapter62/ApplicationTests.java | 41 +++++++++++++ .../src/test/resources/application.properties | 3 + .../src/test/resources/ldap-server.ldif | 18 ++++++ 2.x/pom.xml | 6 +- 10 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 2.x/chapter6-2/pom.xml create mode 100644 2.x/chapter6-2/src/main/java/com/didispace/chapter62/Chapter62Application.java create mode 100644 2.x/chapter6-2/src/main/java/com/didispace/chapter62/Person.java create mode 100644 2.x/chapter6-2/src/main/java/com/didispace/chapter62/PersonRepository.java create mode 100644 2.x/chapter6-2/src/main/resources/application.properties create mode 100644 2.x/chapter6-2/src/test/java/com/didispace/chapter62/ApplicationTests.java create mode 100644 2.x/chapter6-2/src/test/resources/application.properties create mode 100644 2.x/chapter6-2/src/test/resources/ldap-server.ldif diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 5d195321..434e80a3 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -110,7 +110,7 @@ **其他常见存储的使用** - [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) - +- [Spring Boot 2.x基础教程:使用LDAP来管理用户与组织数据](http://blog.didispace.com/spring-boot-learning-24-6-2/) ### Web开发 diff --git a/2.x/chapter6-2/pom.xml b/2.x/chapter6-2/pom.xml new file mode 100644 index 00000000..30cc85ae --- /dev/null +++ b/2.x/chapter6-2/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + com.didispace + chapter6-2 + 1.0.0 + jar + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + + UTF-8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-ldap + + + + com.unboundid + unboundid-ldapsdk + test + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Chapter62Application.java b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Chapter62Application.java new file mode 100644 index 00000000..5baa9594 --- /dev/null +++ b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Chapter62Application.java @@ -0,0 +1,13 @@ +package com.didispace.chapter62; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Chapter62Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter62Application.class, args); + } + +} diff --git a/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Person.java b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Person.java new file mode 100644 index 00000000..f8a9f439 --- /dev/null +++ b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Person.java @@ -0,0 +1,22 @@ +package com.didispace.chapter62; + +import lombok.Data; +import org.springframework.ldap.odm.annotations.*; + +import javax.naming.Name; + +@Entry(base = "ou=people,dc=didispace,dc=com", objectClasses = "inetOrgPerson") +@Data +public class Person { + + @Id + private Name id; + @DnAttribute(value = "uid", index = 3) + private String uid; + @Attribute(name = "cn") + private String commonName; + @Attribute(name = "sn") + private String suerName; + private String userPassword; + +} diff --git a/2.x/chapter6-2/src/main/java/com/didispace/chapter62/PersonRepository.java b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/PersonRepository.java new file mode 100644 index 00000000..53258324 --- /dev/null +++ b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/PersonRepository.java @@ -0,0 +1,10 @@ +package com.didispace.chapter62; + +import org.springframework.data.repository.CrudRepository; + +import javax.naming.Name; + +public interface PersonRepository extends CrudRepository { + + +} \ No newline at end of file diff --git a/2.x/chapter6-2/src/main/resources/application.properties b/2.x/chapter6-2/src/main/resources/application.properties new file mode 100644 index 00000000..4b3fab0b --- /dev/null +++ b/2.x/chapter6-2/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#spring.ldap.urls=ldap://localhost:1235 +#spring.ldap.base=dc=didispace,dc=com +#spring.ldap.username=didispace +#spring.ldap.password=123456 \ No newline at end of file diff --git a/2.x/chapter6-2/src/test/java/com/didispace/chapter62/ApplicationTests.java b/2.x/chapter6-2/src/test/java/com/didispace/chapter62/ApplicationTests.java new file mode 100644 index 00000000..955e680f --- /dev/null +++ b/2.x/chapter6-2/src/test/java/com/didispace/chapter62/ApplicationTests.java @@ -0,0 +1,41 @@ +package com.didispace.chapter62; + +import com.didispace.Person; +import com.didispace.PersonRepository; +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; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ApplicationTests { + + @Autowired + private PersonRepository personRepository; + + @Test + public void findAll() throws Exception { + + personRepository.findAll().forEach(p -> { + System.out.println(p); + }); + + } + + @Test + public void save() throws Exception { + Person person = new Person(); + person.setUid("uid:1"); + person.setSuerName("AAA"); + person.setCommonName("aaa"); + person.setUserPassword("123456"); + personRepository.save(person); + + personRepository.findAll().forEach(p -> { + System.out.println(p); + }); + } + +} diff --git a/2.x/chapter6-2/src/test/resources/application.properties b/2.x/chapter6-2/src/test/resources/application.properties new file mode 100644 index 00000000..08bbb56b --- /dev/null +++ b/2.x/chapter6-2/src/test/resources/application.properties @@ -0,0 +1,3 @@ +spring.ldap.embedded.ldif=ldap-server.ldif +spring.ldap.embedded.base-dn=dc=didispace,dc=com + diff --git a/2.x/chapter6-2/src/test/resources/ldap-server.ldif b/2.x/chapter6-2/src/test/resources/ldap-server.ldif new file mode 100644 index 00000000..4eac0611 --- /dev/null +++ b/2.x/chapter6-2/src/test/resources/ldap-server.ldif @@ -0,0 +1,18 @@ +dn: dc=didispace,dc=com +objectClass: top +objectClass: domain + +dn: ou=people,dc=didispace,dc=com +objectclass: top +objectclass: organizationalUnit +ou: people + +dn: uid=ben,ou=people,dc=didispace,dc=com +objectclass: top +objectclass: person +objectclass: organizationalPerson +objectclass: inetOrgPerson +cn: didi +sn: zhaiyongchao +uid: didi +userPassword: {SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ= diff --git a/2.x/pom.xml b/2.x/pom.xml index 9b88b0d4..56af88a5 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -62,9 +62,9 @@ chapter6-1 - - - + chapter6-2 + + From 07bf68ae5ac0dbdaea5582e63aa57705adecf907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Fri, 18 Jun 2021 16:33:30 +0800 Subject: [PATCH 11/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8LDAP=E6=9D=A5?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=94=A8=E6=88=B7=E4=B8=8E=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter6-2/pom.xml | 6 +++ .../java/com/didispace/chapter62/Person.java | 2 +- .../src/main/resources/application.properties | 2 +- .../didispace/chapter62/ApplicationTests.java | 49 +++++++++---------- .../src/test/resources/application.properties | 2 +- .../src/test/resources/ldap-server.ldif | 2 + 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/2.x/chapter6-2/pom.xml b/2.x/chapter6-2/pom.xml index 30cc85ae..1cd64699 100644 --- a/2.x/chapter6-2/pom.xml +++ b/2.x/chapter6-2/pom.xml @@ -32,6 +32,12 @@ spring-boot-starter-data-ldap + + org.projectlombok + lombok + provided + + com.unboundid unboundid-ldapsdk diff --git a/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Person.java b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Person.java index f8a9f439..cc078f67 100644 --- a/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Person.java +++ b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Person.java @@ -16,7 +16,7 @@ public class Person { @Attribute(name = "cn") private String commonName; @Attribute(name = "sn") - private String suerName; + private String userName; private String userPassword; } diff --git a/2.x/chapter6-2/src/main/resources/application.properties b/2.x/chapter6-2/src/main/resources/application.properties index 4b3fab0b..d2726e89 100644 --- a/2.x/chapter6-2/src/main/resources/application.properties +++ b/2.x/chapter6-2/src/main/resources/application.properties @@ -1,4 +1,4 @@ #spring.ldap.urls=ldap://localhost:1235 #spring.ldap.base=dc=didispace,dc=com #spring.ldap.username=didispace -#spring.ldap.password=123456 \ No newline at end of file +#spring.ldap.password=123456 diff --git a/2.x/chapter6-2/src/test/java/com/didispace/chapter62/ApplicationTests.java b/2.x/chapter6-2/src/test/java/com/didispace/chapter62/ApplicationTests.java index 955e680f..b1e2a2fd 100644 --- a/2.x/chapter6-2/src/test/java/com/didispace/chapter62/ApplicationTests.java +++ b/2.x/chapter6-2/src/test/java/com/didispace/chapter62/ApplicationTests.java @@ -1,41 +1,38 @@ package com.didispace.chapter62; -import com.didispace.Person; -import com.didispace.PersonRepository; -import org.junit.Test; -import org.junit.runner.RunWith; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) +@Slf4j @SpringBootTest public class ApplicationTests { - @Autowired - private PersonRepository personRepository; + @Autowired + private PersonRepository personRepository; - @Test - public void findAll() throws Exception { + @Test + public void findAll() { - personRepository.findAll().forEach(p -> { - System.out.println(p); - }); + personRepository.findAll().forEach(p -> { + System.out.println(p); + }); - } + } - @Test - public void save() throws Exception { - Person person = new Person(); - person.setUid("uid:1"); - person.setSuerName("AAA"); - person.setCommonName("aaa"); - person.setUserPassword("123456"); - personRepository.save(person); + @Test + public void save() { + Person person = new Person(); + person.setUid("uid:1"); + person.setUserName("AAA"); + person.setCommonName("aaa"); + person.setUserPassword("123456"); + personRepository.save(person); - personRepository.findAll().forEach(p -> { - System.out.println(p); - }); - } + personRepository.findAll().forEach(p -> { + System.out.println(p); + }); + } } diff --git a/2.x/chapter6-2/src/test/resources/application.properties b/2.x/chapter6-2/src/test/resources/application.properties index 08bbb56b..55e19357 100644 --- a/2.x/chapter6-2/src/test/resources/application.properties +++ b/2.x/chapter6-2/src/test/resources/application.properties @@ -1,3 +1,3 @@ -spring.ldap.embedded.ldif=ldap-server.ldif +spring.ldap.embedded.ldif=classpath:ldap-server.ldif spring.ldap.embedded.base-dn=dc=didispace,dc=com diff --git a/2.x/chapter6-2/src/test/resources/ldap-server.ldif b/2.x/chapter6-2/src/test/resources/ldap-server.ldif index 4eac0611..353a4939 100644 --- a/2.x/chapter6-2/src/test/resources/ldap-server.ldif +++ b/2.x/chapter6-2/src/test/resources/ldap-server.ldif @@ -1,6 +1,8 @@ dn: dc=didispace,dc=com objectClass: top objectClass: domain +objectclass: extensibleObject +dc: didispace dn: ou=people,dc=didispace,dc=com objectclass: top From 6ddbfc0ae87250703324d0587a3149da814f9943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Sat, 19 Jun 2021 15:07:15 +0800 Subject: [PATCH 12/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8Redis=E7=9A=84?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E8=AE=A2=E9=98=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 3 + 2.x/README_zh.md | 3 +- 2.x/chapter5-5/.gitignore | 29 +++++++++ 2.x/chapter5-5/pom.xml | 64 +++++++++++++++++++ .../chapter55/Chapter55Application.java | 61 ++++++++++++++++++ .../src/main/resources/application.properties | 7 ++ 2.x/pom.xml | 4 +- 7 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 2.x/chapter5-5/.gitignore create mode 100644 2.x/chapter5-5/pom.xml create mode 100644 2.x/chapter5-5/src/main/java/com/didispace/chapter55/Chapter55Application.java create mode 100644 2.x/chapter5-5/src/main/resources/application.properties diff --git a/2.x/README.md b/2.x/README.md index c22d7d01..68e31e2d 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -105,10 +105,12 @@ - [Spring Boot 2.x基础教程:EhCache缓存的使用](http://blog.didispace.com/spring-boot-learning-21-5-2/) - [Spring Boot 2.x基础教程:使用EhCache缓存集群](http://blog.didispace.com/spring-boot-learning-21-5-3/) - [Spring Boot 2.x基础教程:使用集中式缓存Redis](http://blog.didispace.com/spring-boot-learning-21-5-4/) +- [Spring Boot 2.x基础教程:使用Redis的发布订阅功能](http://blog.didispace.com/spring-boot-learning-25-5-5/) **其他常见存储的使用** - [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) +- [Spring Boot 2.x基础教程:使用LDAP来管理用户与组织数据](http://blog.didispace.com/spring-boot-learning-24-6-2/) ### Web开发 @@ -144,6 +146,7 @@ - [Spring Boot 2.4.0 正式发布!全新的配置处理机制,拥抱云原生!](http://blog.didispace.com/spring-boot-2-4-0-ga/) - [Spring Boot 2.4.1 发布,修正大量2.4全新配置机制的Bug](http://blog.didispace.com/spring-boot-2-4-1-release/) - [Spring Boot 2.5.0 发布:支持Java16、Gradle 7、Datasource初始化调整](https://blog.didispace.com/spring-boot-2-5-0-release/) +- [Spring Boot 2.5.1 发布](https://blog.didispace.com/spring-boot-2-5-1-release/) ## 我的公众号 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 434e80a3..1a094b95 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -106,13 +106,13 @@ - [Spring Boot 2.x基础教程:EhCache缓存的使用](http://blog.didispace.com/spring-boot-learning-21-5-2/) - [Spring Boot 2.x基础教程:使用EhCache缓存集群](http://blog.didispace.com/spring-boot-learning-21-5-3/) - [Spring Boot 2.x基础教程:使用集中式缓存Redis](http://blog.didispace.com/spring-boot-learning-21-5-4/) +- [Spring Boot 2.x基础教程:使用Redis的发布订阅功能](http://blog.didispace.com/spring-boot-learning-25-5-5/) **其他常见存储的使用** - [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) - [Spring Boot 2.x基础教程:使用LDAP来管理用户与组织数据](http://blog.didispace.com/spring-boot-learning-24-6-2/) - ### Web开发 - [Spring Boot 2.x基础教程:使用 Thymeleaf开发Web页面](http://blog.didispace.com/spring-boot-learning-21-4-1/) @@ -148,6 +148,7 @@ - [Spring Boot 2.4.0 正式发布!全新的配置处理机制,拥抱云原生!](http://blog.didispace.com/spring-boot-2-4-0-ga/) - [Spring Boot 2.4.1 发布,修正大量2.4全新配置机制的Bug](http://blog.didispace.com/spring-boot-2-4-1-release/) - [Spring Boot 2.5.0 发布:支持Java16、Gradle 7、Datasource初始化调整](https://blog.didispace.com/spring-boot-2-5-0-release/) +- [Spring Boot 2.5.1 发布](https://blog.didispace.com/spring-boot-2-5-1-release/) ## 推荐内容 diff --git a/2.x/chapter5-5/.gitignore b/2.x/chapter5-5/.gitignore new file mode 100644 index 00000000..153c9335 --- /dev/null +++ b/2.x/chapter5-5/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/2.x/chapter5-5/pom.xml b/2.x/chapter5-5/pom.xml new file mode 100644 index 00000000..6d630aed --- /dev/null +++ b/2.x/chapter5-5/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter5-5 + 0.0.1-SNAPSHOT + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.apache.commons + commons-pool2 + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter5-5/src/main/java/com/didispace/chapter55/Chapter55Application.java b/2.x/chapter5-5/src/main/java/com/didispace/chapter55/Chapter55Application.java new file mode 100644 index 00000000..8da3b8b0 --- /dev/null +++ b/2.x/chapter5-5/src/main/java/com/didispace/chapter55/Chapter55Application.java @@ -0,0 +1,61 @@ +package com.didispace.chapter55; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.redis.connection.Message; +import org.springframework.data.redis.connection.MessageListener; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.nio.charset.StandardCharsets; + +@SpringBootApplication +public class Chapter55Application { + + private static String CHANNEL = "didispace"; + + public static void main(String[] args) { + SpringApplication.run(Chapter55Application.class, args); + } + + @RestController + static class RedisController { + + private RedisTemplate redisTemplate; + + public RedisController(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + @GetMapping("/publish") + public void publish(@RequestParam String message) { + // 发送消息 + redisTemplate.convertAndSend(CHANNEL, message); + } + + } + + @Slf4j + @Service + static class MessageSubscriber { + + public MessageSubscriber(RedisTemplate redisTemplate) { + RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection(); + redisConnection.subscribe(new MessageListener() { + @Override + public void onMessage(Message message, byte[] bytes) { + // 收到消息的处理逻辑 + log.info("Receive message : " + message); + } + }, CHANNEL.getBytes(StandardCharsets.UTF_8)); + + } + + } + +} diff --git a/2.x/chapter5-5/src/main/resources/application.properties b/2.x/chapter5-5/src/main/resources/application.properties new file mode 100644 index 00000000..2992f608 --- /dev/null +++ b/2.x/chapter5-5/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.redis.host=localhost +spring.redis.port=6379 +spring.redis.lettuce.pool.max-idle=8 +spring.redis.lettuce.pool.max-active=8 +spring.redis.lettuce.pool.max-wait=-1ms +spring.redis.lettuce.pool.min-idle=0 +spring.redis.lettuce.shutdown-timeout=100ms diff --git a/2.x/pom.xml b/2.x/pom.xml index 56af88a5..0b23ac0b 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -58,7 +58,9 @@ chapter5-2 chapter5-3 chapter5-4 - + chapter5-5 + + chapter6-1 From 406922e2311a14762c668268353ce779da073072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Tue, 13 Jul 2021 15:27:07 +0800 Subject: [PATCH 13/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8@Scheduled?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 4 ++ 2.x/README_zh.md | 4 ++ 2.x/chapter7-1/pom.xml | 49 +++++++++++++++++++ .../chapter71/Chapter71Application.java | 15 ++++++ .../didispace/chapter71/ScheduledTasks.java | 24 +++++++++ .../src/main/resources/application.properties | 0 2.x/pom.xml | 9 ++-- 7 files changed, 101 insertions(+), 4 deletions(-) create mode 100755 2.x/chapter7-1/pom.xml create mode 100755 2.x/chapter7-1/src/main/java/com/didispace/chapter71/Chapter71Application.java create mode 100644 2.x/chapter7-1/src/main/java/com/didispace/chapter71/ScheduledTasks.java create mode 100644 2.x/chapter7-1/src/main/resources/application.properties diff --git a/2.x/README.md b/2.x/README.md index 68e31e2d..0dc709b8 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -120,6 +120,10 @@ - [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) - [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) +### 其他功能 + +- [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) + ### 常见问题 - [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 1a094b95..24efde5c 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -121,6 +121,10 @@ - [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) - [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) +### 其他功能 + +- [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) + ### 常见问题 - [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) diff --git a/2.x/chapter7-1/pom.xml b/2.x/chapter7-1/pom.xml new file mode 100755 index 00000000..45945209 --- /dev/null +++ b/2.x/chapter7-1/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-1 + 0.0.1-SNAPSHOT + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter7-1/src/main/java/com/didispace/chapter71/Chapter71Application.java b/2.x/chapter7-1/src/main/java/com/didispace/chapter71/Chapter71Application.java new file mode 100755 index 00000000..95fd0d2d --- /dev/null +++ b/2.x/chapter7-1/src/main/java/com/didispace/chapter71/Chapter71Application.java @@ -0,0 +1,15 @@ +package com.didispace.chapter71; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +@EnableScheduling +@SpringBootApplication +public class Chapter71Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter71Application.class, args); + } + +} diff --git a/2.x/chapter7-1/src/main/java/com/didispace/chapter71/ScheduledTasks.java b/2.x/chapter7-1/src/main/java/com/didispace/chapter71/ScheduledTasks.java new file mode 100644 index 00000000..27f1d0db --- /dev/null +++ b/2.x/chapter7-1/src/main/java/com/didispace/chapter71/ScheduledTasks.java @@ -0,0 +1,24 @@ +package com.didispace.chapter71; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.util.Date; + +@Slf4j +@Component +@AllArgsConstructor +public class ScheduledTasks { + + private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); + + + @Scheduled(fixedRate = 5000) + public void reportCurrentTime() { + log.info("现在时间:" + dateFormat.format(new Date())); + } + +} \ No newline at end of file diff --git a/2.x/chapter7-1/src/main/resources/application.properties b/2.x/chapter7-1/src/main/resources/application.properties new file mode 100644 index 00000000..e69de29b diff --git a/2.x/pom.xml b/2.x/pom.xml index 0b23ac0b..79a206b6 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -26,7 +26,8 @@ chapter2-6 chapter2-7 chapter2-8 - + + chapter3-1 @@ -69,10 +70,10 @@ - + chapter7-1 - + + - From ec1c5bb36f83748142f1f1df09048c1e3131dc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Tue, 20 Jul 2021 15:45:21 +0800 Subject: [PATCH 14/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8Elastic=20Job?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 3 +- 2.x/README_zh.md | 4 +- 2.x/chapter7-2/pom.xml | 50 +++++++++++++++++++ .../chapter72/Chapter72Application.java | 13 +++++ .../com/didispace/chapter72/MySimpleJob.java | 17 +++++++ .../src/main/resources/application.properties | 7 +++ 2.x/chapter7-3/pom.xml | 50 +++++++++++++++++++ .../chapter73/Chapter73Application.java | 13 +++++ .../didispace/chapter73/MyShardingJob.java | 27 ++++++++++ .../src/main/resources/application.properties | 9 ++++ 2.x/pom.xml | 7 +-- 11 files changed, 194 insertions(+), 6 deletions(-) create mode 100755 2.x/chapter7-2/pom.xml create mode 100755 2.x/chapter7-2/src/main/java/com/didispace/chapter72/Chapter72Application.java create mode 100644 2.x/chapter7-2/src/main/java/com/didispace/chapter72/MySimpleJob.java create mode 100644 2.x/chapter7-2/src/main/resources/application.properties create mode 100755 2.x/chapter7-3/pom.xml create mode 100755 2.x/chapter7-3/src/main/java/com/didispace/chapter73/Chapter73Application.java create mode 100644 2.x/chapter7-3/src/main/java/com/didispace/chapter73/MyShardingJob.java create mode 100644 2.x/chapter7-3/src/main/resources/application.properties diff --git a/2.x/README.md b/2.x/README.md index 0dc709b8..3586fbbe 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -120,9 +120,10 @@ - [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) - [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) -### 其他功能 +### 任务管理 - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) +- [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) ### 常见问题 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 24efde5c..9023a7ac 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -121,9 +121,10 @@ - [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) - [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) -### 其他功能 +### 任务管理 - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) +- [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) ### 常见问题 @@ -132,7 +133,6 @@ - [使用Java 8中LocalDate等时间日期类的问题解决](http://blog.didispace.com/Spring-Boot-And-Feign-Use-localdate/) - [Request header is too large 如何解决?](https://blog.didispace.com/request-header-is-too-large/) - ## 版本资讯 ### 1.x到2.x diff --git a/2.x/chapter7-2/pom.xml b/2.x/chapter7-2/pom.xml new file mode 100755 index 00000000..93028618 --- /dev/null +++ b/2.x/chapter7-2/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-2 + 0.0.1-SNAPSHOT + + + 1.8 + + + + + org.apache.shardingsphere.elasticjob + elasticjob-lite-spring-boot-starter + 3.0.0 + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter7-2/src/main/java/com/didispace/chapter72/Chapter72Application.java b/2.x/chapter7-2/src/main/java/com/didispace/chapter72/Chapter72Application.java new file mode 100755 index 00000000..236357d8 --- /dev/null +++ b/2.x/chapter7-2/src/main/java/com/didispace/chapter72/Chapter72Application.java @@ -0,0 +1,13 @@ +package com.didispace.chapter72; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Chapter72Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter72Application.class, args); + } + +} diff --git a/2.x/chapter7-2/src/main/java/com/didispace/chapter72/MySimpleJob.java b/2.x/chapter7-2/src/main/java/com/didispace/chapter72/MySimpleJob.java new file mode 100644 index 00000000..242a8168 --- /dev/null +++ b/2.x/chapter7-2/src/main/java/com/didispace/chapter72/MySimpleJob.java @@ -0,0 +1,17 @@ +package com.didispace.chapter72; + +import lombok.extern.slf4j.Slf4j; +import org.apache.shardingsphere.elasticjob.api.ShardingContext; +import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class MySimpleJob implements SimpleJob { + + @Override + public void execute(ShardingContext context) { + log.info("MySimpleJob start : didispace.com {}", System.currentTimeMillis()); + } + +} \ No newline at end of file diff --git a/2.x/chapter7-2/src/main/resources/application.properties b/2.x/chapter7-2/src/main/resources/application.properties new file mode 100644 index 00000000..38bca408 --- /dev/null +++ b/2.x/chapter7-2/src/main/resources/application.properties @@ -0,0 +1,7 @@ + +elasticjob.reg-center.server-lists=localhost:2181 +elasticjob.reg-center.namespace=didispace + +elasticjob.jobs.my-simple-job.elastic-job-class=com.didispace.chapter72.MySimpleJob +elasticjob.jobs.my-simple-job.cron=0/5 * * * * ? +elasticjob.jobs.my-simple-job.sharding-total-count=1 diff --git a/2.x/chapter7-3/pom.xml b/2.x/chapter7-3/pom.xml new file mode 100755 index 00000000..55b3c184 --- /dev/null +++ b/2.x/chapter7-3/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-3 + 0.0.1-SNAPSHOT + + + 1.8 + + + + + org.apache.shardingsphere.elasticjob + elasticjob-lite-spring-boot-starter + 3.0.0 + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter7-3/src/main/java/com/didispace/chapter73/Chapter73Application.java b/2.x/chapter7-3/src/main/java/com/didispace/chapter73/Chapter73Application.java new file mode 100755 index 00000000..5c62c3e6 --- /dev/null +++ b/2.x/chapter7-3/src/main/java/com/didispace/chapter73/Chapter73Application.java @@ -0,0 +1,13 @@ +package com.didispace.chapter73; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Chapter73Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter73Application.class, args); + } + +} diff --git a/2.x/chapter7-3/src/main/java/com/didispace/chapter73/MyShardingJob.java b/2.x/chapter7-3/src/main/java/com/didispace/chapter73/MyShardingJob.java new file mode 100644 index 00000000..039eb5b4 --- /dev/null +++ b/2.x/chapter7-3/src/main/java/com/didispace/chapter73/MyShardingJob.java @@ -0,0 +1,27 @@ +package com.didispace.chapter73; + +import lombok.extern.slf4j.Slf4j; +import org.apache.shardingsphere.elasticjob.api.ShardingContext; +import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class MyShardingJob implements SimpleJob { + + @Override + public void execute(ShardingContext context) { + switch (context.getShardingItem()) { + case 0: + log.info("do something by sharding item 0"); + break; + case 1: + log.info("do something by sharding item 1"); + break; + case 2: + log.info("do something by sharding item 2"); + break; + } + } + +} \ No newline at end of file diff --git a/2.x/chapter7-3/src/main/resources/application.properties b/2.x/chapter7-3/src/main/resources/application.properties new file mode 100644 index 00000000..92517831 --- /dev/null +++ b/2.x/chapter7-3/src/main/resources/application.properties @@ -0,0 +1,9 @@ +elasticjob.reg-center.server-lists=localhost:2181 +elasticjob.reg-center.namespace=didispace + + +elasticjob.jobs.my-sharding-job.elastic-job-class=com.didispace.chapter73.MyShardingJob +elasticjob.jobs.my-sharding-job.cron=0/5 * * * * ? +elasticjob.jobs.my-sharding-job.sharding-total-count=3 +elasticjob.jobs.my-elastic-job.sharding-item-parameters=0=BJ,1=SH,2=GZ + diff --git a/2.x/pom.xml b/2.x/pom.xml index 79a206b6..9da32871 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -71,9 +71,10 @@ chapter7-1 - - - + chapter7-2 + + + From aa4a2881f0b5c28e8b9226f3b0b9800c6611adef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Tue, 20 Jul 2021 15:48:17 +0800 Subject: [PATCH 15/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8Elastic=20Job?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter2-9/pom.xml | 75 +++++++++++++++++++ .../chapter29/Chapter29Application.java | 18 +++++ .../java/com/didispace/chapter29/User.java | 26 +++++++ .../didispace/chapter29/UserController.java | 27 +++++++ .../src/main/resources/application.properties | 0 5 files changed, 146 insertions(+) create mode 100644 2.x/chapter2-9/pom.xml create mode 100755 2.x/chapter2-9/src/main/java/com/didispace/chapter29/Chapter29Application.java create mode 100755 2.x/chapter2-9/src/main/java/com/didispace/chapter29/User.java create mode 100755 2.x/chapter2-9/src/main/java/com/didispace/chapter29/UserController.java create mode 100755 2.x/chapter2-9/src/main/resources/application.properties diff --git a/2.x/chapter2-9/pom.xml b/2.x/chapter2-9/pom.xml new file mode 100644 index 00000000..9f670750 --- /dev/null +++ b/2.x/chapter2-9/pom.xml @@ -0,0 +1,75 @@ + + + 4.0.0 + + com.didispace + chapter2-9 + 1.0.0 + jar + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.experimental + graphql-spring-boot-starter + 1.0.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + + org.projectlombok + lombok + provided + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-snapshots + https://repo.spring.io/snapshot + true + + + spring-milestones + https://repo.spring.io/milestone + + + + \ No newline at end of file diff --git a/2.x/chapter2-9/src/main/java/com/didispace/chapter29/Chapter29Application.java b/2.x/chapter2-9/src/main/java/com/didispace/chapter29/Chapter29Application.java new file mode 100755 index 00000000..c72319b2 --- /dev/null +++ b/2.x/chapter2-9/src/main/java/com/didispace/chapter29/Chapter29Application.java @@ -0,0 +1,18 @@ +package com.didispace.chapter29; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + */ +@SpringBootApplication +public class Chapter29Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter29Application.class, args); + } + +} diff --git a/2.x/chapter2-9/src/main/java/com/didispace/chapter29/User.java b/2.x/chapter2-9/src/main/java/com/didispace/chapter29/User.java new file mode 100755 index 00000000..40b2725f --- /dev/null +++ b/2.x/chapter2-9/src/main/java/com/didispace/chapter29/User.java @@ -0,0 +1,26 @@ +package com.didispace.chapter29; + + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@JacksonXmlRootElement(localName = "User") +public class User { + + @JacksonXmlProperty(localName = "name") + private String name; + @JacksonXmlProperty(localName = "age") + private Integer age; + +} diff --git a/2.x/chapter2-9/src/main/java/com/didispace/chapter29/UserController.java b/2.x/chapter2-9/src/main/java/com/didispace/chapter29/UserController.java new file mode 100755 index 00000000..d7711fa5 --- /dev/null +++ b/2.x/chapter2-9/src/main/java/com/didispace/chapter29/UserController.java @@ -0,0 +1,27 @@ +package com.didispace.chapter29; + +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +/** + * + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + * + */ +@Controller +public class UserController { + + @PostMapping(value = "/user", + consumes = MediaType.APPLICATION_XML_VALUE, + produces = MediaType.APPLICATION_XML_VALUE) + @ResponseBody + public User create(@RequestBody User user) { + user.setName("didispace.com : " + user.getName()); + user.setAge(user.getAge() + 100); + return user; + } + +} \ No newline at end of file diff --git a/2.x/chapter2-9/src/main/resources/application.properties b/2.x/chapter2-9/src/main/resources/application.properties new file mode 100755 index 00000000..e69de29b From 1fe9c48c771fb0564d0d5b5aa533f979a45f1c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Wed, 21 Jul 2021 17:53:44 +0800 Subject: [PATCH 16/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8Elastic=20Job?= =?UTF-8?q?=E7=9A=84=E5=88=86=E7=89=87=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/didispace/chapter73/MyShardingJob.java | 7 ++++--- 2.x/chapter7-3/src/main/resources/application.properties | 3 --- 2.x/pom.xml | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/2.x/chapter7-3/src/main/java/com/didispace/chapter73/MyShardingJob.java b/2.x/chapter7-3/src/main/java/com/didispace/chapter73/MyShardingJob.java index 039eb5b4..d1f535ae 100644 --- a/2.x/chapter7-3/src/main/java/com/didispace/chapter73/MyShardingJob.java +++ b/2.x/chapter7-3/src/main/java/com/didispace/chapter73/MyShardingJob.java @@ -11,15 +11,16 @@ public class MyShardingJob implements SimpleJob { @Override public void execute(ShardingContext context) { + // sharding-total-count=3,所以任务被分为三个分片 switch (context.getShardingItem()) { case 0: - log.info("do something by sharding item 0"); + log.info("分片1:执行任务"); break; case 1: - log.info("do something by sharding item 1"); + log.info("分片2:执行任务"); break; case 2: - log.info("do something by sharding item 2"); + log.info("分片3:执行任务"); break; } } diff --git a/2.x/chapter7-3/src/main/resources/application.properties b/2.x/chapter7-3/src/main/resources/application.properties index 92517831..cb7d3cd8 100644 --- a/2.x/chapter7-3/src/main/resources/application.properties +++ b/2.x/chapter7-3/src/main/resources/application.properties @@ -1,9 +1,6 @@ elasticjob.reg-center.server-lists=localhost:2181 elasticjob.reg-center.namespace=didispace - elasticjob.jobs.my-sharding-job.elastic-job-class=com.didispace.chapter73.MyShardingJob elasticjob.jobs.my-sharding-job.cron=0/5 * * * * ? elasticjob.jobs.my-sharding-job.sharding-total-count=3 -elasticjob.jobs.my-elastic-job.sharding-item-parameters=0=BJ,1=SH,2=GZ - diff --git a/2.x/pom.xml b/2.x/pom.xml index 9da32871..37415270 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -72,7 +72,7 @@ chapter7-1 chapter7-2 - + chapter7-3 From 118290f711cca392e19296a3ec7987aa544c73ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Wed, 21 Jul 2021 17:56:07 +0800 Subject: [PATCH 17/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8Elastic=20Job?= =?UTF-8?q?=E7=9A=84=E5=88=86=E7=89=87=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 2 ++ 2.x/README_zh.md | 1 + 2 files changed, 3 insertions(+) diff --git a/2.x/README.md b/2.x/README.md index 3586fbbe..2f79e3b5 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -124,6 +124,8 @@ - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) +- [Spring Boot 2.x基础教程:使用Elastic Job的分片配置](https://blog.didispace.com/spring-boot-learning-2-7-3) + ### 常见问题 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 9023a7ac..2a57f5ac 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -125,6 +125,7 @@ - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) +- [Spring Boot 2.x基础教程:使用Elastic Job的分片配置](https://blog.didispace.com/spring-boot-learning-2-7-3) ### 常见问题 From 44052ed3a86bc4bd8f7c7c5b2720f80f6a212cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:26:40 +0800 Subject: [PATCH 18/97] =?UTF-8?q?=E6=9E=84=E5=BB=BARESTful=20API=E4=B8=8E?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter2-1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter2-1/pom.xml b/2.x/chapter2-1/pom.xml index 8c292e60..3b306388 100644 --- a/2.x/chapter2-1/pom.xml +++ b/2.x/chapter2-1/pom.xml @@ -14,7 +14,7 @@ chapter2-1 0.0.1-SNAPSHOT chapter2-1 - Demo project for Spring Boot + 构建RESTful API与单元测试 1.8 From f745d84a37d904082900112a7d303e1a98d61996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:27:03 +0800 Subject: [PATCH 19/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8Swagger2=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=BC=BA=E5=A4=A7=E7=9A=84API=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter2-2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter2-2/pom.xml b/2.x/chapter2-2/pom.xml index aa373bc4..7d31c5eb 100644 --- a/2.x/chapter2-2/pom.xml +++ b/2.x/chapter2-2/pom.xml @@ -14,7 +14,7 @@ chapter2-2 0.0.1-SNAPSHOT chapter2-2 - Demo project for Spring Boot + 使用Swagger2构建强大的API文档 1.8 From 45743a4cbbec67a2f92c2ae6931d6fb0b8b9f92c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:27:36 +0800 Subject: [PATCH 20/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8JSR-303=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter2-3/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter2-3/pom.xml b/2.x/chapter2-3/pom.xml index 284c9d0d..da056f65 100644 --- a/2.x/chapter2-3/pom.xml +++ b/2.x/chapter2-3/pom.xml @@ -14,7 +14,7 @@ chapter2-3 0.0.1-SNAPSHOT chapter2-3 - Demo project for Spring Boot + 使用JSR-303实现请求参数校验 1.8 From fa96338a6c0ae5883efc64a369311f2e55e405f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:30:11 +0800 Subject: [PATCH 21/97] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter1-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter1-4/pom.xml b/2.x/chapter1-4/pom.xml index e64ae735..8c5539f1 100644 --- a/2.x/chapter1-4/pom.xml +++ b/2.x/chapter1-4/pom.xml @@ -12,7 +12,7 @@ chapter1-4 0.0.1-SNAPSHOT chapter1-1 - Demo project for Spring Boot + 配置元数据的应用 1.8 From 1611c4cc6cddf9625bab84da54d3dd56adcf6e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:30:32 +0800 Subject: [PATCH 22/97] =?UTF-8?q?2.4=E7=89=88=E6=9C=AC=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E9=85=8D=E7=BD=AE=E5=88=86=E7=BB=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter1-3/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter1-3/pom.xml b/2.x/chapter1-3/pom.xml index 75bb4754..93b6ec3a 100644 --- a/2.x/chapter1-3/pom.xml +++ b/2.x/chapter1-3/pom.xml @@ -12,7 +12,7 @@ chapter1-3 0.0.1-SNAPSHOT chapter1-3 - Demo project for Spring Boot + 2.4版本前后的配置分组配置 1.8 From cbb4892377bfe8686df13df806cbd7b32fe7c202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:30:57 +0800 Subject: [PATCH 23/97] =?UTF-8?q?2.4=E7=89=88=E6=9C=AC=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E5=A4=9A=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE=E4=B8=8E?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter1-2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter1-2/pom.xml b/2.x/chapter1-2/pom.xml index 3dd49659..4bee1018 100644 --- a/2.x/chapter1-2/pom.xml +++ b/2.x/chapter1-2/pom.xml @@ -12,7 +12,7 @@ chapter1-2 0.0.1-SNAPSHOT chapter1-2 - Demo project for Spring Boot + 2.4版本前后的多环境配置与配置激活 1.8 From b0e82aebdea1a4f62c61ad54a5eaef761730c3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:31:14 +0800 Subject: [PATCH 24/97] =?UTF-8?q?=E5=BF=AB=E9=80=9F=E5=85=A5=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter1-1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter1-1/pom.xml b/2.x/chapter1-1/pom.xml index d849128d..d4e872a6 100644 --- a/2.x/chapter1-1/pom.xml +++ b/2.x/chapter1-1/pom.xml @@ -12,7 +12,7 @@ chapter1-1 0.0.1-SNAPSHOT chapter1-1 - Demo project for Spring Boot + 快速入门 1.8 From a52c050aacf436c06cb270b99652d9940321aa8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:31:40 +0800 Subject: [PATCH 25/97] =?UTF-8?q?Swagger=E6=8E=A5=E5=8F=A3=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E4=B8=8E=E5=90=84=E5=85=83=E7=B4=A0=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=AF=A6=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter2-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter2-4/pom.xml b/2.x/chapter2-4/pom.xml index 8dcad73d..844ae4d1 100644 --- a/2.x/chapter2-4/pom.xml +++ b/2.x/chapter2-4/pom.xml @@ -14,7 +14,7 @@ chapter2-4 0.0.1-SNAPSHOT chapter2-4 - Demo project for Spring Boot + Swagger接口分类与各元素排序问题详解 1.8 From 6ac4845663c514992499e445b867a9d583f86bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:31:54 +0800 Subject: [PATCH 26/97] =?UTF-8?q?Swagger=E9=9D=99=E6=80=81=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E7=9A=84=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter2-5/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter2-5/pom.xml b/2.x/chapter2-5/pom.xml index 9ffaafe8..2b81ca3b 100644 --- a/2.x/chapter2-5/pom.xml +++ b/2.x/chapter2-5/pom.xml @@ -14,7 +14,7 @@ chapter2-5 0.0.1-SNAPSHOT chapter2-5 - Demo project for Spring Boot + Swagger静态文档的生成 1.8 From 6c797ffc846cbae3791ff367e1201be5bd2c82ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:32:19 +0800 Subject: [PATCH 27/97] =?UTF-8?q?=E6=89=BE=E5=9B=9E=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=B8=AD=E7=9A=84=E8=AF=B7=E6=B1=82=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter2-6/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter2-6/pom.xml b/2.x/chapter2-6/pom.xml index 09ba9399..f4252540 100644 --- a/2.x/chapter2-6/pom.xml +++ b/2.x/chapter2-6/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter2-6 0.0.1-SNAPSHOT + 找回启动日志中的请求路径列表 1.8 From cf654dcbd24596c9d8da6e37aff1b2d1e0fae185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:32:43 +0800 Subject: [PATCH 28/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8SpringFox3=E7=94=9F?= =?UTF-8?q?=E6=88=90Swagger=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter2-7/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter2-7/pom.xml b/2.x/chapter2-7/pom.xml index 882a8176..285eeeea 100644 --- a/2.x/chapter2-7/pom.xml +++ b/2.x/chapter2-7/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter2-7 0.0.1-SNAPSHOT + 使用SpringFox3生成Swagger文档 1.8 From 7e55b34ff2615be8eb18492eb9511972a04d9b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:33:17 +0800 Subject: [PATCH 29/97] =?UTF-8?q?=E5=A6=82=E4=BD=95=E6=89=A9=E5=B1=95XML?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E7=9A=84=E8=AF=B7=E6=B1=82=E5=92=8C=E5=93=8D?= =?UTF-8?q?=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter2-8/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/2.x/chapter2-8/pom.xml b/2.x/chapter2-8/pom.xml index e2746409..86a98950 100644 --- a/2.x/chapter2-8/pom.xml +++ b/2.x/chapter2-8/pom.xml @@ -4,9 +4,10 @@ 4.0.0 com.didispace - Chapter2-8 + chapter2-8 1.0.0 jar + 如何扩展XML格式的请求和响应 org.springframework.boot From bd19eb27caaffd1d6f460035d1ad7680c57f363a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:33:43 +0800 Subject: [PATCH 30/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8JdbcTemplate=E8=AE=BF?= =?UTF-8?q?=E9=97=AEMySQL=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-1/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter3-1/pom.xml b/2.x/chapter3-1/pom.xml index 4621591e..e70062b4 100644 --- a/2.x/chapter3-1/pom.xml +++ b/2.x/chapter3-1/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-1 0.0.1-SNAPSHOT + 使用JdbcTemplate访问MySQL数据库 1.8 From ee86666712cd235f52f33ff15502a1a5a168201f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:34:00 +0800 Subject: [PATCH 31/97] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90Hikari=E7=9A=84=E9=85=8D=E7=BD=AE=E8=AF=A6=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-2/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter3-2/pom.xml b/2.x/chapter3-2/pom.xml index 2de383a2..d3a5f35d 100644 --- a/2.x/chapter3-2/pom.xml +++ b/2.x/chapter3-2/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-2 0.0.1-SNAPSHOT + 默认数据源Hikari的配置详解 1.8 From aada619881e7572faa52d7208bcb3de60871a057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:34:17 +0800 Subject: [PATCH 32/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=9B=BD=E4=BA=A7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=9E=E6=8E=A5=E6=B1=A0Druid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-3/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter3-3/pom.xml b/2.x/chapter3-3/pom.xml index c83eddc6..63a0dbe3 100644 --- a/2.x/chapter3-3/pom.xml +++ b/2.x/chapter3-3/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-3 0.0.1-SNAPSHOT + 使用国产数据库连接池Druid 1.8 From dcdbce71bfa2c386108a5b66daa84067e3437b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:34:33 +0800 Subject: [PATCH 33/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8Spring=20Data=20JPA?= =?UTF-8?q?=E8=AE=BF=E9=97=AEMySQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-4/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter3-4/pom.xml b/2.x/chapter3-4/pom.xml index 602beb6d..d529c02b 100644 --- a/2.x/chapter3-4/pom.xml +++ b/2.x/chapter3-4/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-4 0.0.1-SNAPSHOT + 使用Spring Data JPA访问MySQL 1.8 From bc1798ec1d95430d738c252a4ad6fe8b28f4d443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:35:23 +0800 Subject: [PATCH 34/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8MyBatis=E8=AE=BF?= =?UTF-8?q?=E9=97=AEMySQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-5/pom.xml | 1 + 2.x/pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/2.x/chapter3-5/pom.xml b/2.x/chapter3-5/pom.xml index 2cb4f499..43bfeb2a 100644 --- a/2.x/chapter3-5/pom.xml +++ b/2.x/chapter3-5/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-5 0.0.1-SNAPSHOT + 使用MyBatis访问MySQL 1.8 diff --git a/2.x/pom.xml b/2.x/pom.xml index 37415270..d367e897 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -34,8 +34,8 @@ chapter3-2 chapter3-3 chapter3-4 - chapter3-5 - chapter3-6 + chapter3-5 + chapter3-6 chapter3-7 chapter3-8 chapter3-9 From 4e3ec310d277a25c998d4502d153aa1e00cecbec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:35:46 +0800 Subject: [PATCH 35/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8MyBatis=EF=BC=88xml?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=B9=E5=BC=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-6/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter3-6/pom.xml b/2.x/chapter3-6/pom.xml index 2f515975..97869305 100644 --- a/2.x/chapter3-6/pom.xml +++ b/2.x/chapter3-6/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-6 0.0.1-SNAPSHOT + 使用MyBatis(xml配置方式) 1.8 From 401b9e6997510cacc83704d3604992a01f9cd0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:36:03 +0800 Subject: [PATCH 36/97] =?UTF-8?q?JdbcTemplate=E7=9A=84=E5=A4=9A=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-7/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter3-7/pom.xml b/2.x/chapter3-7/pom.xml index f8314a33..589d40ec 100644 --- a/2.x/chapter3-7/pom.xml +++ b/2.x/chapter3-7/pom.xml @@ -13,7 +13,7 @@ com.didispace chapter3-7 0.0.1-SNAPSHOT - 使用JDBCTemplate的多数据源配置 + JdbcTemplate的多数据源配置 1.8 From 9643954ba203c99b2d691ec2d7690a195fa7ba01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:36:17 +0800 Subject: [PATCH 37/97] =?UTF-8?q?Spring=20Data=20JPA=E7=9A=84=E5=A4=9A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=BA=90=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-8/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter3-8/pom.xml b/2.x/chapter3-8/pom.xml index cd677906..fcb9d03a 100644 --- a/2.x/chapter3-8/pom.xml +++ b/2.x/chapter3-8/pom.xml @@ -13,7 +13,7 @@ com.didispace chapter3-8 0.0.1-SNAPSHOT - 使用spring-data-jpa的多数据源配置 + Spring Data JPA的多数据源配置 1.8 From 3cf14689668c5a3a9fbae2f04bc812b8e993eb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:36:33 +0800 Subject: [PATCH 38/97] =?UTF-8?q?MyBatis=E7=9A=84=E5=A4=9A=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-9/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter3-9/pom.xml b/2.x/chapter3-9/pom.xml index f8572620..c8f731ef 100644 --- a/2.x/chapter3-9/pom.xml +++ b/2.x/chapter3-9/pom.xml @@ -13,7 +13,7 @@ com.didispace chapter3-9 0.0.1-SNAPSHOT - 使用MyBatis的多数据源配置 + MyBatis的多数据源配置 1.8 From 2533d8e1feb043df5c4fa1153f196d511c875036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:36:52 +0800 Subject: [PATCH 39/97] =?UTF-8?q?=E4=BA=8B=E5=8A=A1=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=85=A5=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-10/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter3-10/pom.xml b/2.x/chapter3-10/pom.xml index 9b2abc07..72162203 100644 --- a/2.x/chapter3-10/pom.xml +++ b/2.x/chapter3-10/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-10 0.0.1-SNAPSHOT + 事务管理入门 1.8 From f3ee045c01c9e44e0631377e2d5d646275bd1411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:37:08 +0800 Subject: [PATCH 40/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8Flyway=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=95=B0=E6=8D=AE=E5=BA=93=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-11/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter3-11/pom.xml b/2.x/chapter3-11/pom.xml index ca51dc20..c9692e8d 100644 --- a/2.x/chapter3-11/pom.xml +++ b/2.x/chapter3-11/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-11 0.0.1-SNAPSHOT + 使用Flyway管理数据库版本 1.8 From d2771e64788e9344ef864a0066b960a41347d9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:37:47 +0800 Subject: [PATCH 41/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8JTA=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=A4=9A=E6=95=B0=E6=8D=AE=E6=BA=90=E7=9A=84=E4=BA=8B=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-12/pom.xml | 1 + 2.x/pom.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/2.x/chapter3-12/pom.xml b/2.x/chapter3-12/pom.xml index f097b682..a61772d3 100644 --- a/2.x/chapter3-12/pom.xml +++ b/2.x/chapter3-12/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-12 0.0.1-SNAPSHOT + 使用JTA实现多数据源的事务 1.8 diff --git a/2.x/pom.xml b/2.x/pom.xml index d367e897..06cdc815 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -41,7 +41,7 @@ chapter3-9 chapter3-10 chapter3-11 - chapter3-12 + chapter3-12 chapter3-13 From e1769e09626a822d1c9c4fefe817a1267192c7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:38:02 +0800 Subject: [PATCH 42/97] =?UTF-8?q?2.5=E7=89=88=E6=9C=AC=E4=B9=8B=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter3-13/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter3-13/pom.xml b/2.x/chapter3-13/pom.xml index 8fecff2e..de7746d3 100644 --- a/2.x/chapter3-13/pom.xml +++ b/2.x/chapter3-13/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter3-13 0.0.1-SNAPSHOT + 2.5版本之后的数据脚本初始化 1.8 From bfcfea35889896b50c5b50681ce8d4d77014278c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:38:26 +0800 Subject: [PATCH 43/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20Thymeleaf=E5=BC=80?= =?UTF-8?q?=E5=8F=91Web=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter4-1/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter4-1/pom.xml b/2.x/chapter4-1/pom.xml index e8191b85..07c54958 100644 --- a/2.x/chapter4-1/pom.xml +++ b/2.x/chapter4-1/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter4-1 0.0.1-SNAPSHOT + 使用 Thymeleaf开发Web页面 1.8 From b91099d8d2f607e7fd0e97ba9ab947b32234ec8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:38:49 +0800 Subject: [PATCH 44/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20ECharts=20=E7=BB=98?= =?UTF-8?q?=E5=88=B6=E6=8A=98=E7=BA=BF=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter4-2/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter4-2/pom.xml b/2.x/chapter4-2/pom.xml index d6022db9..26b9d0e6 100644 --- a/2.x/chapter4-2/pom.xml +++ b/2.x/chapter4-2/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter4-2 0.0.1-SNAPSHOT + 使用 ECharts 绘制折线图 1.8 From fda096905e4a46356bc8927109aed34939dbeeb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:39:09 +0800 Subject: [PATCH 45/97] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter4-3/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter4-3/pom.xml b/2.x/chapter4-3/pom.xml index 47dc30ce..21238608 100644 --- a/2.x/chapter4-3/pom.xml +++ b/2.x/chapter4-3/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter4-3 0.0.1-SNAPSHOT + 文件上传 1.8 From ccdaa070b295bd66789aa8a3b56de6060c8933a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:39:25 +0800 Subject: [PATCH 46/97] =?UTF-8?q?=E5=A4=9A=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter4-4/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter4-4/pom.xml b/2.x/chapter4-4/pom.xml index d575ab1d..49da68de 100644 --- a/2.x/chapter4-4/pom.xml +++ b/2.x/chapter4-4/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter4-4 0.0.1-SNAPSHOT + 多文件上传 1.8 From 559e12cb4e7063015c650660e745cfd32b968dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:40:36 +0800 Subject: [PATCH 47/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E5=86=85=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter5-1/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter5-1/pom.xml b/2.x/chapter5-1/pom.xml index 2af64776..19540eff 100644 --- a/2.x/chapter5-1/pom.xml +++ b/2.x/chapter5-1/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter5-1 0.0.1-SNAPSHOT + 使用进程内缓存 1.8 From fa21d0e9e7d661dad5a680a3d8931f6c4dd768c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:40:50 +0800 Subject: [PATCH 48/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E5=86=85=E7=BC=93=E5=AD=98=20EhCache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter5-2/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter5-2/pom.xml b/2.x/chapter5-2/pom.xml index bb82477e..affc2e9c 100644 --- a/2.x/chapter5-2/pom.xml +++ b/2.x/chapter5-2/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter5-2 0.0.1-SNAPSHOT + 使用进程内缓存 EhCache 1.8 From 593b19e6fb24160f2cc270563f986bce2f972588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:41:02 +0800 Subject: [PATCH 49/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8EhCache=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E9=9B=86=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter5-3/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter5-3/pom.xml b/2.x/chapter5-3/pom.xml index c0bb21fd..5c729543 100644 --- a/2.x/chapter5-3/pom.xml +++ b/2.x/chapter5-3/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter5-3 0.0.1-SNAPSHOT + 使用EhCache缓存集群 1.8 From 5cd65480f7c2b420b1ca77ddd21c4f1330194b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:41:24 +0800 Subject: [PATCH 50/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=9B=86=E4=B8=AD?= =?UTF-8?q?=E5=BC=8F=E7=BC=93=E5=AD=98Redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter5-4/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter5-4/pom.xml b/2.x/chapter5-4/pom.xml index c33d2854..1f4de65e 100644 --- a/2.x/chapter5-4/pom.xml +++ b/2.x/chapter5-4/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter5-4 0.0.1-SNAPSHOT + 使用集中式缓存Redis 1.8 From 9dfade97455f9729652e37b925c035a27ca8b6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:41:40 +0800 Subject: [PATCH 51/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8Redis=E7=9A=84=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter5-5/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter5-5/pom.xml b/2.x/chapter5-5/pom.xml index 6d630aed..dc1d2874 100644 --- a/2.x/chapter5-5/pom.xml +++ b/2.x/chapter5-5/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter5-5 0.0.1-SNAPSHOT + 使用Redis的发布订阅 1.8 From 966809163794ab143cfe492af9d86f05e8548dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:42:02 +0800 Subject: [PATCH 52/97] =?UTF-8?q?=20=E4=BD=BF=E7=94=A8MongoDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter6-1/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter6-1/pom.xml b/2.x/chapter6-1/pom.xml index 7c21c138..10a0116e 100755 --- a/2.x/chapter6-1/pom.xml +++ b/2.x/chapter6-1/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter6-1 0.0.1-SNAPSHOT + 使用MongoDB 1.8 From 9ab2bd5fc1975ecf6da5d3f37e6940ae08d62a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:42:18 +0800 Subject: [PATCH 53/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=BD=BB=E9=87=8F?= =?UTF-8?q?=E7=BA=A7=E6=A0=91=E7=8A=B6=E5=AD=98=E5=82=A8=20LDAP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter6-2/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter6-2/pom.xml b/2.x/chapter6-2/pom.xml index 1cd64699..dc1b63bd 100644 --- a/2.x/chapter6-2/pom.xml +++ b/2.x/chapter6-2/pom.xml @@ -7,6 +7,7 @@ chapter6-2 1.0.0 jar + 使用轻量级树状存储 LDAP org.springframework.boot From 8b382804c89f98a516789baac983b268a5eac81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:42:34 +0800 Subject: [PATCH 54/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8@Scheduled=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter7-1/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter7-1/pom.xml b/2.x/chapter7-1/pom.xml index 45945209..fc9142ad 100755 --- a/2.x/chapter7-1/pom.xml +++ b/2.x/chapter7-1/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter7-1 0.0.1-SNAPSHOT + 使用@Scheduled实现定时任务 1.8 From 2823ce127613d3d49b23b842defc52cd2c4b663c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:42:51 +0800 Subject: [PATCH 55/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8Elastic=20Job=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter7-2/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter7-2/pom.xml b/2.x/chapter7-2/pom.xml index 93028618..e1987da5 100755 --- a/2.x/chapter7-2/pom.xml +++ b/2.x/chapter7-2/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter7-2 0.0.1-SNAPSHOT + 使用Elastic Job实现定时任务 1.8 From 648b6d8eb7e4af09f2d1ed28c2d686f508c5ca25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:43:03 +0800 Subject: [PATCH 56/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8Elastic=20Job=E7=9A=84?= =?UTF-8?q?=E5=88=86=E7=89=87=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter7-3/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2.x/chapter7-3/pom.xml b/2.x/chapter7-3/pom.xml index 55b3c184..55d4ff9f 100755 --- a/2.x/chapter7-3/pom.xml +++ b/2.x/chapter7-3/pom.xml @@ -13,6 +13,7 @@ com.didispace chapter7-3 0.0.1-SNAPSHOT + 使用Elastic Job的分片配置 1.8 From 5f33cb5d0c4c0c37970d92f7a5092c511297a05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:44:37 +0800 Subject: [PATCH 57/97] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 79 +++++++++++++++++++++++---------------------- 2.x/README_zh.md | 83 +++++++++++++++++++++++------------------------- 2 files changed, 79 insertions(+), 83 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index 2f79e3b5..a6b40a1e 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -12,46 +12,6 @@ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 -## 特别赞助商 - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` - ## 教程目录(2.x版本) 连载中...Star关注支持一下,随时获得更新信息! @@ -159,3 +119,42 @@ +## 特别赞助商 + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + +
+ +> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` \ No newline at end of file diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 2a57f5ac..d5e8d2b2 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -13,46 +13,6 @@ > **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
-## 特别赞助商 - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` - ## 教程目录(2.x版本) 连载中...Star关注支持一下,随时获得更新信息! @@ -159,9 +119,6 @@ - [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 - [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 -- [GitHub](https://github.com/dyc87112/SpringBoot-Learning):Star支持一下呗 -- [Gitee](https://gitee.com/didispace/SpringBoot-Learning):Star支持一下呗 -- [Spring问答社区](http://www.spring4all.com/):如果您有什么问题,可以去这里发帖 - [Spring Boot基础教程](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 - [Spring Cloud基础教程](http://blog.didispace.com/Spring-Cloud%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网最早最全的免费Spring Cloud基础教程 @@ -172,3 +129,43 @@ ## 推荐我的书 ![](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png "在这里输入图片标题") + +## 特别赞助商 + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + +
+ +> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` \ No newline at end of file From feb99e5d7980edc7c4e400fa69c9ab7d99573c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:48:26 +0800 Subject: [PATCH 58/97] update --- README.md | 24 ++++++++++++------------ README_zh.md | 27 ++++++++++++--------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 64bc8e36..37f45d5e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Spring Boot基础教程 -本项目内容为[《Spring Boot基础教程》](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 +本项目内容为[《Spring Boot基础教程》](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! @@ -13,11 +13,21 @@ ## 教程目录 -- [Spring Boot 1.x 版本教程](./1.x) - [Spring Boot 2.x 版本教程](./2.x) +- [Spring Boot 1.x 版本教程](./1.x) > **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
+## 推荐内容 + +- [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 +- [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 +- [阿里云:ECS云服务器2折起](https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=wxfqkr0o&utm_source=wxfqkr0o) +- [腾讯云:轻松应对建站成本问题](https://cloud.tencent.com/redirect.php?redirect=1027&cps_key=f6a8af1297bfac40b9d10ffa1270029a&from=console) +- [Spring问答社区](http://www.spring4all.com/):如果您有什么问题,可以去这里发帖 +- [Spring Boot基础教程](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 +- [Spring Cloud基础教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 + ## 特别赞助商 @@ -58,16 +68,6 @@ > 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` -## 推荐内容 - -- [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 -- [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 -- [GitHub](https://github.com/dyc87112/SpringBoot-Learning):Star支持一下呗 -- [Gitee](https://gitee.com/didispace/SpringBoot-Learning):Star支持一下呗 -- [Spring问答社区](http://www.spring4all.com/):如果您有什么问题,可以去这里发帖 -- [Spring Boot基础教程](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 -- [Spring Cloud基础教程](http://blog.didispace.com/Spring-Cloud%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网最早最全的免费Spring Cloud基础教程 - ## 我的公众号 diff --git a/README_zh.md b/README_zh.md index 0eb939df..37f45d5e 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1,6 +1,6 @@ # Spring Boot基础教程 -本项目内容为[《Spring Boot基础教程》](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 +本项目内容为[《Spring Boot基础教程》](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! @@ -13,11 +13,21 @@ ## 教程目录 -- [Spring Boot 1.x 版本教程](./1.x) - [Spring Boot 2.x 版本教程](./2.x) +- [Spring Boot 1.x 版本教程](./1.x) > **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
+## 推荐内容 + +- [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 +- [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 +- [阿里云:ECS云服务器2折起](https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=wxfqkr0o&utm_source=wxfqkr0o) +- [腾讯云:轻松应对建站成本问题](https://cloud.tencent.com/redirect.php?redirect=1027&cps_key=f6a8af1297bfac40b9d10ffa1270029a&from=console) +- [Spring问答社区](http://www.spring4all.com/):如果您有什么问题,可以去这里发帖 +- [Spring Boot基础教程](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 +- [Spring Cloud基础教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 + ## 特别赞助商
@@ -58,19 +68,6 @@ > 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` -- [阿里云:ECS云服务器2折起](https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=wxfqkr0o&utm_source=wxfqkr0o) -- [腾讯云:轻松应对建站成本问题](https://cloud.tencent.com/redirect.php?redirect=1027&cps_key=f6a8af1297bfac40b9d10ffa1270029a&from=console) - -## 推荐内容 - -- [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 -- [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 -- [GitHub](https://github.com/dyc87112/SpringBoot-Learning):Star支持一下呗 -- [Gitee](https://gitee.com/didispace/SpringBoot-Learning):Star支持一下呗 -- [Spring问答社区](http://www.spring4all.com/):如果您有什么问题,可以去这里发帖 -- [Spring Boot基础教程](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 -- [Spring Cloud基础教程](http://blog.didispace.com/Spring-Cloud%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网最早最全的免费Spring Cloud基础教程 - ## 我的公众号 From 2b89525926467d9337ba50d5dce69eb9eb996923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 22 Jul 2021 16:57:47 +0800 Subject: [PATCH 59/97] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 1 - 2.x/README_zh.md | 1 - 2 files changed, 2 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index a6b40a1e..ef299949 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -56,7 +56,6 @@ - [Spring Boot 2.x基础教程:事务管理入门](http://blog.didispace.com/spring-boot-learning-21-3-10/) - [Spring Boot 2.x基础教程:使用Flyway管理数据库版本](http://blog.didispace.com/spring-boot-learning-24-3-11/) - [Spring Boot 2.x基础教程:使用JTA实现分布式事务](http://blog.didispace.com/spring-boot-learning-24-3-12/) - - [Spring Boot 2.x基础教程:2.5版本后数据脚本初始化的变动](http://blog.didispace.com/spring-boot-learning-25-3-13/) **加速利器:各种缓存的使用** diff --git a/2.x/README_zh.md b/2.x/README_zh.md index d5e8d2b2..e2e5fd5e 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -57,7 +57,6 @@ - [Spring Boot 2.x基础教程:事务管理入门](http://blog.didispace.com/spring-boot-learning-21-3-10/) - [Spring Boot 2.x基础教程:使用Flyway管理数据库版本](http://blog.didispace.com/spring-boot-learning-24-3-11/) - [Spring Boot 2.x基础教程:使用JTA实现分布式事务](http://blog.didispace.com/spring-boot-learning-24-3-12/) - - [Spring Boot 2.x基础教程:2.5版本后数据脚本初始化的变动](http://blog.didispace.com/spring-boot-learning-25-3-13/) **加速利器:各种缓存的使用** From 134940da0998595d0a4e05f3d9c98cdf8d17b807 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Mon, 26 Jul 2021 22:20:43 +0800 Subject: [PATCH 60/97] =?UTF-8?q?Elastic=20Job=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter7-4/pom.xml | 51 +++++++++++++++++++ .../chapter74/Chapter74Application.java | 13 +++++ .../com/didispace/chapter74/MySimpleJob.java | 18 +++++++ .../src/main/resources/application.properties | 6 +++ 2.x/pom.xml | 7 ++- 5 files changed, 91 insertions(+), 4 deletions(-) create mode 100755 2.x/chapter7-4/pom.xml create mode 100755 2.x/chapter7-4/src/main/java/com/didispace/chapter74/Chapter74Application.java create mode 100644 2.x/chapter7-4/src/main/java/com/didispace/chapter74/MySimpleJob.java create mode 100644 2.x/chapter7-4/src/main/resources/application.properties diff --git a/2.x/chapter7-4/pom.xml b/2.x/chapter7-4/pom.xml new file mode 100755 index 00000000..5bab3842 --- /dev/null +++ b/2.x/chapter7-4/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-4 + 0.0.1-SNAPSHOT + Elastic Job的错误处理策略 + + + 1.8 + + + + + org.apache.shardingsphere.elasticjob + elasticjob-lite-spring-boot-starter + 3.0.0 + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter7-4/src/main/java/com/didispace/chapter74/Chapter74Application.java b/2.x/chapter7-4/src/main/java/com/didispace/chapter74/Chapter74Application.java new file mode 100755 index 00000000..e2674e95 --- /dev/null +++ b/2.x/chapter7-4/src/main/java/com/didispace/chapter74/Chapter74Application.java @@ -0,0 +1,13 @@ +package com.didispace.chapter74; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Chapter74Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter74Application.class, args); + } + +} diff --git a/2.x/chapter7-4/src/main/java/com/didispace/chapter74/MySimpleJob.java b/2.x/chapter7-4/src/main/java/com/didispace/chapter74/MySimpleJob.java new file mode 100644 index 00000000..d51c2ebb --- /dev/null +++ b/2.x/chapter7-4/src/main/java/com/didispace/chapter74/MySimpleJob.java @@ -0,0 +1,18 @@ +package com.didispace.chapter74; + +import lombok.extern.slf4j.Slf4j; +import org.apache.shardingsphere.elasticjob.api.ShardingContext; +import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class MySimpleJob implements SimpleJob { + + @Override + public void execute(ShardingContext context) { + log.info("MySimpleJob start : didispace.com {}", System.currentTimeMillis()); + throw new RuntimeException("模拟任务出现异常"); + } + +} \ No newline at end of file diff --git a/2.x/chapter7-4/src/main/resources/application.properties b/2.x/chapter7-4/src/main/resources/application.properties new file mode 100644 index 00000000..83abb028 --- /dev/null +++ b/2.x/chapter7-4/src/main/resources/application.properties @@ -0,0 +1,6 @@ +elasticjob.reg-center.server-lists=localhost:2181 +elasticjob.reg-center.namespace=didispace + +elasticjob.jobs.my-simple-job.elastic-job-class=com.didispace.chapter74.MySimpleJob +elasticjob.jobs.my-simple-job.cron=0/5 * * * * ? +elasticjob.jobs.my-simple-job.sharding-total-count=1 diff --git a/2.x/pom.xml b/2.x/pom.xml index 06cdc815..877a1b16 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -60,7 +60,6 @@ chapter5-3 chapter5-4 chapter5-5 - @@ -69,12 +68,12 @@ - + chapter7-1 chapter7-2 chapter7-3 - - + chapter7-4 + From 2f1a25fb4f2039b0ef626e9dfc8a32fee55e0a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Wed, 28 Jul 2021 15:05:14 +0800 Subject: [PATCH 61/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8Elastic=20Job=E7=9A=84n?= =?UTF-8?q?amespace=E9=98=B2=E6=AD=A2=E4=BB=BB=E5=8A=A1=E5=90=8D=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 2 +- 2.x/README_zh.md | 1 + .../java/com/didispace/chapter74/Chapter74Application.java | 0 .../src/main/java/com/didispace/chapter74/MySimpleJob.java | 1 - 2.x/chapter7-4/src/main/resources/application.properties | 4 +++- 2.x/pom.xml | 2 +- 6 files changed, 6 insertions(+), 4 deletions(-) mode change 100755 => 100644 2.x/chapter7-4/src/main/java/com/didispace/chapter74/Chapter74Application.java diff --git a/2.x/README.md b/2.x/README.md index ef299949..4b63af1b 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -84,7 +84,7 @@ - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置](https://blog.didispace.com/spring-boot-learning-2-7-3) - +- [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) ### 常见问题 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index e2e5fd5e..1ae48722 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -85,6 +85,7 @@ - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置](https://blog.didispace.com/spring-boot-learning-2-7-3) +- [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) ### 常见问题 diff --git a/2.x/chapter7-4/src/main/java/com/didispace/chapter74/Chapter74Application.java b/2.x/chapter7-4/src/main/java/com/didispace/chapter74/Chapter74Application.java old mode 100755 new mode 100644 diff --git a/2.x/chapter7-4/src/main/java/com/didispace/chapter74/MySimpleJob.java b/2.x/chapter7-4/src/main/java/com/didispace/chapter74/MySimpleJob.java index d51c2ebb..4e651c3e 100644 --- a/2.x/chapter7-4/src/main/java/com/didispace/chapter74/MySimpleJob.java +++ b/2.x/chapter7-4/src/main/java/com/didispace/chapter74/MySimpleJob.java @@ -12,7 +12,6 @@ public class MySimpleJob implements SimpleJob { @Override public void execute(ShardingContext context) { log.info("MySimpleJob start : didispace.com {}", System.currentTimeMillis()); - throw new RuntimeException("模拟任务出现异常"); } } \ No newline at end of file diff --git a/2.x/chapter7-4/src/main/resources/application.properties b/2.x/chapter7-4/src/main/resources/application.properties index 83abb028..16a59e0f 100644 --- a/2.x/chapter7-4/src/main/resources/application.properties +++ b/2.x/chapter7-4/src/main/resources/application.properties @@ -1,5 +1,7 @@ +spring.application.name=chapter74 + elasticjob.reg-center.server-lists=localhost:2181 -elasticjob.reg-center.namespace=didispace +elasticjob.reg-center.namespace=${spring.application.name} elasticjob.jobs.my-simple-job.elastic-job-class=com.didispace.chapter74.MySimpleJob elasticjob.jobs.my-simple-job.cron=0/5 * * * * ? diff --git a/2.x/pom.xml b/2.x/pom.xml index 877a1b16..8fa69fa4 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -72,7 +72,7 @@ chapter7-1 chapter7-2 chapter7-3 - chapter7-4 + chapter7-4 From 6275fa479f9ce485a5b5dc6f2cacd9528bdc8985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Wed, 28 Jul 2021 15:17:51 +0800 Subject: [PATCH 62/97] update --- 2.x/README.md | 2 +- 2.x/README_zh.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index 4b63af1b..175d3aa8 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -83,7 +83,7 @@ - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) -- [Spring Boot 2.x基础教程:使用Elastic Job的分片配置](https://blog.didispace.com/spring-boot-learning-2-7-3) +- [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) ### 常见问题 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 1ae48722..bb1e39dc 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -84,7 +84,7 @@ - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) -- [Spring Boot 2.x基础教程:使用Elastic Job的分片配置](https://blog.didispace.com/spring-boot-learning-2-7-3) +- [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) ### 常见问题 From a8948d92618268dd6c4ecd8209c1ac000cc5655a Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Tue, 3 Aug 2021 02:05:13 +0800 Subject: [PATCH 63/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=97=B6=E5=BA=8F?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=20InfluxDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 1 + 2.x/README_zh.md | 2 + 2.x/chapter6-3/pom.xml | 59 +++++++++++++++++++ .../chapter63/Chapter63Application.java | 15 +++++ .../java/com/didispace/chapter63/Monitor.java | 43 ++++++++++++++ .../src/main/resources/application.properties | 5 ++ .../didispace/chapter63/ApplicationTests.java | 22 +++++++ 2.x/pom.xml | 2 +- 8 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 2.x/chapter6-3/pom.xml create mode 100644 2.x/chapter6-3/src/main/java/com/didispace/chapter63/Chapter63Application.java create mode 100644 2.x/chapter6-3/src/main/java/com/didispace/chapter63/Monitor.java create mode 100644 2.x/chapter6-3/src/main/resources/application.properties create mode 100644 2.x/chapter6-3/src/test/java/com/didispace/chapter63/ApplicationTests.java diff --git a/2.x/README.md b/2.x/README.md index 175d3aa8..3553630f 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -70,6 +70,7 @@ - [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) - [Spring Boot 2.x基础教程:使用LDAP来管理用户与组织数据](http://blog.didispace.com/spring-boot-learning-24-6-2/) +- [Spring Boot 2.x基础教程:使用时序数据库InfluxDB](http://blog.didispace.com/spring-boot-learning-2-6-3/) ### Web开发 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index bb1e39dc..94a3ed95 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -71,6 +71,8 @@ - [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) - [Spring Boot 2.x基础教程:使用LDAP来管理用户与组织数据](http://blog.didispace.com/spring-boot-learning-24-6-2/) +- [Spring Boot 2.x基础教程:使用时序数据库InfluxDB](http://blog.didispace.com/spring-boot-learning-2-6-3/) + ### Web开发 diff --git a/2.x/chapter6-3/pom.xml b/2.x/chapter6-3/pom.xml new file mode 100644 index 00000000..686e3150 --- /dev/null +++ b/2.x/chapter6-3/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + com.didispace + chapter6-3 + 1.0.0 + jar + 使用时序数据库InfluxDB + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + + UTF-8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.influxdb + influxdb-java + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/2.x/chapter6-3/src/main/java/com/didispace/chapter63/Chapter63Application.java b/2.x/chapter6-3/src/main/java/com/didispace/chapter63/Chapter63Application.java new file mode 100644 index 00000000..54cc0e22 --- /dev/null +++ b/2.x/chapter6-3/src/main/java/com/didispace/chapter63/Chapter63Application.java @@ -0,0 +1,15 @@ +package com.didispace.chapter63; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +@EnableScheduling +@SpringBootApplication +public class Chapter63Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter63Application.class, args); + } + +} diff --git a/2.x/chapter6-3/src/main/java/com/didispace/chapter63/Monitor.java b/2.x/chapter6-3/src/main/java/com/didispace/chapter63/Monitor.java new file mode 100644 index 00000000..fd62dc20 --- /dev/null +++ b/2.x/chapter6-3/src/main/java/com/didispace/chapter63/Monitor.java @@ -0,0 +1,43 @@ +package com.didispace.chapter63; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.influxdb.InfluxDB; +import org.influxdb.dto.Point; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.util.Random; +import java.util.concurrent.TimeUnit; + +/** + * Created by 程序猿DD on 2021/8/2. + *

+ * Blog: http://blog.didispace.com/ + * Github: https://github.com/dyc87112/ + */ +@Service +@AllArgsConstructor +@Slf4j +public class Monitor { + + private InfluxDB influxDB; + + @Scheduled(fixedRate = 5000) + public void writeQPS() { + // 模拟要上报的统计数据 + int count = (int) (Math.random() * 100); + + Point point = Point.measurement("ApiQPS") // ApiQPS表 + .tag("url", "/hello") // url字段 + .addField("count", count) // 统计数据 + .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS) // 时间 + .build(); + + // 往test库写数据 + influxDB.write("test", "autogen", point); + + log.info("上报统计数据:" + count); + } + +} diff --git a/2.x/chapter6-3/src/main/resources/application.properties b/2.x/chapter6-3/src/main/resources/application.properties new file mode 100644 index 00000000..0df52b44 --- /dev/null +++ b/2.x/chapter6-3/src/main/resources/application.properties @@ -0,0 +1,5 @@ + +spring.influx.url=http://localhost:8086 +spring.influx.user=admin +spring.influx.password= + diff --git a/2.x/chapter6-3/src/test/java/com/didispace/chapter63/ApplicationTests.java b/2.x/chapter6-3/src/test/java/com/didispace/chapter63/ApplicationTests.java new file mode 100644 index 00000000..4720d3cc --- /dev/null +++ b/2.x/chapter6-3/src/test/java/com/didispace/chapter63/ApplicationTests.java @@ -0,0 +1,22 @@ +package com.didispace.chapter63; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@Slf4j +@SpringBootTest +public class ApplicationTests { + + @Test + public void findAll() { + + } + + @Test + public void save() { + + } + +} diff --git a/2.x/pom.xml b/2.x/pom.xml index 8fa69fa4..792f409b 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -65,7 +65,7 @@ chapter6-1 chapter6-2 - + chapter6-3 From e12aa4f076d5029fb18e7aeefb580b3961174619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Thu, 12 Aug 2021 17:18:44 +0800 Subject: [PATCH 64/97] update --- 2.x/chapter1-5/.gitignore | 29 ++++++++++++ 2.x/chapter1-5/pom.xml | 47 +++++++++++++++++++ .../chapter15/Chapter15Application.java | 13 +++++ .../didispace/chapter15/HelloController.java | 14 ++++++ .../src/main/resources/application.properties | 3 ++ 2.x/pom.xml | 1 + 6 files changed, 107 insertions(+) create mode 100644 2.x/chapter1-5/.gitignore create mode 100644 2.x/chapter1-5/pom.xml create mode 100644 2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java create mode 100644 2.x/chapter1-5/src/main/java/com/didispace/chapter15/HelloController.java create mode 100644 2.x/chapter1-5/src/main/resources/application.properties diff --git a/2.x/chapter1-5/.gitignore b/2.x/chapter1-5/.gitignore new file mode 100644 index 00000000..153c9335 --- /dev/null +++ b/2.x/chapter1-5/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/2.x/chapter1-5/pom.xml b/2.x/chapter1-5/pom.xml new file mode 100644 index 00000000..23e61eaa --- /dev/null +++ b/2.x/chapter1-5/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + com.didispace + chapter1-5 + 0.0.1-SNAPSHOT + 敏感配置信息的加密 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java new file mode 100644 index 00000000..1547f9b5 --- /dev/null +++ b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java @@ -0,0 +1,13 @@ +package com.didispace.chapter15; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Chapter15Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter15Application.class, args); + } + +} diff --git a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/HelloController.java b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/HelloController.java new file mode 100644 index 00000000..91236867 --- /dev/null +++ b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/HelloController.java @@ -0,0 +1,14 @@ +package com.didispace.chapter15; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + @RequestMapping("/hello") + public String index() { + return "Hello World"; + } + +} \ No newline at end of file diff --git a/2.x/chapter1-5/src/main/resources/application.properties b/2.x/chapter1-5/src/main/resources/application.properties new file mode 100644 index 00000000..20da7c87 --- /dev/null +++ b/2.x/chapter1-5/src/main/resources/application.properties @@ -0,0 +1,3 @@ + +com.didispace.from=didi + diff --git a/2.x/pom.xml b/2.x/pom.xml index 792f409b..6876b899 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -16,6 +16,7 @@ chapter1-2 chapter1-3 chapter1-4 + chapter1-5 chapter2-1 From e440510a23a3012daff1d6b04bb1bbcf493354a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E6=B0=B8=E8=B6=85?= Date: Fri, 13 Aug 2021 16:59:21 +0800 Subject: [PATCH 65/97] update --- 2.x/chapter1-5/pom.xml | 12 ++++++++++ .../chapter15/Chapter15Application.java | 24 ++++++++++++++++--- .../didispace/chapter15/HelloController.java | 14 ----------- .../didispace/chapter15/JasyptExample.java | 18 ++++++++++++++ .../src/main/resources/application.properties | 10 +++++++- .../didispace/chapter15/PropertiesTest.java | 21 ++++++++++++++++ 6 files changed, 81 insertions(+), 18 deletions(-) delete mode 100644 2.x/chapter1-5/src/main/java/com/didispace/chapter15/HelloController.java create mode 100644 2.x/chapter1-5/src/main/java/com/didispace/chapter15/JasyptExample.java create mode 100644 2.x/chapter1-5/src/test/java/com/didispace/chapter15/PropertiesTest.java diff --git a/2.x/chapter1-5/pom.xml b/2.x/chapter1-5/pom.xml index 23e61eaa..35d5fb02 100644 --- a/2.x/chapter1-5/pom.xml +++ b/2.x/chapter1-5/pom.xml @@ -23,6 +23,12 @@ spring-boot-starter-web + + com.github.ulisesbocchio + jasypt-spring-boot-starter + 3.0.3 + + org.projectlombok lombok @@ -41,6 +47,12 @@ org.springframework.boot spring-boot-maven-plugin + + + com.github.ulisesbocchio + jasypt-maven-plugin + 3.0.3 + diff --git a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java index 1547f9b5..df4e07eb 100644 --- a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java +++ b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java @@ -1,13 +1,31 @@ package com.didispace.chapter15; +import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; @SpringBootApplication +@EnableEncryptableProperties public class Chapter15Application { - public static void main(String[] args) { - SpringApplication.run(Chapter15Application.class, args); - } + public static void main(String[] args) { + SpringApplication.run(Chapter15Application.class, args); + } + + @RestController + static class HelloController { + + @Autowired + private JasyptExample jasyptExample; + + @GetMapping("/hello") + public String hello() { + return "Hello World, " + jasyptExample.getFrom2(); + } + + } } diff --git a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/HelloController.java b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/HelloController.java deleted file mode 100644 index 91236867..00000000 --- a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/HelloController.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.didispace.chapter15; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class HelloController { - - @RequestMapping("/hello") - public String index() { - return "Hello World"; - } - -} \ No newline at end of file diff --git a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/JasyptExample.java b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/JasyptExample.java new file mode 100644 index 00000000..c87ca75f --- /dev/null +++ b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/JasyptExample.java @@ -0,0 +1,18 @@ +package com.didispace.chapter15; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Slf4j +@Data +@Component +public class JasyptExample { + + @Value("${com.didispace.from1:}") + private String from1; + @Value("${com.didispace.from2:}") + private String from2; + +} \ No newline at end of file diff --git a/2.x/chapter1-5/src/main/resources/application.properties b/2.x/chapter1-5/src/main/resources/application.properties index 20da7c87..1cbf505e 100644 --- a/2.x/chapter1-5/src/main/resources/application.properties +++ b/2.x/chapter1-5/src/main/resources/application.properties @@ -1,3 +1,11 @@ -com.didispace.from=didi +com.didispace.from1=didi +com.didispace.from2=ENC(1I1oWHryzOJt+Gm81xnGnOUbBUpEBEFYES/NprA/q6ec3jBkU1xlBZWsHCaj71ds) +jasypt.encryptor.password=didispace + +#[INFO] Encryptor config not found for property jasypt.encryptor.salt-generator-classname, using default value: org.jasypt.salt.RandomSaltGenerator +#[INFO] Encryptor config not found for property jasypt.encryptor.iv-generator-classname, using default value: org.jasypt.iv.RandomIvGenerator + +# mvn jasypt:encrypt -Djasypt.encryptor.password=didispace +# mvn jasypt:decrypt -Djasypt.encryptor.password=didispace \ No newline at end of file diff --git a/2.x/chapter1-5/src/test/java/com/didispace/chapter15/PropertiesTest.java b/2.x/chapter1-5/src/test/java/com/didispace/chapter15/PropertiesTest.java new file mode 100644 index 00000000..1185ff4a --- /dev/null +++ b/2.x/chapter1-5/src/test/java/com/didispace/chapter15/PropertiesTest.java @@ -0,0 +1,21 @@ +package com.didispace.chapter15; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@Slf4j +@SpringBootTest +public class PropertiesTest { + + @Autowired + private JasyptExample jasyptExample; + + @Test + public void test() { + log.info("from1 : {}", jasyptExample.getFrom1()); + log.info("from2 : {}", jasyptExample.getFrom2()); + } + +} From b28477aad3a2b4d9c11122b2b3ab89855b44fc7d Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Fri, 13 Aug 2021 23:04:01 +0800 Subject: [PATCH 66/97] =?UTF-8?q?=E5=8A=A0=E5=AF=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=AD=E7=9A=84=E6=95=8F=E6=84=9F=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 3 ++- 2.x/README_zh.md | 3 ++- 2.x/chapter1-5/pom.xml | 2 +- .../chapter15/Chapter15Application.java | 18 ------------------ .../com/didispace/chapter15/JasyptExample.java | 18 ------------------ .../src/main/resources/application.properties | 11 +++++------ .../didispace/chapter15/PropertiesTest.java | 8 ++++---- 2.x/pom.xml | 2 +- 8 files changed, 15 insertions(+), 50 deletions(-) delete mode 100644 2.x/chapter1-5/src/main/java/com/didispace/chapter15/JasyptExample.java diff --git a/2.x/README.md b/2.x/README.md index 3553630f..623f5393 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -25,9 +25,10 @@ ### 配置文件 - [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/) +- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化](http://blog.didispace.com/spring-boot-learning-24-1-4/) - [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/) -- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) +- [Spring Boot 2.x基础教程:加密配置中的敏感信息](http://blog.didispace.com/spring-boot-learning-2-1-5/) ### API开发 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 94a3ed95..2958f22c 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -26,9 +26,10 @@ ### 配置文件 - [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/) +- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化](http://blog.didispace.com/spring-boot-learning-24-1-4/) - [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/) -- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) +- [Spring Boot 2.x基础教程:加密配置中的敏感信息](http://blog.didispace.com/spring-boot-learning-2-1-5/) ### API开发 diff --git a/2.x/chapter1-5/pom.xml b/2.x/chapter1-5/pom.xml index 35d5fb02..a9c25152 100644 --- a/2.x/chapter1-5/pom.xml +++ b/2.x/chapter1-5/pom.xml @@ -11,7 +11,7 @@ com.didispace chapter1-5 0.0.1-SNAPSHOT - 敏感配置信息的加密 + 加密配置中的敏感信息 1.8 diff --git a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java index df4e07eb..6b0c79d6 100644 --- a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java +++ b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java @@ -1,31 +1,13 @@ package com.didispace.chapter15; -import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; @SpringBootApplication -@EnableEncryptableProperties public class Chapter15Application { public static void main(String[] args) { SpringApplication.run(Chapter15Application.class, args); } - @RestController - static class HelloController { - - @Autowired - private JasyptExample jasyptExample; - - @GetMapping("/hello") - public String hello() { - return "Hello World, " + jasyptExample.getFrom2(); - } - - } - } diff --git a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/JasyptExample.java b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/JasyptExample.java deleted file mode 100644 index c87ca75f..00000000 --- a/2.x/chapter1-5/src/main/java/com/didispace/chapter15/JasyptExample.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.didispace.chapter15; - -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Slf4j -@Data -@Component -public class JasyptExample { - - @Value("${com.didispace.from1:}") - private String from1; - @Value("${com.didispace.from2:}") - private String from2; - -} \ No newline at end of file diff --git a/2.x/chapter1-5/src/main/resources/application.properties b/2.x/chapter1-5/src/main/resources/application.properties index 1cbf505e..b5780fe0 100644 --- a/2.x/chapter1-5/src/main/resources/application.properties +++ b/2.x/chapter1-5/src/main/resources/application.properties @@ -1,11 +1,10 @@ -com.didispace.from1=didi -com.didispace.from2=ENC(1I1oWHryzOJt+Gm81xnGnOUbBUpEBEFYES/NprA/q6ec3jBkU1xlBZWsHCaj71ds) +datasource.password=ENC(/AL9nJENCYCh9Pfzdf2xLPsqOZ6HwNgQ3AnMybFAMeOM5GphZlOK6PxzozwtCm+Q) jasypt.encryptor.password=didispace -#[INFO] Encryptor config not found for property jasypt.encryptor.salt-generator-classname, using default value: org.jasypt.salt.RandomSaltGenerator -#[INFO] Encryptor config not found for property jasypt.encryptor.iv-generator-classname, using default value: org.jasypt.iv.RandomIvGenerator - # mvn jasypt:encrypt -Djasypt.encryptor.password=didispace -# mvn jasypt:decrypt -Djasypt.encryptor.password=didispace \ No newline at end of file +# mvn jasypt:decrypt -Djasypt.encryptor.password=didispace + +#jasypt.encryptor.property.prefix=ENC( +#jasypt.encryptor.property.suffix=) \ No newline at end of file diff --git a/2.x/chapter1-5/src/test/java/com/didispace/chapter15/PropertiesTest.java b/2.x/chapter1-5/src/test/java/com/didispace/chapter15/PropertiesTest.java index 1185ff4a..db8ff86d 100644 --- a/2.x/chapter1-5/src/test/java/com/didispace/chapter15/PropertiesTest.java +++ b/2.x/chapter1-5/src/test/java/com/didispace/chapter15/PropertiesTest.java @@ -3,19 +3,19 @@ import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @Slf4j @SpringBootTest public class PropertiesTest { - @Autowired - private JasyptExample jasyptExample; + @Value("${datasource.password:}") + private String password; @Test public void test() { - log.info("from1 : {}", jasyptExample.getFrom1()); - log.info("from2 : {}", jasyptExample.getFrom2()); + log.info("datasource.password : {}", password); } } diff --git a/2.x/pom.xml b/2.x/pom.xml index 6876b899..755a140f 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -16,7 +16,7 @@ chapter1-2 chapter1-3 chapter1-4 - chapter1-5 + chapter1-5 chapter2-1 From f52bb67ab896642ad0d7f4d7a783571d053612f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Mon, 16 Aug 2021 12:51:41 +0800 Subject: [PATCH 67/97] =?UTF-8?q?=E8=AF=A5=E7=9B=AE=E5=BD=95=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=B7=B2=E8=BF=81=E7=A7=BB=E8=87=B32.x=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.1.x/README.md | 124 ++----------------------------------------- 2.1.x/README_zh.md | 129 ++------------------------------------------- 2 files changed, 6 insertions(+), 247 deletions(-) diff --git a/2.1.x/README.md b/2.1.x/README.md index de29ff83..5f07e37b 100644 --- a/2.1.x/README.md +++ b/2.1.x/README.md @@ -1,122 +1,4 @@ -# Spring Boot基础教程(2.x版本) - -本项目内容为[《Spring Boot基础教程》](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 - -**专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! - -**如何支持**: - -1. 关注我的公众号”**程序猿DD**“ -2. 点个`Star`并`Follow`我 -3. 把该仓库分享给更多的朋友 - -## 特别赞助商 - -

- - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` - -## 教程目录(2.x版本) - -连载中...Star关注支持一下,随时获得更新信息! - -### 基础知识 - -- [Spring Boot 2.x基础教程:版本关系](http://blog.didispace.com/spring-cloud-alibaba-version/) -- [Spring Boot 2.x基础教程:快速入门](http://blog.didispace.com/spring-boot-learning-21-1-1/) -- [Spring Boot 2.x基础教程:工程结构推荐](http://blog.didispace.com/spring-boot-learning-21-1-2/) -- [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/) - -### Web开发 - -- [Spring Boot 2.x基础教程:构建RESTful API与单元测试](http://blog.didispace.com/spring-boot-learning-21-2-1/) -- [Spring Boot 2.x基础教程:使用Swagger2构建强大的API文档](http://blog.didispace.com/spring-boot-learning-21-2-2/) -- [Spring Boot 2.x基础教程:JSR-303实现请求参数校验](http://blog.didispace.com/spring-boot-learning-21-2-3/) -- [Spring Boot 2.x基础教程:Swagger接口分类与各元素排序问题详解](http://blog.didispace.com/spring-boot-learning-21-2-4/) -- [Spring Boot 2.x基础教程:Swagger静态文档的生成](http://blog.didispace.com/spring-boot-learning-21-2-5/) -- [Spring Boot 2.x基础教程:找回启动日志中的请求路径列表](http://blog.didispace.com/spring-boot-learning-21-2-6/) - -### 数据访问 - -**关系型数据库** - -- [Spring Boot 2.x基础教程:使用JdbcTemplate访问MySQL数据库](http://blog.didispace.com/spring-boot-learning-21-3-1/) -- [Spring Boot 2.x基础教程:默认数据源Hikari的配置详解](http://blog.didispace.com/spring-boot-learning-21-3-2/) -- [Spring Boot 2.x基础教程:使用国产数据库连接池Druid](http://blog.didispace.com/spring-boot-learning-21-3-3/) -- [Spring Boot 2.x基础教程:使用Spring Data JPA访问MySQL](http://blog.didispace.com/spring-boot-learning-21-3-4/) -- [Spring Boot 2.x基础教程:使用MyBatis访问MySQL](http://blog.didispace.com/spring-boot-learning-21-3-5/) -- [Spring Boot 2.x基础教程:使用MyBatis的XML配置方式](http://blog.didispace.com/spring-boot-learning-21-3-6/) -- [Spring Boot 2.x基础教程:JdbcTemplate的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-7/) -- [Spring Boot 2.x基础教程:Spring Data JPA的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-8/) -- [Spring Boot 2.x基础教程:MyBatis的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-9/) -- [Spring Boot 2.x基础教程:事务管理入门](http://blog.didispace.com/spring-boot-learning-21-3-10/) - -**加速利器:各种缓存的使用** - -- [Spring Boot 2.x基础教程:进程内缓存的使用与Cache注解详解](http://blog.didispace.com/spring-boot-learning-21-5-1/) -- [Spring Boot 2.x基础教程:EhCache缓存的使用](http://blog.didispace.com/spring-boot-learning-21-5-2/) -- [Spring Boot 2.x基础教程:使用EhCache缓存集群](http://blog.didispace.com/spring-boot-learning-21-5-3/) -- [Spring Boot 2.x基础教程:使用集中式缓存Redis](http://blog.didispace.com/spring-boot-learning-21-5-4/) - -### Web开发 - -- [Spring Boot 2.x基础教程:使用 Thymeleaf开发Web页面](http://blog.didispace.com/spring-boot-learning-21-4-1/) -- [Spring Boot 2.x基础教程:使用 ECharts 绘制各种华丽的数据图表](http://blog.didispace.com/spring-boot-learning-21-4-2/) - -### 1.x到2.x - -- [Spring Boot 2.0 正式发布,升还是不升呢?](http://blog.didispace.com/spring-boot-2-release/) -- [Spring Boot 2.0 新特性和发展方向](http://blog.didispace.com/Spring-Boot-2-0-%E6%96%B0%E7%89%B9%E6%80%A7%E5%92%8C%E5%8F%91%E5%B1%95%E6%96%B9%E5%90%91/) -- [Spring Boot 2.0 与 Java 9](http://blog.didispace.com/Spring-Boot-2.0%E4%B8%8EJava-9/) -- [Spring Boot 2.0 新特性(一):配置绑定 2.0 全解析](http://blog.didispace.com/Spring-Boot-2-0-feature-1-relaxed-binding-2/) -- [Spring Boot 2.0 新特性(二):新增事件ApplicationStartedEvent](http://blog.didispace.com/Spring-Boot-2-0-feature-2-ApplicationStartedEvent/) - -## 推荐内容 - -- [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 -- [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 -- [GitHub](https://github.com/dyc87112/SpringBoot-Learning):Star支持一下呗 -- [Gitee](https://gitee.com/didispace/SpringBoot-Learning):Star支持一下呗 -- [Spring问答社区](http://www.spring4all.com/):如果您有什么问题,可以去这里发帖 -- [Spring Boot基础教程](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 -- [Spring Cloud基础教程](http://blog.didispace.com/Spring-Cloud%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网最早最全的免费Spring Cloud基础教程 - -## 我的公众号 - - - +该目录下内容已迁移道`2.x`目录,本文件夹不继续维护。 +- 教程汇总(1.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-1x/) +- 教程汇总(2.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-2x/) diff --git a/2.1.x/README_zh.md b/2.1.x/README_zh.md index 301ec021..5f07e37b 100644 --- a/2.1.x/README_zh.md +++ b/2.1.x/README_zh.md @@ -1,127 +1,4 @@ -# Spring Boot基础教程(2.x版本) +该目录下内容已迁移道`2.x`目录,本文件夹不继续维护。 -本项目内容为[《Spring Boot基础教程》](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 - -**专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! - -**如何支持**: -1. 关注我的公众号”**程序猿DD**“ -2. 点个`Star`并`Follow`我 -3. 把该仓库分享给更多的朋友 - -如果您对文字类教程不感冒或者想要通过综合案例学习Spring,那么给您推荐这个我觉得目前内容与价格最良心的视频课程:["玩转Spring全家桶"](https://time.geekbang.org/course/intro/100023501?code=d1se%2F7ugeBEyuU%2FIYp1ynfSZa6ulbGhhDK%2Fkpn3-lFc%3D) - -> **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
- -## 特别赞助商 - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` - -## 教程目录(2.x版本) - -连载中...Star关注支持一下,随时获得更新信息! - -### 基础知识 - -- [Spring Boot 2.x基础教程:版本关系](http://blog.didispace.com/spring-cloud-alibaba-version/) -- [Spring Boot 2.x基础教程:快速入门](http://blog.didispace.com/spring-boot-learning-21-1-1/) -- [Spring Boot 2.x基础教程:工程结构推荐](http://blog.didispace.com/spring-boot-learning-21-1-2/) -- [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/) - -### Web开发 - -- [Spring Boot 2.x基础教程:构建RESTful API与单元测试](http://blog.didispace.com/spring-boot-learning-21-2-1/) -- [Spring Boot 2.x基础教程:使用Swagger2构建强大的API文档](http://blog.didispace.com/spring-boot-learning-21-2-2/) -- [Spring Boot 2.x基础教程:JSR-303实现请求参数校验](http://blog.didispace.com/spring-boot-learning-21-2-3/) -- [Spring Boot 2.x基础教程:Swagger接口分类与各元素排序问题详解](http://blog.didispace.com/spring-boot-learning-21-2-4/) -- [Spring Boot 2.x基础教程:Swagger静态文档的生成](http://blog.didispace.com/spring-boot-learning-21-2-5/) -- [Spring Boot 2.x基础教程:找回启动日志中的请求路径列表](http://blog.didispace.com/spring-boot-learning-21-2-6/) - -### 数据访问 - -**关系型数据库** - -- [Spring Boot 2.x基础教程:使用JdbcTemplate访问MySQL数据库](http://blog.didispace.com/spring-boot-learning-21-3-1/) -- [Spring Boot 2.x基础教程:默认数据源Hikari的配置详解](http://blog.didispace.com/spring-boot-learning-21-3-2/) -- [Spring Boot 2.x基础教程:使用国产数据库连接池Druid](http://blog.didispace.com/spring-boot-learning-21-3-3/) -- [Spring Boot 2.x基础教程:使用Spring Data JPA访问MySQL](http://blog.didispace.com/spring-boot-learning-21-3-4/) -- [Spring Boot 2.x基础教程:使用MyBatis访问MySQL](http://blog.didispace.com/spring-boot-learning-21-3-5/) -- [Spring Boot 2.x基础教程:使用MyBatis的XML配置方式](http://blog.didispace.com/spring-boot-learning-21-3-6/) -- [Spring Boot 2.x基础教程:JdbcTemplate的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-7/) -- [Spring Boot 2.x基础教程:Spring Data JPA的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-8/) -- [Spring Boot 2.x基础教程:MyBatis的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-9/) -- [Spring Boot 2.x基础教程:事务管理入门](http://blog.didispace.com/spring-boot-learning-21-3-10/) - -**加速利器:各种缓存的使用** - -- [Spring Boot 2.x基础教程:进程内缓存的使用与Cache注解详解](http://blog.didispace.com/spring-boot-learning-21-5-1/) -- [Spring Boot 2.x基础教程:EhCache缓存的使用](http://blog.didispace.com/spring-boot-learning-21-5-2/) -- [Spring Boot 2.x基础教程:使用EhCache缓存集群](http://blog.didispace.com/spring-boot-learning-21-5-3/) -- [Spring Boot 2.x基础教程:使用集中式缓存Redis](http://blog.didispace.com/spring-boot-learning-21-5-4/) - -### Web开发 - -- [Spring Boot 2.x基础教程:使用 Thymeleaf开发Web页面](http://blog.didispace.com/spring-boot-learning-21-4-1/) -- [Spring Boot 2.x基础教程:使用 ECharts 绘制各种华丽的数据图表](http://blog.didispace.com/spring-boot-learning-21-4-2/) - -### 1.x到2.x - -- [Spring Boot 2.0 正式发布,升还是不升呢?](http://blog.didispace.com/spring-boot-2-release/) -- [Spring Boot 2.0 新特性和发展方向](http://blog.didispace.com/Spring-Boot-2-0-%E6%96%B0%E7%89%B9%E6%80%A7%E5%92%8C%E5%8F%91%E5%B1%95%E6%96%B9%E5%90%91/) -- [Spring Boot 2.0 与 Java 9](http://blog.didispace.com/Spring-Boot-2.0%E4%B8%8EJava-9/) -- [Spring Boot 2.0 新特性(一):配置绑定 2.0 全解析](http://blog.didispace.com/Spring-Boot-2-0-feature-1-relaxed-binding-2/) -- [Spring Boot 2.0 新特性(二):新增事件ApplicationStartedEvent](http://blog.didispace.com/Spring-Boot-2-0-feature-2-ApplicationStartedEvent/) - -## 推荐内容 - -- [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 -- [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 -- [GitHub](https://github.com/dyc87112/SpringBoot-Learning):Star支持一下呗 -- [Gitee](https://gitee.com/didispace/SpringBoot-Learning):Star支持一下呗 -- [Spring问答社区](http://www.spring4all.com/):如果您有什么问题,可以去这里发帖 -- [Spring Boot基础教程](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 -- [Spring Cloud基础教程](http://blog.didispace.com/Spring-Cloud%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网最早最全的免费Spring Cloud基础教程 - -## 我的公众号 - - - -## 我出版的书 - -![输入图片说明](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png "在这里输入图片标题") +- 教程汇总(1.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-1x/) +- 教程汇总(2.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-2x/) From 1246efed24ac91188d1cf6795aa079132f4ea459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Mon, 16 Aug 2021 12:59:37 +0800 Subject: [PATCH 68/97] =?UTF-8?q?1.x=E6=95=99=E7=A8=8B=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.x/README.md | 65 ++++++------------------------------------- 1.x/README_zh.md | 72 ++++++------------------------------------------ 2 files changed, 17 insertions(+), 120 deletions(-) diff --git a/1.x/README.md b/1.x/README.md index e5f191c2..a1fcc0fe 100644 --- a/1.x/README.md +++ b/1.x/README.md @@ -1,60 +1,11 @@ -# Spring Boot基础教程(1.x版本) - -本项目内容为[《Spring Boot基础教程》](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 - -**专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! - -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) - -**如何支持**: -1. 关注我的公众号”**程序猿DD**“ -2. 点个`Star`并`Follow`我 -3. 把该仓库分享给更多的朋友 - -如果您对文字类教程不感冒或者想要通过综合案例学习Spring,那么给您推荐这个我觉得目前内容与价格最良心的视频课程:["玩转Spring全家桶"](https://time.geekbang.org/course/intro/100023501?code=d1se%2F7ugeBEyuU%2FIYp1ynfSZa6ulbGhhDK%2Fkpn3-lFc%3D) - - -> **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
- -## 特别赞助商 - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` +该目录下为Spring Boot 1.x版本的教程,因为版本落后,**后续不再继续更新**。 + +推荐下面的2.x版本,还在持续更新哦! + +- 教程汇总(1.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-1x/) +- 教程汇总(2.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-2x/) + +Spring Boot 2.x版本的教程可在`2.x`目录下查看。 ## 教程目录(1.x版本) diff --git a/1.x/README_zh.md b/1.x/README_zh.md index b23d4a16..a1fcc0fe 100644 --- a/1.x/README_zh.md +++ b/1.x/README_zh.md @@ -1,63 +1,11 @@ -# Spring Boot基础教程(1.x版本) - -本项目内容为[《Spring Boot基础教程》](http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 - -**专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! - -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) - -**如何支持**: -1. 关注我的公众号”**程序猿DD**“ -2. 点个`Star`并`Follow`我 -3. 把该仓库分享给更多的朋友 - -如果您对文字类教程不感冒或者想要通过综合案例学习Spring,那么给您推荐这个我觉得目前内容与价格最良心的视频课程:["玩转Spring全家桶"](https://time.geekbang.org/course/intro/100023501?code=d1se%2F7ugeBEyuU%2FIYp1ynfSZa6ulbGhhDK%2Fkpn3-lFc%3D) - - -> **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
- -## 特别赞助商 - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` - -- [阿里云:ECS云服务器2折起](https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=wxfqkr0o&utm_source=wxfqkr0o) -- [腾讯云:轻松应对建站成本问题](https://cloud.tencent.com/redirect.php?redirect=1027&cps_key=f6a8af1297bfac40b9d10ffa1270029a&from=console) +该目录下为Spring Boot 1.x版本的教程,因为版本落后,**后续不再继续更新**。 + +推荐下面的2.x版本,还在持续更新哦! + +- 教程汇总(1.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-1x/) +- 教程汇总(2.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-2x/) + +Spring Boot 2.x版本的教程可在`2.x`目录下查看。 ## 教程目录(1.x版本) @@ -170,8 +118,6 @@ ## 我的公众号 - + -## 我出版的书 -![输入图片说明](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png "在这里输入图片标题") From cc65093ef06a961f7e79642f732cc41cd69dea23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Mon, 16 Aug 2021 13:01:22 +0800 Subject: [PATCH 69/97] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/pom.xml | 3 ++- README.md | 12 +++++++----- README_zh.md | 12 +++++++----- pom.xml | 5 +++++ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/2.x/pom.xml b/2.x/pom.xml index 755a140f..1252ae43 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -4,8 +4,9 @@ 4.0.0 com.didispace - SpringBoot-Learning + 2.x 2.0-SNAPSHOT + pom 全网Star最多的Spring Boot基础教程 diff --git a/README.md b/README.md index 37f45d5e..e962dabe 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,17 @@ **加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) **如何支持**: + 1. 关注我的公众号”**程序猿DD**“ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 ## 教程目录 +该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总。 + +可以通过下面的链接,进入具体版本的教程目录: + - [Spring Boot 2.x 版本教程](./2.x) - [Spring Boot 1.x 版本教程](./1.x) @@ -21,12 +26,9 @@ ## 推荐内容 - [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 +- [我的Spring Boot教程](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 +- [我的Spring Cloud教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 - [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 -- [阿里云:ECS云服务器2折起](https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=wxfqkr0o&utm_source=wxfqkr0o) -- [腾讯云:轻松应对建站成本问题](https://cloud.tencent.com/redirect.php?redirect=1027&cps_key=f6a8af1297bfac40b9d10ffa1270029a&from=console) -- [Spring问答社区](http://www.spring4all.com/):如果您有什么问题,可以去这里发帖 -- [Spring Boot基础教程](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 -- [Spring Cloud基础教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 ## 特别赞助商 diff --git a/README_zh.md b/README_zh.md index 37f45d5e..e962dabe 100644 --- a/README_zh.md +++ b/README_zh.md @@ -7,12 +7,17 @@ **加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) **如何支持**: + 1. 关注我的公众号”**程序猿DD**“ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 ## 教程目录 +该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总。 + +可以通过下面的链接,进入具体版本的教程目录: + - [Spring Boot 2.x 版本教程](./2.x) - [Spring Boot 1.x 版本教程](./1.x) @@ -21,12 +26,9 @@ ## 推荐内容 - [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 +- [我的Spring Boot教程](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 +- [我的Spring Cloud教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 - [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 -- [阿里云:ECS云服务器2折起](https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=wxfqkr0o&utm_source=wxfqkr0o) -- [腾讯云:轻松应对建站成本问题](https://cloud.tencent.com/redirect.php?redirect=1027&cps_key=f6a8af1297bfac40b9d10ffa1270029a&from=console) -- [Spring问答社区](http://www.spring4all.com/):如果您有什么问题,可以去这里发帖 -- [Spring Boot基础教程](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 -- [Spring Cloud基础教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 ## 特别赞助商 diff --git a/pom.xml b/pom.xml index bbb1474b..469fe5a3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,6 +6,11 @@ com.didispace SpringBoot-Learning 1.0-SNAPSHOT + pom + + + 2.x + From 12284303a3a188f2cdfd3165aa11385001d59f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Thu, 26 Aug 2021 17:51:56 +0800 Subject: [PATCH 70/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8@Async=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 3 ++ 2.x/README_zh.md | 2 + 2.x/chapter7-5/pom.xml | 50 +++++++++++++++++++ .../com/didispace/chapter75/AsyncTasks.java | 40 +++++++++++++++ .../chapter75/Chapter75Application.java | 13 +++++ .../src/main/resources/application.properties | 0 .../chapter75/Chapter75ApplicationTests.java | 22 ++++++++ 2.x/pom.xml | 3 +- 8 files changed, 132 insertions(+), 1 deletion(-) create mode 100755 2.x/chapter7-5/pom.xml create mode 100644 2.x/chapter7-5/src/main/java/com/didispace/chapter75/AsyncTasks.java create mode 100644 2.x/chapter7-5/src/main/java/com/didispace/chapter75/Chapter75Application.java create mode 100644 2.x/chapter7-5/src/main/resources/application.properties create mode 100644 2.x/chapter7-5/src/test/java/com/didispace/chapter75/Chapter75ApplicationTests.java diff --git a/2.x/README.md b/2.x/README.md index 623f5393..7ce6922a 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -88,6 +88,9 @@ - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) +- [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) + + ### 常见问题 - [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 2958f22c..ed03e29c 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -90,6 +90,8 @@ - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) +- [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) + ### 常见问题 - [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) diff --git a/2.x/chapter7-5/pom.xml b/2.x/chapter7-5/pom.xml new file mode 100755 index 00000000..4ff53d56 --- /dev/null +++ b/2.x/chapter7-5/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-5 + 0.0.1-SNAPSHOT + 使用@Async实现异步任务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter7-5/src/main/java/com/didispace/chapter75/AsyncTasks.java b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/AsyncTasks.java new file mode 100644 index 00000000..2db5b26d --- /dev/null +++ b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/AsyncTasks.java @@ -0,0 +1,40 @@ +package com.didispace.chapter75; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Slf4j +@Component +@AllArgsConstructor +public class AsyncTasks { + + public static Random random = new Random(); + + public void doTaskOne() throws Exception { + log.info("开始做任务一"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务一,耗时:" + (end - start) + "毫秒"); + } + + public void doTaskTwo() throws Exception { + log.info("开始做任务二"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务二,耗时:" + (end - start) + "毫秒"); + } + + public void doTaskThree() throws Exception { + log.info("开始做任务三"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务三,耗时:" + (end - start) + "毫秒"); + } + +} \ No newline at end of file diff --git a/2.x/chapter7-5/src/main/java/com/didispace/chapter75/Chapter75Application.java b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/Chapter75Application.java new file mode 100644 index 00000000..b7d233ee --- /dev/null +++ b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/Chapter75Application.java @@ -0,0 +1,13 @@ +package com.didispace.chapter75; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Chapter75Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter75Application.class, args); + } + +} diff --git a/2.x/chapter7-5/src/main/resources/application.properties b/2.x/chapter7-5/src/main/resources/application.properties new file mode 100644 index 00000000..e69de29b diff --git a/2.x/chapter7-5/src/test/java/com/didispace/chapter75/Chapter75ApplicationTests.java b/2.x/chapter7-5/src/test/java/com/didispace/chapter75/Chapter75ApplicationTests.java new file mode 100644 index 00000000..61aa967e --- /dev/null +++ b/2.x/chapter7-5/src/test/java/com/didispace/chapter75/Chapter75ApplicationTests.java @@ -0,0 +1,22 @@ +package com.didispace.chapter75; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@Slf4j +@SpringBootTest +public class Chapter75ApplicationTests { + + @Autowired + private AsyncTasks asyncTasks; + + @Test + public void test() throws Exception { + asyncTasks.doTaskOne(); + asyncTasks.doTaskTwo(); + asyncTasks.doTaskThree(); + } + +} diff --git a/2.x/pom.xml b/2.x/pom.xml index 1252ae43..3c743265 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -75,7 +75,8 @@ chapter7-2 chapter7-3 chapter7-4 - + chapter7-5 + From 679ebf65924a2b8cc2594ac440f2fc5e23261432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Sat, 11 Sep 2021 23:36:09 +0800 Subject: [PATCH 71/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8@Async=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/didispace/chapter75/AsyncTasks.java | 16 +++++++++++----- .../chapter75/Chapter75Application.java | 2 ++ .../chapter75/Chapter75ApplicationTests.java | 17 ++++++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/2.x/chapter7-5/src/main/java/com/didispace/chapter75/AsyncTasks.java b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/AsyncTasks.java index 2db5b26d..e2f1be13 100644 --- a/2.x/chapter7-5/src/main/java/com/didispace/chapter75/AsyncTasks.java +++ b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/AsyncTasks.java @@ -1,40 +1,46 @@ package com.didispace.chapter75; -import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import java.util.Random; +import java.util.concurrent.CompletableFuture; @Slf4j @Component -@AllArgsConstructor public class AsyncTasks { public static Random random = new Random(); - public void doTaskOne() throws Exception { + @Async + public CompletableFuture doTaskOne() throws Exception { log.info("开始做任务一"); long start = System.currentTimeMillis(); Thread.sleep(random.nextInt(10000)); long end = System.currentTimeMillis(); log.info("完成任务一,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务一完成"); } - public void doTaskTwo() throws Exception { + @Async + public CompletableFuture doTaskTwo() throws Exception { log.info("开始做任务二"); long start = System.currentTimeMillis(); Thread.sleep(random.nextInt(10000)); long end = System.currentTimeMillis(); log.info("完成任务二,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务二完成"); } - public void doTaskThree() throws Exception { + @Async + public CompletableFuture doTaskThree() throws Exception { log.info("开始做任务三"); long start = System.currentTimeMillis(); Thread.sleep(random.nextInt(10000)); long end = System.currentTimeMillis(); log.info("完成任务三,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务三完成"); } } \ No newline at end of file diff --git a/2.x/chapter7-5/src/main/java/com/didispace/chapter75/Chapter75Application.java b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/Chapter75Application.java index b7d233ee..e8aef549 100644 --- a/2.x/chapter7-5/src/main/java/com/didispace/chapter75/Chapter75Application.java +++ b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/Chapter75Application.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; +@EnableAsync @SpringBootApplication public class Chapter75Application { diff --git a/2.x/chapter7-5/src/test/java/com/didispace/chapter75/Chapter75ApplicationTests.java b/2.x/chapter7-5/src/test/java/com/didispace/chapter75/Chapter75ApplicationTests.java index 61aa967e..af32b972 100644 --- a/2.x/chapter7-5/src/test/java/com/didispace/chapter75/Chapter75ApplicationTests.java +++ b/2.x/chapter7-5/src/test/java/com/didispace/chapter75/Chapter75ApplicationTests.java @@ -5,6 +5,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; + @Slf4j @SpringBootTest public class Chapter75ApplicationTests { @@ -14,9 +17,17 @@ public class Chapter75ApplicationTests { @Test public void test() throws Exception { - asyncTasks.doTaskOne(); - asyncTasks.doTaskTwo(); - asyncTasks.doTaskThree(); + long start = System.currentTimeMillis(); + + CompletableFuture task1 = asyncTasks.doTaskOne(); + CompletableFuture task2 = asyncTasks.doTaskTwo(); + CompletableFuture task3 = asyncTasks.doTaskThree(); + + CompletableFuture.allOf(task1, task2, task3).join(); + + long end = System.currentTimeMillis(); + + log.info("任务全部完成,总耗时:" + (end - start) + "毫秒"); } } From ee785269238f00c1a60904757e6998d26fe9b92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Tue, 14 Sep 2021 17:24:54 +0800 Subject: [PATCH 72/97] =?UTF-8?q?@Async=E5=BC=82=E6=AD=A5=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E7=BA=BF=E7=A8=8B=E6=B1=A0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter7-6/pom.xml | 50 +++++++++++++++++++ .../com/didispace/chapter76/AsyncTasks.java | 46 +++++++++++++++++ .../chapter76/Chapter76Application.java | 15 ++++++ .../src/main/resources/application.properties | 0 .../chapter76/Chapter76ApplicationTests.java | 33 ++++++++++++ 2.x/pom.xml | 2 +- 6 files changed, 145 insertions(+), 1 deletion(-) create mode 100755 2.x/chapter7-6/pom.xml create mode 100644 2.x/chapter7-6/src/main/java/com/didispace/chapter76/AsyncTasks.java create mode 100644 2.x/chapter7-6/src/main/java/com/didispace/chapter76/Chapter76Application.java create mode 100644 2.x/chapter7-6/src/main/resources/application.properties create mode 100644 2.x/chapter7-6/src/test/java/com/didispace/chapter76/Chapter76ApplicationTests.java diff --git a/2.x/chapter7-6/pom.xml b/2.x/chapter7-6/pom.xml new file mode 100755 index 00000000..c67956f5 --- /dev/null +++ b/2.x/chapter7-6/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-6 + 0.0.1-SNAPSHOT + @Async异步任务的线程池配置 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter7-6/src/main/java/com/didispace/chapter76/AsyncTasks.java b/2.x/chapter7-6/src/main/java/com/didispace/chapter76/AsyncTasks.java new file mode 100644 index 00000000..3af4adcf --- /dev/null +++ b/2.x/chapter7-6/src/main/java/com/didispace/chapter76/AsyncTasks.java @@ -0,0 +1,46 @@ +package com.didispace.chapter76; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.util.Random; +import java.util.concurrent.CompletableFuture; + +@Slf4j +@Component +public class AsyncTasks { + + public static Random random = new Random(); + + @Async + public CompletableFuture doTaskOne() throws Exception { + log.info("开始做任务一"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务一,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务一完成"); + } + + @Async + public CompletableFuture doTaskTwo() throws Exception { + log.info("开始做任务二"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务二,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务二完成"); + } + + @Async + public CompletableFuture doTaskThree() throws Exception { + log.info("开始做任务三"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务三,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务三完成"); + } + +} \ No newline at end of file diff --git a/2.x/chapter7-6/src/main/java/com/didispace/chapter76/Chapter76Application.java b/2.x/chapter7-6/src/main/java/com/didispace/chapter76/Chapter76Application.java new file mode 100644 index 00000000..4f856eba --- /dev/null +++ b/2.x/chapter7-6/src/main/java/com/didispace/chapter76/Chapter76Application.java @@ -0,0 +1,15 @@ +package com.didispace.chapter76; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; + +@EnableAsync +@SpringBootApplication +public class Chapter76Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter76Application.class, args); + } + +} diff --git a/2.x/chapter7-6/src/main/resources/application.properties b/2.x/chapter7-6/src/main/resources/application.properties new file mode 100644 index 00000000..e69de29b diff --git a/2.x/chapter7-6/src/test/java/com/didispace/chapter76/Chapter76ApplicationTests.java b/2.x/chapter7-6/src/test/java/com/didispace/chapter76/Chapter76ApplicationTests.java new file mode 100644 index 00000000..44d7267c --- /dev/null +++ b/2.x/chapter7-6/src/test/java/com/didispace/chapter76/Chapter76ApplicationTests.java @@ -0,0 +1,33 @@ +package com.didispace.chapter76; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; + +@Slf4j +@SpringBootTest +public class Chapter76ApplicationTests { + + @Autowired + private AsyncTasks asyncTasks; + + @Test + public void test() throws Exception { + long start = System.currentTimeMillis(); + + CompletableFuture task1 = asyncTasks.doTaskOne(); + CompletableFuture task2 = asyncTasks.doTaskTwo(); + CompletableFuture task3 = asyncTasks.doTaskThree(); + + CompletableFuture.allOf(task1, task2, task3).join(); + + long end = System.currentTimeMillis(); + + log.info("任务全部完成,总耗时:" + (end - start) + "毫秒"); + } + +} diff --git a/2.x/pom.xml b/2.x/pom.xml index 3c743265..d72dcbe2 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -76,7 +76,7 @@ chapter7-3 chapter7-4 chapter7-5 - + chapter7-6 From 0bfbf6500210a0da81f7da1974e7d2b2aa23d1cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 15 Sep 2021 00:57:26 +0800 Subject: [PATCH 73/97] =?UTF-8?q?=E9=85=8D=E7=BD=AE@Async=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E4=BB=BB=E5=8A=A1=E7=9A=84=E7=BA=BF=E7=A8=8B=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 5 +++++ 2.x/README_zh.md | 5 +++++ .../main/java/com/didispace/chapter76/AsyncTasks.java | 1 + 2.x/chapter7-6/src/main/resources/application.properties | 9 +++++++++ .../didispace/chapter76/Chapter76ApplicationTests.java | 3 +-- 2.x/pom.xml | 6 +++++- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index 7ce6922a..82131402 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -83,12 +83,17 @@ ### 任务管理 +**定时任务** + - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) +**异步任务* + - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) +- [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) ### 常见问题 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index ed03e29c..c533d737 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -85,12 +85,17 @@ ### 任务管理 +**定时任务** + - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) +**异步任务* + - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) +- [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) ### 常见问题 diff --git a/2.x/chapter7-6/src/main/java/com/didispace/chapter76/AsyncTasks.java b/2.x/chapter7-6/src/main/java/com/didispace/chapter76/AsyncTasks.java index 3af4adcf..66a01d8e 100644 --- a/2.x/chapter7-6/src/main/java/com/didispace/chapter76/AsyncTasks.java +++ b/2.x/chapter7-6/src/main/java/com/didispace/chapter76/AsyncTasks.java @@ -6,6 +6,7 @@ import java.util.Random; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; @Slf4j @Component diff --git a/2.x/chapter7-6/src/main/resources/application.properties b/2.x/chapter7-6/src/main/resources/application.properties index e69de29b..070a4b71 100644 --- a/2.x/chapter7-6/src/main/resources/application.properties +++ b/2.x/chapter7-6/src/main/resources/application.properties @@ -0,0 +1,9 @@ +spring.task.execution.pool.core-size=2 +spring.task.execution.pool.max-size=5 +spring.task.execution.pool.queue-capacity=10 +spring.task.execution.pool.keep-alive=60s +spring.task.execution.pool.allow-core-thread-timeout=true +spring.task.execution.thread-name-prefix=task- + +spring.task.execution.shutdown.await-termination=false +spring.task.execution.shutdown.await-termination-period=30s \ No newline at end of file diff --git a/2.x/chapter7-6/src/test/java/com/didispace/chapter76/Chapter76ApplicationTests.java b/2.x/chapter7-6/src/test/java/com/didispace/chapter76/Chapter76ApplicationTests.java index 44d7267c..2a832502 100644 --- a/2.x/chapter7-6/src/test/java/com/didispace/chapter76/Chapter76ApplicationTests.java +++ b/2.x/chapter7-6/src/test/java/com/didispace/chapter76/Chapter76ApplicationTests.java @@ -6,7 +6,6 @@ import org.springframework.boot.test.context.SpringBootTest; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; @Slf4j @SpringBootTest @@ -16,7 +15,7 @@ public class Chapter76ApplicationTests { private AsyncTasks asyncTasks; @Test - public void test() throws Exception { + public void test1() throws Exception { long start = System.currentTimeMillis(); CompletableFuture task1 = asyncTasks.doTaskOne(); diff --git a/2.x/pom.xml b/2.x/pom.xml index d72dcbe2..e940e683 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -76,7 +76,11 @@ chapter7-3 chapter7-4 chapter7-5 - chapter7-6 + chapter7-6 + + + + chapter8-1 From 2a5e47d005ca69e0a71440dd32278deb83677c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 15 Sep 2021 00:57:49 +0800 Subject: [PATCH 74/97] =?UTF-8?q?@Async=E5=BC=82=E6=AD=A5=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E7=BA=BF=E7=A8=8B=E6=B1=A0=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter7-7/pom.xml | 50 ++++++++++++++++ .../com/didispace/chapter77/AsyncTasks.java | 57 +++++++++++++++++++ .../chapter77/Chapter77Application.java | 43 ++++++++++++++ .../src/main/resources/application.properties | 9 +++ .../chapter77/Chapter77ApplicationTests.java | 48 ++++++++++++++++ 5 files changed, 207 insertions(+) create mode 100755 2.x/chapter7-7/pom.xml create mode 100644 2.x/chapter7-7/src/main/java/com/didispace/chapter77/AsyncTasks.java create mode 100644 2.x/chapter7-7/src/main/java/com/didispace/chapter77/Chapter77Application.java create mode 100644 2.x/chapter7-7/src/main/resources/application.properties create mode 100644 2.x/chapter7-7/src/test/java/com/didispace/chapter77/Chapter77ApplicationTests.java diff --git a/2.x/chapter7-7/pom.xml b/2.x/chapter7-7/pom.xml new file mode 100755 index 00000000..bed2f64b --- /dev/null +++ b/2.x/chapter7-7/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-6 + 0.0.1-SNAPSHOT + @Async异步任务的线程池隔离 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter7-7/src/main/java/com/didispace/chapter77/AsyncTasks.java b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/AsyncTasks.java new file mode 100644 index 00000000..a538e379 --- /dev/null +++ b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/AsyncTasks.java @@ -0,0 +1,57 @@ +package com.didispace.chapter77; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.util.Random; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; + +@Slf4j +@Component +public class AsyncTasks { + + public static Random random = new Random(); + + @Async + public CompletableFuture doTaskOne() throws Exception { + log.info("开始做任务一"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务一,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务一完成"); + } + + @Async + public CompletableFuture doTaskTwo() throws Exception { + log.info("开始做任务二"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务二,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务二完成"); + } + + @Async + public CompletableFuture doTaskThree() throws Exception { + log.info("开始做任务三"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务三,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务三完成"); + } + + @Async("taskExecutor2") + public CompletableFuture doTaskFour() throws Exception { + log.info("开始做任务四"); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务四,耗时:" + (end - start) + "毫秒"); + return CompletableFuture.completedFuture("任务四完成"); + } + +} \ No newline at end of file diff --git a/2.x/chapter7-7/src/main/java/com/didispace/chapter77/Chapter77Application.java b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/Chapter77Application.java new file mode 100644 index 00000000..127eaf46 --- /dev/null +++ b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/Chapter77Application.java @@ -0,0 +1,43 @@ +package com.didispace.chapter77; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +@EnableAsync +@SpringBootApplication +public class Chapter76Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter76Application.class, args); + } + + @EnableAsync + @Configuration + class TaskPoolConfig { + +// @Bean +// public Executor taskExecutor2() { +// ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); +// executor.setCorePoolSize(1); +// executor.setMaxPoolSize(2); +// executor.setQueueCapacity(50); +// executor.setKeepAliveSeconds(60); +// executor.setThreadNamePrefix("taskExecutor2-"); +// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); +// return executor; +// } + + } + +} diff --git a/2.x/chapter7-7/src/main/resources/application.properties b/2.x/chapter7-7/src/main/resources/application.properties new file mode 100644 index 00000000..070a4b71 --- /dev/null +++ b/2.x/chapter7-7/src/main/resources/application.properties @@ -0,0 +1,9 @@ +spring.task.execution.pool.core-size=2 +spring.task.execution.pool.max-size=5 +spring.task.execution.pool.queue-capacity=10 +spring.task.execution.pool.keep-alive=60s +spring.task.execution.pool.allow-core-thread-timeout=true +spring.task.execution.thread-name-prefix=task- + +spring.task.execution.shutdown.await-termination=false +spring.task.execution.shutdown.await-termination-period=30s \ No newline at end of file diff --git a/2.x/chapter7-7/src/test/java/com/didispace/chapter77/Chapter77ApplicationTests.java b/2.x/chapter7-7/src/test/java/com/didispace/chapter77/Chapter77ApplicationTests.java new file mode 100644 index 00000000..84f52c48 --- /dev/null +++ b/2.x/chapter7-7/src/test/java/com/didispace/chapter77/Chapter77ApplicationTests.java @@ -0,0 +1,48 @@ +package com.didispace.chapter76; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; + +@Slf4j +@SpringBootTest +public class Chapter76ApplicationTests { + + @Autowired + private AsyncTasks asyncTasks; + + @Test + public void test1() throws Exception { + long start = System.currentTimeMillis(); + + CompletableFuture task1 = asyncTasks.doTaskOne(); + CompletableFuture task2 = asyncTasks.doTaskTwo(); + CompletableFuture task3 = asyncTasks.doTaskThree(); + + CompletableFuture.allOf(task1, task2, task3).join(); + + long end = System.currentTimeMillis(); + + log.info("任务全部完成,总耗时:" + (end - start) + "毫秒"); + } + + @Test + public void test2() throws Exception { + long start = System.currentTimeMillis(); + + CompletableFuture task1 = asyncTasks.doTaskFour(); + CompletableFuture task2 = asyncTasks.doTaskFour(); + CompletableFuture task3 = asyncTasks.doTaskFour(); + + CompletableFuture.allOf(task1, task2, task3).join(); + + long end = System.currentTimeMillis(); + + log.info("任务全部完成,总耗时:" + (end - start) + "毫秒"); + } + +} From 3dae3e62b9516491241c8d6559ef321b1f9fb1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 15 Sep 2021 00:58:22 +0800 Subject: [PATCH 75/97] =?UTF-8?q?Spring=20Security=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E5=85=A5=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter8-1/pom.xml | 63 +++++++++++++++++++ .../com/didispace/chapter81/Application.java | 22 +++++++ .../didispace/chapter81/HelloController.java | 33 ++++++++++ .../chapter81/WebSecurityConfig.java | 36 +++++++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/templates/hello.html | 13 ++++ .../src/main/resources/templates/index.html | 12 ++++ .../src/main/resources/templates/login.html | 21 +++++++ 8 files changed, 200 insertions(+) create mode 100644 2.x/chapter8-1/pom.xml create mode 100644 2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java create mode 100644 2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java create mode 100644 2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java create mode 100644 2.x/chapter8-1/src/main/resources/application.properties create mode 100644 2.x/chapter8-1/src/main/resources/templates/hello.html create mode 100644 2.x/chapter8-1/src/main/resources/templates/index.html create mode 100644 2.x/chapter8-1/src/main/resources/templates/login.html diff --git a/2.x/chapter8-1/pom.xml b/2.x/chapter8-1/pom.xml new file mode 100644 index 00000000..81817f27 --- /dev/null +++ b/2.x/chapter8-1/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter8-1 + 0.0.1-SNAPSHOT + Spring Security快速入门 + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-security + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java new file mode 100644 index 00000000..f7a9e16e --- /dev/null +++ b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java @@ -0,0 +1,22 @@ +package com.didispace; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + * + */ +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + + SpringApplication.run(Application.class, args); + + } + +} diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java new file mode 100644 index 00000000..f5a6770b --- /dev/null +++ b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java @@ -0,0 +1,33 @@ +package com.didispace.chapter81; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + * + */ +@Controller +public class HelloController { + + @RequestMapping("/") + public String index() { + return "index"; + } + + @RequestMapping("/hello") + public String hello() { + return "hello"; + } + + @RequestMapping(value = "/login", method = RequestMethod.GET) + public String login() { + return "login"; + } + +} \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java new file mode 100644 index 00000000..1f3da340 --- /dev/null +++ b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java @@ -0,0 +1,36 @@ +package com.didispace.chapter81; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .antMatchers("/", "/home").permitAll() + .anyRequest().authenticated() + .and() + .formLogin() + .loginPage("/login") + .permitAll() + .and() + .logout() + .permitAll(); + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth + .inMemoryAuthentication() + .withUser("user").password("password").roles("USER"); + } + +} \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/resources/application.properties b/2.x/chapter8-1/src/main/resources/application.properties new file mode 100644 index 00000000..e69de29b diff --git a/2.x/chapter8-1/src/main/resources/templates/hello.html b/2.x/chapter8-1/src/main/resources/templates/hello.html new file mode 100644 index 00000000..51477131 --- /dev/null +++ b/2.x/chapter8-1/src/main/resources/templates/hello.html @@ -0,0 +1,13 @@ + + + + Hello World! + + +

Hello [[${#httpServletRequest.remoteUser}]]!

+
+ +
+ + \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/resources/templates/index.html b/2.x/chapter8-1/src/main/resources/templates/index.html new file mode 100644 index 00000000..ffe28340 --- /dev/null +++ b/2.x/chapter8-1/src/main/resources/templates/index.html @@ -0,0 +1,12 @@ + + + + Spring Security入门 + + +

欢迎使用Spring Security!

+ +

点击 这里 打个招呼吧

+ + \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/resources/templates/login.html b/2.x/chapter8-1/src/main/resources/templates/login.html new file mode 100644 index 00000000..f5cbe8e2 --- /dev/null +++ b/2.x/chapter8-1/src/main/resources/templates/login.html @@ -0,0 +1,21 @@ + + + + Spring Security Example + + +
+ 用户名或密码错 +
+
+ 您已注销成功 +
+
+
+
+
+
+ + \ No newline at end of file From 854720573ee7306d5aa5f5df05244f65eb6d0951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 15 Sep 2021 12:31:35 +0800 Subject: [PATCH 76/97] 1 --- 2.x/README.md | 2 +- 2.x/README_zh.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/2.x/README.md b/2.x/README.md index 82131402..08ae2291 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -94,7 +94,7 @@ - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) - +- [Spring Boot 2.x基础教程:@Async异步任务的线程池隔离](https://blog.didispace.com/spring-boot-learning-2-7-7) ### 常见问题 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index c533d737..0566a534 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -96,6 +96,7 @@ - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) +- [Spring Boot 2.x基础教程:@Async异步任务的线程池隔离](https://blog.didispace.com/spring-boot-learning-2-7-7) ### 常见问题 From 7866b41a8030364d546145b47a460a35cd543826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 15 Sep 2021 23:51:10 +0800 Subject: [PATCH 77/97] =?UTF-8?q?=E5=A6=82=E4=BD=95=E9=9A=94=E7=A6=BB@Asyn?= =?UTF-8?q?c=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1=E7=9A=84=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 2 +- 2.x/README_zh.md | 2 +- 2.x/chapter7-7/pom.xml | 4 +- .../com/didispace/chapter77/AsyncTasks.java | 39 +++++-------------- .../chapter77/Chapter77Application.java | 38 +++++++++++------- .../src/main/resources/application.properties | 9 ----- .../chapter77/Chapter77ApplicationTests.java | 34 +++++++--------- 2.x/pom.xml | 2 +- 8 files changed, 52 insertions(+), 78 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index 08ae2291..936fa1b3 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -94,7 +94,7 @@ - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) -- [Spring Boot 2.x基础教程:@Async异步任务的线程池隔离](https://blog.didispace.com/spring-boot-learning-2-7-7) +- [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) ### 常见问题 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 0566a534..0c10db16 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -96,7 +96,7 @@ - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) -- [Spring Boot 2.x基础教程:@Async异步任务的线程池隔离](https://blog.didispace.com/spring-boot-learning-2-7-7) +- [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) ### 常见问题 diff --git a/2.x/chapter7-7/pom.xml b/2.x/chapter7-7/pom.xml index bed2f64b..2a69afe0 100755 --- a/2.x/chapter7-7/pom.xml +++ b/2.x/chapter7-7/pom.xml @@ -11,9 +11,9 @@
com.didispace - chapter7-6 + chapter7-7 0.0.1-SNAPSHOT - @Async异步任务的线程池隔离 + 如何隔离@Async异步任务的线程池 1.8 diff --git a/2.x/chapter7-7/src/main/java/com/didispace/chapter77/AsyncTasks.java b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/AsyncTasks.java index a538e379..90185dc8 100644 --- a/2.x/chapter7-7/src/main/java/com/didispace/chapter77/AsyncTasks.java +++ b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/AsyncTasks.java @@ -6,7 +6,6 @@ import java.util.Random; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; @Slf4j @Component @@ -14,44 +13,24 @@ public class AsyncTasks { public static Random random = new Random(); - @Async - public CompletableFuture doTaskOne() throws Exception { - log.info("开始做任务一"); + @Async("taskExecutor1") + public CompletableFuture doTaskOne(String taskNo) throws Exception { + log.info("开始任务:{}", taskNo); long start = System.currentTimeMillis(); Thread.sleep(random.nextInt(10000)); long end = System.currentTimeMillis(); - log.info("完成任务一,耗时:" + (end - start) + "毫秒"); - return CompletableFuture.completedFuture("任务一完成"); - } - - @Async - public CompletableFuture doTaskTwo() throws Exception { - log.info("开始做任务二"); - long start = System.currentTimeMillis(); - Thread.sleep(random.nextInt(10000)); - long end = System.currentTimeMillis(); - log.info("完成任务二,耗时:" + (end - start) + "毫秒"); - return CompletableFuture.completedFuture("任务二完成"); - } - - @Async - public CompletableFuture doTaskThree() throws Exception { - log.info("开始做任务三"); - long start = System.currentTimeMillis(); - Thread.sleep(random.nextInt(10000)); - long end = System.currentTimeMillis(); - log.info("完成任务三,耗时:" + (end - start) + "毫秒"); - return CompletableFuture.completedFuture("任务三完成"); + log.info("完成任务:{},耗时:{} 毫秒", taskNo, end - start); + return CompletableFuture.completedFuture("任务完成"); } @Async("taskExecutor2") - public CompletableFuture doTaskFour() throws Exception { - log.info("开始做任务四"); + public CompletableFuture doTaskTwo(String taskNo) throws Exception { + log.info("开始任务:{}", taskNo); long start = System.currentTimeMillis(); Thread.sleep(random.nextInt(10000)); long end = System.currentTimeMillis(); - log.info("完成任务四,耗时:" + (end - start) + "毫秒"); - return CompletableFuture.completedFuture("任务四完成"); + log.info("完成任务:{},耗时:{} 毫秒", taskNo, end - start); + return CompletableFuture.completedFuture("任务完成"); } } \ No newline at end of file diff --git a/2.x/chapter7-7/src/main/java/com/didispace/chapter77/Chapter77Application.java b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/Chapter77Application.java index 127eaf46..e598f26d 100644 --- a/2.x/chapter7-7/src/main/java/com/didispace/chapter77/Chapter77Application.java +++ b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/Chapter77Application.java @@ -16,27 +16,39 @@ @EnableAsync @SpringBootApplication -public class Chapter76Application { +public class Chapter77Application { public static void main(String[] args) { - SpringApplication.run(Chapter76Application.class, args); + SpringApplication.run(Chapter77Application.class, args); } @EnableAsync @Configuration class TaskPoolConfig { -// @Bean -// public Executor taskExecutor2() { -// ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); -// executor.setCorePoolSize(1); -// executor.setMaxPoolSize(2); -// executor.setQueueCapacity(50); -// executor.setKeepAliveSeconds(60); -// executor.setThreadNamePrefix("taskExecutor2-"); -// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); -// return executor; -// } + @Bean + public Executor taskExecutor1() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(2); + executor.setMaxPoolSize(2); + executor.setQueueCapacity(10); + executor.setKeepAliveSeconds(60); + executor.setThreadNamePrefix("executor-1-"); + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + return executor; + } + + @Bean + public Executor taskExecutor2() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(2); + executor.setMaxPoolSize(2); + executor.setQueueCapacity(10); + executor.setKeepAliveSeconds(60); + executor.setThreadNamePrefix("executor-2-"); + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + return executor; + } } diff --git a/2.x/chapter7-7/src/main/resources/application.properties b/2.x/chapter7-7/src/main/resources/application.properties index 070a4b71..e69de29b 100644 --- a/2.x/chapter7-7/src/main/resources/application.properties +++ b/2.x/chapter7-7/src/main/resources/application.properties @@ -1,9 +0,0 @@ -spring.task.execution.pool.core-size=2 -spring.task.execution.pool.max-size=5 -spring.task.execution.pool.queue-capacity=10 -spring.task.execution.pool.keep-alive=60s -spring.task.execution.pool.allow-core-thread-timeout=true -spring.task.execution.thread-name-prefix=task- - -spring.task.execution.shutdown.await-termination=false -spring.task.execution.shutdown.await-termination-period=30s \ No newline at end of file diff --git a/2.x/chapter7-7/src/test/java/com/didispace/chapter77/Chapter77ApplicationTests.java b/2.x/chapter7-7/src/test/java/com/didispace/chapter77/Chapter77ApplicationTests.java index 84f52c48..d6479787 100644 --- a/2.x/chapter7-7/src/test/java/com/didispace/chapter77/Chapter77ApplicationTests.java +++ b/2.x/chapter7-7/src/test/java/com/didispace/chapter77/Chapter77ApplicationTests.java @@ -1,4 +1,4 @@ -package com.didispace.chapter76; +package com.didispace.chapter77; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; @@ -10,35 +10,27 @@ @Slf4j @SpringBootTest -public class Chapter76ApplicationTests { +public class Chapter77ApplicationTests { @Autowired private AsyncTasks asyncTasks; @Test - public void test1() throws Exception { + public void test() throws Exception { long start = System.currentTimeMillis(); - CompletableFuture task1 = asyncTasks.doTaskOne(); - CompletableFuture task2 = asyncTasks.doTaskTwo(); - CompletableFuture task3 = asyncTasks.doTaskThree(); + // 线程池1 + CompletableFuture task1 = asyncTasks.doTaskOne("1"); + CompletableFuture task2 = asyncTasks.doTaskOne("2"); + CompletableFuture task3 = asyncTasks.doTaskOne("3"); - CompletableFuture.allOf(task1, task2, task3).join(); + // 线程池2 + CompletableFuture task4 = asyncTasks.doTaskTwo("4"); + CompletableFuture task5 = asyncTasks.doTaskTwo("5"); + CompletableFuture task6 = asyncTasks.doTaskTwo("6"); - long end = System.currentTimeMillis(); - - log.info("任务全部完成,总耗时:" + (end - start) + "毫秒"); - } - - @Test - public void test2() throws Exception { - long start = System.currentTimeMillis(); - - CompletableFuture task1 = asyncTasks.doTaskFour(); - CompletableFuture task2 = asyncTasks.doTaskFour(); - CompletableFuture task3 = asyncTasks.doTaskFour(); - - CompletableFuture.allOf(task1, task2, task3).join(); + // 一起执行 + CompletableFuture.allOf(task1, task2, task3, task4, task5, task6).join(); long end = System.currentTimeMillis(); diff --git a/2.x/pom.xml b/2.x/pom.xml index e940e683..1a260592 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -77,7 +77,7 @@ chapter7-4 chapter7-5 chapter7-6 - + chapter7-7 chapter8-1 From 9feeec755da9b5b54bfc115236652983c572c6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 22 Sep 2021 17:03:27 +0800 Subject: [PATCH 78/97] =?UTF-8?q?=E4=B8=BA@Async=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=BA=BF=E7=A8=8B=E6=B1=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=8B=92=E7=BB=9D=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 1 + 2.x/README_zh.md | 1 + 2.x/chapter7-8/pom.xml | 50 +++++++++++++++ .../com/didispace/chapter78/AsyncTasks.java | 36 +++++++++++ .../chapter78/Chapter78Application.java | 45 ++++++++++++++ .../src/main/resources/application.properties | 0 .../chapter78/Chapter78ApplicationTests.java | 61 +++++++++++++++++++ 2.x/pom.xml | 4 +- 8 files changed, 197 insertions(+), 1 deletion(-) create mode 100755 2.x/chapter7-8/pom.xml create mode 100644 2.x/chapter7-8/src/main/java/com/didispace/chapter78/AsyncTasks.java create mode 100644 2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java create mode 100644 2.x/chapter7-8/src/main/resources/application.properties create mode 100644 2.x/chapter7-8/src/test/java/com/didispace/chapter78/Chapter78ApplicationTests.java diff --git a/2.x/README.md b/2.x/README.md index 936fa1b3..324ba82b 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -95,6 +95,7 @@ - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) - [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) +- [Spring Boot 2.x基础教程:为@Async异步任务线程池配置拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) ### 常见问题 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 0c10db16..c1f7c929 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -97,6 +97,7 @@ - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) - [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) +- [Spring Boot 2.x基础教程:为@Async异步任务的线程池设置拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) ### 常见问题 diff --git a/2.x/chapter7-8/pom.xml b/2.x/chapter7-8/pom.xml new file mode 100755 index 00000000..40158a94 --- /dev/null +++ b/2.x/chapter7-8/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-8 + 0.0.1-SNAPSHOT + 为@Async异步任务线程池配置拒绝策略 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/2.x/chapter7-8/src/main/java/com/didispace/chapter78/AsyncTasks.java b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/AsyncTasks.java new file mode 100644 index 00000000..c6a78519 --- /dev/null +++ b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/AsyncTasks.java @@ -0,0 +1,36 @@ +package com.didispace.chapter78; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.util.Random; +import java.util.concurrent.CompletableFuture; + +@Slf4j +@Component +public class AsyncTasks { + + public static Random random = new Random(); + + @Async("taskExecutor1") + public CompletableFuture doTaskOne(String taskNo) throws Exception { + log.info("开始任务:{}", taskNo); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务:{},耗时:{} 毫秒", taskNo, end - start); + return CompletableFuture.completedFuture("任务完成"); + } + + @Async("taskExecutor2") + public CompletableFuture doTaskTwo(String taskNo) throws Exception { + log.info("开始任务:{}", taskNo); + long start = System.currentTimeMillis(); + Thread.sleep(random.nextInt(10000)); + long end = System.currentTimeMillis(); + log.info("完成任务:{},耗时:{} 毫秒", taskNo, end - start); + return CompletableFuture.completedFuture("任务完成"); + } + +} \ No newline at end of file diff --git a/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java new file mode 100644 index 00000000..04870377 --- /dev/null +++ b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java @@ -0,0 +1,45 @@ +package com.didispace.chapter78; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +@EnableAsync +@SpringBootApplication +public class Chapter78Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter78Application.class, args); + } + + @EnableAsync + @Configuration + class TaskPoolConfig { + + @Bean + public Executor taskExecutor1() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(2); + executor.setMaxPoolSize(2); + executor.setQueueCapacity(2); + executor.setKeepAliveSeconds(60); + executor.setThreadNamePrefix("executor-1-"); + + // 配置拒绝策略 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + return executor; + } + + } + +} diff --git a/2.x/chapter7-8/src/main/resources/application.properties b/2.x/chapter7-8/src/main/resources/application.properties new file mode 100644 index 00000000..e69de29b diff --git a/2.x/chapter7-8/src/test/java/com/didispace/chapter78/Chapter78ApplicationTests.java b/2.x/chapter7-8/src/test/java/com/didispace/chapter78/Chapter78ApplicationTests.java new file mode 100644 index 00000000..6b9a3919 --- /dev/null +++ b/2.x/chapter7-8/src/test/java/com/didispace/chapter78/Chapter78ApplicationTests.java @@ -0,0 +1,61 @@ +package com.didispace.chapter78; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; + +@Slf4j +@SpringBootTest +public class Chapter78ApplicationTests { + + @Autowired + private AsyncTasks asyncTasks; + + @Test + public void test() throws Exception { + // 线程池配置:core-2,max-2,queue=2,可以容纳4个任务提交 + + long start = System.currentTimeMillis(); + + // 线程池1 + CompletableFuture task1 = asyncTasks.doTaskOne("1"); + CompletableFuture task2 = asyncTasks.doTaskOne("2"); + CompletableFuture task3 = asyncTasks.doTaskOne("3"); + CompletableFuture task4 = asyncTasks.doTaskOne("4"); + + // 一起执行 + CompletableFuture.allOf(task1, task2, task3, task4).join(); + + long end = System.currentTimeMillis(); + + log.info("任务全部完成,总耗时:" + (end - start) + "毫秒"); + } + + @Test + public void test2() throws Exception { + // 线程池配置:core-2,max-2,queue=2,同时有5个任务,出现下面异常: + // org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@59901c4d[Running, pool size = 2, + // active threads = 0, queued tasks = 2, completed tasks = 4]] did not accept task: java.util.concurrent.CompletableFuture$AsyncSupply@408e96d9 + + long start = System.currentTimeMillis(); + + // 线程池1 + CompletableFuture task1 = asyncTasks.doTaskOne("1"); + CompletableFuture task2 = asyncTasks.doTaskOne("2"); + CompletableFuture task3 = asyncTasks.doTaskOne("3"); + CompletableFuture task4 = asyncTasks.doTaskOne("4"); + CompletableFuture task5 = asyncTasks.doTaskOne("5"); + + // 一起执行 + CompletableFuture.allOf(task1, task2, task3, task4, task5).join(); + + long end = System.currentTimeMillis(); + + log.info("任务全部完成,总耗时:" + (end - start) + "毫秒"); + } + +} diff --git a/2.x/pom.xml b/2.x/pom.xml index 1a260592..293aad51 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -77,7 +77,9 @@ chapter7-4 chapter7-5 chapter7-6 - chapter7-7 + chapter7-7 + chapter7-8 + chapter8-1 From ddcb8cc33230cf7465f31f4d347ca2b870703714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 22 Sep 2021 17:50:49 +0800 Subject: [PATCH 79/97] =?UTF-8?q?=E4=B8=BA@Async=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=BA=BF=E7=A8=8B=E6=B1=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=8B=92=E7=BB=9D=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/didispace/chapter78/AsyncTasks.java | 10 -------- .../chapter78/Chapter78Application.java | 25 +++++++++++++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/2.x/chapter7-8/src/main/java/com/didispace/chapter78/AsyncTasks.java b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/AsyncTasks.java index c6a78519..5cb782f5 100644 --- a/2.x/chapter7-8/src/main/java/com/didispace/chapter78/AsyncTasks.java +++ b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/AsyncTasks.java @@ -23,14 +23,4 @@ public CompletableFuture doTaskOne(String taskNo) throws Exception { return CompletableFuture.completedFuture("任务完成"); } - @Async("taskExecutor2") - public CompletableFuture doTaskTwo(String taskNo) throws Exception { - log.info("开始任务:{}", taskNo); - long start = System.currentTimeMillis(); - Thread.sleep(random.nextInt(10000)); - long end = System.currentTimeMillis(); - log.info("完成任务:{},耗时:{} 毫秒", taskNo, end - start); - return CompletableFuture.completedFuture("任务完成"); - } - } \ No newline at end of file diff --git a/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java index 04870377..c8573f87 100644 --- a/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java +++ b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.Executor; +import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; @EnableAsync @@ -35,8 +36,28 @@ public Executor taskExecutor1() { executor.setKeepAliveSeconds(60); executor.setThreadNamePrefix("executor-1-"); - // 配置拒绝策略 - executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + /**配置拒绝策略**/ + + // AbortPolicy策略:默认策略,如果线程池队列满了丢掉这个任务并且抛出RejectedExecutionException异常。 +// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy()); + + // DiscardPolicy策略:如果线程池队列满了,会直接丢掉这个任务并且不会有任何异常。 +// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); + + // DiscardOldestPolicy策略:如果队列满了,会将最早进入队列的任务删掉腾出空间,再尝试加入队列。 +// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy()); + + // CallerRunsPolicy策略:如果添加到线程池失败,那么主线程会自己去执行该任务,不会等待线程池中的线程去执行。 +// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + + // 自定义策略 +// executor.setRejectedExecutionHandler(new RejectedExecutionHandler() { +// @Override +// public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { +// +// } +// }); + return executor; } From 832f5549e32dc3bcb14387763773a403aee542c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 22 Sep 2021 18:00:34 +0800 Subject: [PATCH 80/97] =?UTF-8?q?=E4=B8=BA@Async=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=BA=BF=E7=A8=8B=E6=B1=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=8B=92=E7=BB=9D=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/didispace/chapter78/Chapter78Application.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java index c8573f87..f04169be 100644 --- a/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java +++ b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java @@ -1,19 +1,13 @@ package com.didispace.chapter78; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.Executor; -import java.util.concurrent.RejectedExecutionHandler; -import java.util.concurrent.ThreadPoolExecutor; @EnableAsync @SpringBootApplication From f3e71f55bb8ff1ce70cc040ff069b6e5401081fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 22 Sep 2021 18:53:45 +0800 Subject: [PATCH 81/97] =?UTF-8?q?=E4=B8=BA@Async=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=BA=BF=E7=A8=8B=E6=B1=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=8B=92=E7=BB=9D=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 4 ++-- 2.x/README_zh.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index 324ba82b..a6627efd 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -90,12 +90,12 @@ - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) -**异步任务* +**异步任务** - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) - [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) -- [Spring Boot 2.x基础教程:为@Async异步任务线程池配置拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) +- [Spring Boot 2.x基础教程:配置线程池的拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) ### 常见问题 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index c1f7c929..fd94ee25 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -92,12 +92,12 @@ - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) -**异步任务* +**异步任务** - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) - [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) -- [Spring Boot 2.x基础教程:为@Async异步任务的线程池设置拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) +- [Spring Boot 2.x基础教程:配置线程池的拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) ### 常见问题 From 0b83b965faebaa274aa4560f389119942b65810d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 22 Sep 2021 19:08:47 +0800 Subject: [PATCH 82/97] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 60 +++++++++------------------------------------------- README_zh.md | 60 +++++++++------------------------------------------- 2 files changed, 20 insertions(+), 100 deletions(-) diff --git a/README.md b/README.md index e962dabe..84dea730 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,35 @@ # Spring Boot基础教程 -本项目内容为[《Spring Boot基础教程》](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 - **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) - **如何支持**: 1. 关注我的公众号”**程序猿DD**“ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 +**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) + ## 教程目录 -该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总。 +该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。 + +为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总。 可以通过下面的链接,进入具体版本的教程目录: -- [Spring Boot 2.x 版本教程](./2.x) -- [Spring Boot 1.x 版本教程](./1.x) +- [Spring Boot 2.x](./2.x) +- [Spring Boot 1.x](./1.x) > **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
## 推荐内容 - [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 -- [我的Spring Boot教程](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 -- [我的Spring Cloud教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 +- [Spring Boot教程](https://blog.didispace.com/spring-boot-learning-2x/):全网Star最多的免费Spring Boot基础教程 +- [Spring Cloud教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 - [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 -## 特别赞助商 - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` - -## 我的公众号 +**关注公众号,获得更多技术资讯** diff --git a/README_zh.md b/README_zh.md index e962dabe..84dea730 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1,75 +1,35 @@ # Spring Boot基础教程 -本项目内容为[《Spring Boot基础教程》](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/)的程序样例。 - **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) - **如何支持**: 1. 关注我的公众号”**程序猿DD**“ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 +**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) + ## 教程目录 -该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总。 +该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。 + +为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总。 可以通过下面的链接,进入具体版本的教程目录: -- [Spring Boot 2.x 版本教程](./2.x) -- [Spring Boot 1.x 版本教程](./1.x) +- [Spring Boot 2.x](./2.x) +- [Spring Boot 1.x](./1.x) > **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
## 推荐内容 - [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 -- [我的Spring Boot教程](https://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/):全网Star最多的免费Spring Boot基础教程 -- [我的Spring Cloud教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 +- [Spring Boot教程](https://blog.didispace.com/spring-boot-learning-2x/):全网Star最多的免费Spring Boot基础教程 +- [Spring Cloud教程](https://blog.didispace.com/spring-cloud-learning/):全网最早最全的免费Spring Cloud基础教程 - [知识星球](https://t.xiaomiquan.com/zfEiY3v):聊聊技术人的斜杠生活 -## 特别赞助商 - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` - -## 我的公众号 +**关注公众号,获得更多技术资讯** From 28a71aa31d4288672aa7ad95c619b49951c4c543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Thu, 23 Sep 2021 12:08:01 +0800 Subject: [PATCH 83/97] =?UTF-8?q?=E7=A7=BB=E9=99=A42.1.x=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.1.x/README.md | 4 - 2.1.x/README_zh.md | 4 - 2.1.x/chapter1-1/.gitignore | 29 - 2.1.x/chapter1-1/pom.xml | 43 - .../chapter11/Chapter11Application.java | 13 - .../didispace/chapter11/HelloController.java | 14 - .../src/main/resources/application.properties | 1 - .../chapter11/Chapter11ApplicationTests.java | 36 - 2.1.x/chapter2-1/.gitignore | 29 - 2.1.x/chapter2-1/pom.xml | 50 - .../chapter21/Chapter21Application.java | 13 - .../java/com/didispace/chapter21/User.java | 12 - .../didispace/chapter21/UserController.java | 79 - .../src/main/resources/application.properties | 1 - .../chapter21/Chapter21ApplicationTests.java | 79 - 2.1.x/chapter2-2/.gitignore | 29 - 2.1.x/chapter2-2/pom.xml | 56 - .../chapter22/Chapter22Application.java | 15 - .../java/com/didispace/chapter22/User.java | 18 - .../didispace/chapter22/UserController.java | 56 - .../src/main/resources/application.properties | 13 - 2.1.x/chapter2-3/.gitignore | 29 - 2.1.x/chapter2-3/pom.xml | 56 - .../chapter23/Chapter23Application.java | 15 - .../java/com/didispace/chapter23/User.java | 32 - .../didispace/chapter23/UserController.java | 57 - .../src/main/resources/application.properties | 13 - 2.1.x/chapter2-4/.gitignore | 29 - 2.1.x/chapter2-4/pom.xml | 56 - .../chapter24/Chapter24Application.java | 61 - .../java/com/didispace/chapter24/User.java | 32 - .../didispace/chapter24/UserController.java | 57 - .../src/main/resources/application.properties | 16 - 2.1.x/chapter2-5/.gitignore | 29 - 2.1.x/chapter2-5/pom.xml | 102 -- .../generated-by-plugin/definitions.adoc | 22 - .../generated-by-plugin/overview.adoc | 38 - .../asciidoc/generated-by-plugin/paths.adoc | 265 ---- .../generated-by-plugin/security.adoc | 13 - .../docs/asciidoc/generated/definitions.adoc | 22 - .../src/docs/asciidoc/generated/overview.adoc | 38 - .../src/docs/asciidoc/generated/paths.adoc | 265 ---- .../src/docs/asciidoc/generated/security.adoc | 13 - .../src/docs/asciidoc/html/definitions.html | 603 ------- .../src/docs/asciidoc/html/overview.html | 591 ------- .../src/docs/asciidoc/html/paths.html | 1379 ----------------- .../src/docs/asciidoc/html/security.html | 553 ------- .../docs/confluence/generated/definitions.txt | 14 - .../docs/confluence/generated/overview.txt | 33 - .../src/docs/confluence/generated/paths.txt | 212 --- .../docs/confluence/generated/security.txt | 10 - .../docs/markdown/generated/definitions.md | 17 - .../src/docs/markdown/generated/overview.md | 34 - .../src/docs/markdown/generated/paths.md | 232 --- .../src/docs/markdown/generated/security.md | 12 - .../chapter25/Chapter25Application.java | 15 - .../java/com/didispace/chapter25/User.java | 18 - .../didispace/chapter25/UserController.java | 56 - .../src/main/resources/application.properties | 13 - .../chapter25/DemoApplicationTests.java | 71 - 2.1.x/chapter2-6/.gitignore | 29 - 2.1.x/chapter2-6/pom.xml | 49 - .../chapter26/Chapter26Application.java | 13 - .../java/com/didispace/chapter26/User.java | 12 - .../didispace/chapter26/UserController.java | 46 - .../src/main/resources/application.properties | 3 - 2.1.x/chapter2-7/.gitignore | 24 - 2.1.x/chapter2-7/pom.xml | 67 - .../chapter27/Chapter27Application.java | 15 - .../java/com/didispace/chapter27/User.java | 29 - .../didispace/chapter27/UserController.java | 45 - .../src/main/resources/application.properties | 2 - 2.1.x/chapter3-1/.gitignore | 29 - 2.1.x/chapter3-1/pom.xml | 58 - .../chapter31/Chapter31Application.java | 13 - .../java/com/didispace/chapter31/User.java | 13 - .../com/didispace/chapter31/UserService.java | 40 - .../didispace/chapter31/UserServiceImpl.java | 52 - .../src/main/resources/application.properties | 4 - .../chapter31/Chapter31ApplicationTests.java | 63 - 2.1.x/chapter3-10/.gitignore | 29 - 2.1.x/chapter3-10/pom.xml | 64 - .../chapter310/Chapter310Application.java | 25 - .../java/com/didispace/chapter310/User.java | 27 - .../didispace/chapter310/UserRepository.java | 22 - .../src/main/resources/application.properties | 7 - .../Chapter310ApplicationTests.java | 56 - 2.1.x/chapter3-2/.gitignore | 29 - 2.1.x/chapter3-2/pom.xml | 58 - .../chapter32/Chapter32Application.java | 13 - .../java/com/didispace/chapter32/User.java | 13 - .../com/didispace/chapter32/UserService.java | 40 - .../didispace/chapter32/UserServiceImpl.java | 52 - .../src/main/resources/application.properties | 17 - .../chapter32/Chapter32ApplicationTests.java | 69 - 2.1.x/chapter3-3/.gitignore | 29 - 2.1.x/chapter3-3/pom.xml | 70 - .../chapter33/Chapter33Application.java | 25 - .../java/com/didispace/chapter33/User.java | 13 - .../didispace/chapter33/UserController.java | 47 - .../com/didispace/chapter33/UserService.java | 40 - .../didispace/chapter33/UserServiceImpl.java | 52 - .../src/main/resources/application.properties | 29 - .../chapter33/Chapter33ApplicationTests.java | 69 - 2.1.x/chapter3-4/.gitignore | 29 - 2.1.x/chapter3-4/pom.xml | 64 - .../chapter34/Chapter34Application.java | 25 - .../java/com/didispace/chapter34/User.java | 26 - .../didispace/chapter34/UserRepository.java | 22 - .../src/main/resources/application.properties | 6 - .../chapter34/Chapter34ApplicationTests.java | 57 - 2.1.x/chapter3-5/.gitignore | 29 - 2.1.x/chapter3-5/pom.xml | 55 - .../chapter35/Chapter35Application.java | 13 - .../java/com/didispace/chapter35/User.java | 20 - .../com/didispace/chapter35/UserMapper.java | 23 - .../src/main/resources/application.properties | 4 - .../chapter35/Chapter35ApplicationTests.java | 33 - 2.1.x/chapter3-6/.gitignore | 29 - 2.1.x/chapter3-6/pom.xml | 55 - .../chapter36/Chapter36Application.java | 15 - .../com/didispace/chapter36/entity/User.java | 20 - .../chapter36/mapper/UserMapper.java | 18 - .../src/main/resources/application.properties | 6 - .../src/main/resources/mapper/UserMapper.xml | 13 - .../chapter36/Chapter36ApplicationTests.java | 32 - 2.1.x/chapter3-7/.gitignore | 29 - 2.1.x/chapter3-7/pom.xml | 59 - .../chapter37/Chapter37Application.java | 13 - .../chapter37/DataSourceConfiguration.java | 39 - .../src/main/resources/application.properties | 11 - .../chapter37/Chapter37ApplicationTests.java | 46 - 2.1.x/chapter3-8/.gitignore | 29 - 2.1.x/chapter3-8/pom.xml | 65 - .../chapter38/Chapter38Application.java | 15 - .../chapter38/DataSourceConfiguration.java | 29 - .../didispace/chapter38/PrimaryConfig.java | 70 - .../didispace/chapter38/SecondaryConfig.java | 62 - .../java/com/didispace/chapter38/p/User.java | 27 - .../didispace/chapter38/p/UserRepository.java | 15 - .../com/didispace/chapter38/s/Message.java | 29 - .../chapter38/s/MessageRepository.java | 14 - .../src/main/resources/application.properties | 16 - .../chapter38/Chapter38ApplicationTests.java | 42 - 2.1.x/chapter3-9/.gitignore | 29 - 2.1.x/chapter3-9/pom.xml | 56 - .../chapter39/Chapter39Application.java | 13 - .../chapter39/DataSourceConfiguration.java | 27 - .../didispace/chapter39/PrimaryConfig.java | 38 - .../didispace/chapter39/SecondaryConfig.java | 38 - .../chapter39/p/entity/UserPrimary.java | 20 - .../chapter39/p/mapper/UserMapperPrimary.java | 26 - .../chapter39/s/entity/UserSecondary.java | 20 - .../s/mapper/UserMapperSecondary.java | 25 - .../src/main/resources/application.properties | 13 - .../resources/mapper.primary/UserMapper.xml | 15 - .../resources/mapper.secondary/UserMapper.xml | 16 - .../chapter39/Chapter39ApplicationTests.java | 60 - 2.1.x/chapter4-1/.gitignore | 29 - 2.1.x/chapter4-1/pom.xml | 54 - .../chapter41/Chapter41Application.java | 13 - .../didispace/chapter41/HelloController.java | 19 - .../src/main/resources/application.properties | 1 - .../src/main/resources/templates/index.html | 10 - 2.1.x/chapter4-2/.gitignore | 29 - 2.1.x/chapter4-2/pom.xml | 54 - .../chapter42/Chapter42Application.java | 13 - .../didispace/chapter42/HelloController.java | 16 - .../src/main/resources/application.properties | 1 - .../src/main/resources/templates/index.html | 30 - 2.1.x/chapter5-1/.gitignore | 29 - 2.1.x/chapter5-1/pom.xml | 69 - .../chapter51/Chapter51Application.java | 15 - .../java/com/didispace/chapter51/User.java | 26 - .../didispace/chapter51/UserRepository.java | 26 - .../src/main/resources/application.properties | 7 - .../chapter51/Chapter51ApplicationTests.java | 34 - 2.1.x/chapter5-2/.gitignore | 29 - 2.1.x/chapter5-2/pom.xml | 74 - .../chapter52/Chapter52Application.java | 15 - .../java/com/didispace/chapter52/User.java | 26 - .../didispace/chapter52/UserRepository.java | 21 - .../src/main/resources/application.properties | 7 - .../chapter5-2/src/main/resources/ehcache.xml | 9 - .../chapter52/Chapter52ApplicationTests.java | 36 - 2.1.x/chapter5-3/.gitignore | 29 - 2.1.x/chapter5-3/pom.xml | 74 - .../chapter53/Chapter53Application.java | 50 - .../java/com/didispace/chapter53/User.java | 27 - .../didispace/chapter53/UserRepository.java | 21 - .../src/main/resources/application.properties | 17 - .../src/main/resources/ehcache-1.xml | 29 - .../src/main/resources/ehcache-2.xml | 29 - .../chapter53/Chapter53ApplicationTests.java | 36 - 2.1.x/chapter5-4/.gitignore | 29 - 2.1.x/chapter5-4/pom.xml | 74 - .../chapter54/Chapter54Application.java | 15 - .../java/com/didispace/chapter54/User.java | 27 - .../didispace/chapter54/UserRepository.java | 26 - .../src/main/resources/application.properties | 16 - .../chapter54/Chapter54ApplicationTests.java | 36 - 2.1.x/pom.xml | 60 - 202 files changed, 10105 deletions(-) delete mode 100644 2.1.x/README.md delete mode 100644 2.1.x/README_zh.md delete mode 100644 2.1.x/chapter1-1/.gitignore delete mode 100644 2.1.x/chapter1-1/pom.xml delete mode 100644 2.1.x/chapter1-1/src/main/java/com/didispace/chapter11/Chapter11Application.java delete mode 100644 2.1.x/chapter1-1/src/main/java/com/didispace/chapter11/HelloController.java delete mode 100644 2.1.x/chapter1-1/src/main/resources/application.properties delete mode 100644 2.1.x/chapter1-1/src/test/java/com/didispace/chapter11/Chapter11ApplicationTests.java delete mode 100644 2.1.x/chapter2-1/.gitignore delete mode 100644 2.1.x/chapter2-1/pom.xml delete mode 100644 2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/Chapter21Application.java delete mode 100644 2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/User.java delete mode 100644 2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/UserController.java delete mode 100644 2.1.x/chapter2-1/src/main/resources/application.properties delete mode 100644 2.1.x/chapter2-1/src/test/java/com/didispace/chapter21/Chapter21ApplicationTests.java delete mode 100644 2.1.x/chapter2-2/.gitignore delete mode 100644 2.1.x/chapter2-2/pom.xml delete mode 100644 2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/Chapter22Application.java delete mode 100644 2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/User.java delete mode 100644 2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/UserController.java delete mode 100644 2.1.x/chapter2-2/src/main/resources/application.properties delete mode 100644 2.1.x/chapter2-3/.gitignore delete mode 100644 2.1.x/chapter2-3/pom.xml delete mode 100644 2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/Chapter23Application.java delete mode 100644 2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/User.java delete mode 100644 2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/UserController.java delete mode 100644 2.1.x/chapter2-3/src/main/resources/application.properties delete mode 100644 2.1.x/chapter2-4/.gitignore delete mode 100644 2.1.x/chapter2-4/pom.xml delete mode 100644 2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/Chapter24Application.java delete mode 100644 2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/User.java delete mode 100644 2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/UserController.java delete mode 100644 2.1.x/chapter2-4/src/main/resources/application.properties delete mode 100644 2.1.x/chapter2-5/.gitignore delete mode 100644 2.1.x/chapter2-5/pom.xml delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/definitions.adoc delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/overview.adoc delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/paths.adoc delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/security.adoc delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/generated/definitions.adoc delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/generated/overview.adoc delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/generated/paths.adoc delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/generated/security.adoc delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/html/definitions.html delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/html/overview.html delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/html/paths.html delete mode 100644 2.1.x/chapter2-5/src/docs/asciidoc/html/security.html delete mode 100644 2.1.x/chapter2-5/src/docs/confluence/generated/definitions.txt delete mode 100644 2.1.x/chapter2-5/src/docs/confluence/generated/overview.txt delete mode 100644 2.1.x/chapter2-5/src/docs/confluence/generated/paths.txt delete mode 100644 2.1.x/chapter2-5/src/docs/confluence/generated/security.txt delete mode 100644 2.1.x/chapter2-5/src/docs/markdown/generated/definitions.md delete mode 100644 2.1.x/chapter2-5/src/docs/markdown/generated/overview.md delete mode 100644 2.1.x/chapter2-5/src/docs/markdown/generated/paths.md delete mode 100644 2.1.x/chapter2-5/src/docs/markdown/generated/security.md delete mode 100644 2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/Chapter25Application.java delete mode 100644 2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/User.java delete mode 100644 2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/UserController.java delete mode 100644 2.1.x/chapter2-5/src/main/resources/application.properties delete mode 100644 2.1.x/chapter2-5/src/test/java/com/didispace/chapter25/DemoApplicationTests.java delete mode 100644 2.1.x/chapter2-6/.gitignore delete mode 100644 2.1.x/chapter2-6/pom.xml delete mode 100644 2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/Chapter26Application.java delete mode 100644 2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/User.java delete mode 100644 2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/UserController.java delete mode 100644 2.1.x/chapter2-6/src/main/resources/application.properties delete mode 100644 2.1.x/chapter2-7/.gitignore delete mode 100644 2.1.x/chapter2-7/pom.xml delete mode 100644 2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/Chapter27Application.java delete mode 100644 2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/User.java delete mode 100644 2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/UserController.java delete mode 100644 2.1.x/chapter2-7/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-1/.gitignore delete mode 100644 2.1.x/chapter3-1/pom.xml delete mode 100644 2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/Chapter31Application.java delete mode 100644 2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/User.java delete mode 100644 2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/UserService.java delete mode 100644 2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/UserServiceImpl.java delete mode 100644 2.1.x/chapter3-1/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-1/src/test/java/com/didispace/chapter31/Chapter31ApplicationTests.java delete mode 100644 2.1.x/chapter3-10/.gitignore delete mode 100644 2.1.x/chapter3-10/pom.xml delete mode 100644 2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/Chapter310Application.java delete mode 100644 2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/User.java delete mode 100644 2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/UserRepository.java delete mode 100644 2.1.x/chapter3-10/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-10/src/test/java/com/didispace/chapter310/Chapter310ApplicationTests.java delete mode 100644 2.1.x/chapter3-2/.gitignore delete mode 100644 2.1.x/chapter3-2/pom.xml delete mode 100644 2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/Chapter32Application.java delete mode 100644 2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/User.java delete mode 100644 2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/UserService.java delete mode 100644 2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/UserServiceImpl.java delete mode 100644 2.1.x/chapter3-2/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-2/src/test/java/com/didispace/chapter32/Chapter32ApplicationTests.java delete mode 100644 2.1.x/chapter3-3/.gitignore delete mode 100644 2.1.x/chapter3-3/pom.xml delete mode 100644 2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/Chapter33Application.java delete mode 100644 2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/User.java delete mode 100644 2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserController.java delete mode 100644 2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserService.java delete mode 100644 2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserServiceImpl.java delete mode 100644 2.1.x/chapter3-3/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-3/src/test/java/com/didispace/chapter33/Chapter33ApplicationTests.java delete mode 100644 2.1.x/chapter3-4/.gitignore delete mode 100644 2.1.x/chapter3-4/pom.xml delete mode 100644 2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/Chapter34Application.java delete mode 100644 2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/User.java delete mode 100644 2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/UserRepository.java delete mode 100644 2.1.x/chapter3-4/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-4/src/test/java/com/didispace/chapter34/Chapter34ApplicationTests.java delete mode 100644 2.1.x/chapter3-5/.gitignore delete mode 100644 2.1.x/chapter3-5/pom.xml delete mode 100644 2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/Chapter35Application.java delete mode 100644 2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/User.java delete mode 100644 2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/UserMapper.java delete mode 100644 2.1.x/chapter3-5/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-5/src/test/java/com/didispace/chapter35/Chapter35ApplicationTests.java delete mode 100644 2.1.x/chapter3-6/.gitignore delete mode 100644 2.1.x/chapter3-6/pom.xml delete mode 100644 2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/Chapter36Application.java delete mode 100644 2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/entity/User.java delete mode 100644 2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/mapper/UserMapper.java delete mode 100644 2.1.x/chapter3-6/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-6/src/main/resources/mapper/UserMapper.xml delete mode 100644 2.1.x/chapter3-6/src/test/java/com/didispace/chapter36/Chapter36ApplicationTests.java delete mode 100644 2.1.x/chapter3-7/.gitignore delete mode 100644 2.1.x/chapter3-7/pom.xml delete mode 100644 2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/Chapter37Application.java delete mode 100644 2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/DataSourceConfiguration.java delete mode 100644 2.1.x/chapter3-7/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-7/src/test/java/com/didispace/chapter37/Chapter37ApplicationTests.java delete mode 100644 2.1.x/chapter3-8/.gitignore delete mode 100644 2.1.x/chapter3-8/pom.xml delete mode 100644 2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/Chapter38Application.java delete mode 100644 2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/DataSourceConfiguration.java delete mode 100644 2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/PrimaryConfig.java delete mode 100644 2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/SecondaryConfig.java delete mode 100644 2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/p/User.java delete mode 100644 2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/p/UserRepository.java delete mode 100644 2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/s/Message.java delete mode 100644 2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/s/MessageRepository.java delete mode 100644 2.1.x/chapter3-8/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-8/src/test/java/com/didispace/chapter38/Chapter38ApplicationTests.java delete mode 100644 2.1.x/chapter3-9/.gitignore delete mode 100644 2.1.x/chapter3-9/pom.xml delete mode 100644 2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/Chapter39Application.java delete mode 100644 2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/DataSourceConfiguration.java delete mode 100644 2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/PrimaryConfig.java delete mode 100644 2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/SecondaryConfig.java delete mode 100644 2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/p/entity/UserPrimary.java delete mode 100644 2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/p/mapper/UserMapperPrimary.java delete mode 100644 2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/s/entity/UserSecondary.java delete mode 100644 2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/s/mapper/UserMapperSecondary.java delete mode 100644 2.1.x/chapter3-9/src/main/resources/application.properties delete mode 100644 2.1.x/chapter3-9/src/main/resources/mapper.primary/UserMapper.xml delete mode 100644 2.1.x/chapter3-9/src/main/resources/mapper.secondary/UserMapper.xml delete mode 100644 2.1.x/chapter3-9/src/test/java/com/didispace/chapter39/Chapter39ApplicationTests.java delete mode 100644 2.1.x/chapter4-1/.gitignore delete mode 100644 2.1.x/chapter4-1/pom.xml delete mode 100644 2.1.x/chapter4-1/src/main/java/com/didispace/chapter41/Chapter41Application.java delete mode 100644 2.1.x/chapter4-1/src/main/java/com/didispace/chapter41/HelloController.java delete mode 100644 2.1.x/chapter4-1/src/main/resources/application.properties delete mode 100644 2.1.x/chapter4-1/src/main/resources/templates/index.html delete mode 100644 2.1.x/chapter4-2/.gitignore delete mode 100644 2.1.x/chapter4-2/pom.xml delete mode 100644 2.1.x/chapter4-2/src/main/java/com/didispace/chapter42/Chapter42Application.java delete mode 100644 2.1.x/chapter4-2/src/main/java/com/didispace/chapter42/HelloController.java delete mode 100644 2.1.x/chapter4-2/src/main/resources/application.properties delete mode 100644 2.1.x/chapter4-2/src/main/resources/templates/index.html delete mode 100644 2.1.x/chapter5-1/.gitignore delete mode 100644 2.1.x/chapter5-1/pom.xml delete mode 100644 2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/Chapter51Application.java delete mode 100644 2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/User.java delete mode 100644 2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/UserRepository.java delete mode 100644 2.1.x/chapter5-1/src/main/resources/application.properties delete mode 100644 2.1.x/chapter5-1/src/test/java/com/didispace/chapter51/Chapter51ApplicationTests.java delete mode 100644 2.1.x/chapter5-2/.gitignore delete mode 100644 2.1.x/chapter5-2/pom.xml delete mode 100644 2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/Chapter52Application.java delete mode 100644 2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/User.java delete mode 100644 2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/UserRepository.java delete mode 100644 2.1.x/chapter5-2/src/main/resources/application.properties delete mode 100644 2.1.x/chapter5-2/src/main/resources/ehcache.xml delete mode 100644 2.1.x/chapter5-2/src/test/java/com/didispace/chapter52/Chapter52ApplicationTests.java delete mode 100644 2.1.x/chapter5-3/.gitignore delete mode 100644 2.1.x/chapter5-3/pom.xml delete mode 100644 2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/Chapter53Application.java delete mode 100644 2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/User.java delete mode 100644 2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/UserRepository.java delete mode 100644 2.1.x/chapter5-3/src/main/resources/application.properties delete mode 100644 2.1.x/chapter5-3/src/main/resources/ehcache-1.xml delete mode 100644 2.1.x/chapter5-3/src/main/resources/ehcache-2.xml delete mode 100644 2.1.x/chapter5-3/src/test/java/com/didispace/chapter53/Chapter53ApplicationTests.java delete mode 100644 2.1.x/chapter5-4/.gitignore delete mode 100644 2.1.x/chapter5-4/pom.xml delete mode 100644 2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/Chapter54Application.java delete mode 100644 2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/User.java delete mode 100644 2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/UserRepository.java delete mode 100644 2.1.x/chapter5-4/src/main/resources/application.properties delete mode 100644 2.1.x/chapter5-4/src/test/java/com/didispace/chapter54/Chapter54ApplicationTests.java delete mode 100644 2.1.x/pom.xml diff --git a/2.1.x/README.md b/2.1.x/README.md deleted file mode 100644 index 5f07e37b..00000000 --- a/2.1.x/README.md +++ /dev/null @@ -1,4 +0,0 @@ -该目录下内容已迁移道`2.x`目录,本文件夹不继续维护。 - -- 教程汇总(1.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-1x/) -- 教程汇总(2.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-2x/) diff --git a/2.1.x/README_zh.md b/2.1.x/README_zh.md deleted file mode 100644 index 5f07e37b..00000000 --- a/2.1.x/README_zh.md +++ /dev/null @@ -1,4 +0,0 @@ -该目录下内容已迁移道`2.x`目录,本文件夹不继续维护。 - -- 教程汇总(1.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-1x/) -- 教程汇总(2.x版本):[《Spring Boot基础教程》](https://blog.didispace.com/spring-boot-learning-2x/) diff --git a/2.1.x/chapter1-1/.gitignore b/2.1.x/chapter1-1/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter1-1/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter1-1/pom.xml b/2.1.x/chapter1-1/pom.xml deleted file mode 100644 index d849128d..00000000 --- a/2.1.x/chapter1-1/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - com.didispace - chapter1-1 - 0.0.1-SNAPSHOT - chapter1-1 - Demo project for Spring Boot - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter1-1/src/main/java/com/didispace/chapter11/Chapter11Application.java b/2.1.x/chapter1-1/src/main/java/com/didispace/chapter11/Chapter11Application.java deleted file mode 100644 index 17cd4a7c..00000000 --- a/2.1.x/chapter1-1/src/main/java/com/didispace/chapter11/Chapter11Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter11; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter11Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter11Application.class, args); - } - -} diff --git a/2.1.x/chapter1-1/src/main/java/com/didispace/chapter11/HelloController.java b/2.1.x/chapter1-1/src/main/java/com/didispace/chapter11/HelloController.java deleted file mode 100644 index d19b5ef6..00000000 --- a/2.1.x/chapter1-1/src/main/java/com/didispace/chapter11/HelloController.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.didispace.chapter11; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class HelloController { - - @RequestMapping("/hello") - public String index() { - return "Hello World"; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter1-1/src/main/resources/application.properties b/2.1.x/chapter1-1/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/2.1.x/chapter1-1/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/2.1.x/chapter1-1/src/test/java/com/didispace/chapter11/Chapter11ApplicationTests.java b/2.1.x/chapter1-1/src/test/java/com/didispace/chapter11/Chapter11ApplicationTests.java deleted file mode 100644 index 79cbf107..00000000 --- a/2.1.x/chapter1-1/src/test/java/com/didispace/chapter11/Chapter11ApplicationTests.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.didispace.chapter11; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import static org.hamcrest.Matchers.equalTo; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - - -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter11ApplicationTests { - - private MockMvc mvc; - - @Before - public void setUp() { - mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build(); - } - - @Test - public void getHello() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(equalTo("Hello World"))); - } - -} diff --git a/2.1.x/chapter2-1/.gitignore b/2.1.x/chapter2-1/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter2-1/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter2-1/pom.xml b/2.1.x/chapter2-1/pom.xml deleted file mode 100644 index 8c292e60..00000000 --- a/2.1.x/chapter2-1/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter2-1 - 0.0.1-SNAPSHOT - chapter2-1 - Demo project for Spring Boot - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.projectlombok - lombok - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/Chapter21Application.java b/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/Chapter21Application.java deleted file mode 100644 index 936e8024..00000000 --- a/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/Chapter21Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter21; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter21Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter21Application.class, args); - } - -} diff --git a/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/User.java b/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/User.java deleted file mode 100644 index 1f8749c1..00000000 --- a/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/User.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.didispace.chapter21; - -import lombok.Data; - -@Data -public class User { - - private Long id; - private String name; - private Integer age; - -} \ No newline at end of file diff --git a/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/UserController.java b/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/UserController.java deleted file mode 100644 index c855f1a9..00000000 --- a/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/UserController.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.didispace.chapter21; - -import org.springframework.web.bind.annotation.*; - -import java.util.*; - -@RestController -@RequestMapping(value = "/users") // 通过这里配置使下面的映射都在/users下 -public class UserController { - - // 创建线程安全的Map,模拟users信息的存储 - static Map users = Collections.synchronizedMap(new HashMap()); - - /** - * 处理"/users/"的GET请求,用来获取用户列表 - * - * @return - */ - @GetMapping("/") - public List getUserList() { - // 还可以通过@RequestParam从页面中传递参数来进行查询条件或者翻页信息的传递 - List r = new ArrayList(users.values()); - return r; - } - - /** - * 处理"/users/"的POST请求,用来创建User - * - * @param user - * @return - */ - @PostMapping("/") - public String postUser(@RequestBody User user) { - // @RequestBody注解用来绑定通过http请求中application/json类型上传的数据 - users.put(user.getId(), user); - return "success"; - } - - /** - * 处理"/users/{id}"的GET请求,用来获取url中id值的User信息 - * - * @param id - * @return - */ - @GetMapping("/{id}") - public User getUser(@PathVariable Long id) { - // url中的id可通过@PathVariable绑定到函数的参数中 - return users.get(id); - } - - /** - * 处理"/users/{id}"的PUT请求,用来更新User信息 - * - * @param id - * @param user - * @return - */ - @PutMapping("/{id}") - public String putUser(@PathVariable Long id, @RequestBody User user) { - User u = users.get(id); - u.setName(user.getName()); - u.setAge(user.getAge()); - users.put(id, u); - return "success"; - } - - /** - * 处理"/users/{id}"的DELETE请求,用来删除User - * - * @param id - * @return - */ - @DeleteMapping("/{id}") - public String deleteUser(@PathVariable Long id) { - users.remove(id); - return "success"; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter2-1/src/main/resources/application.properties b/2.1.x/chapter2-1/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/2.1.x/chapter2-1/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/2.1.x/chapter2-1/src/test/java/com/didispace/chapter21/Chapter21ApplicationTests.java b/2.1.x/chapter2-1/src/test/java/com/didispace/chapter21/Chapter21ApplicationTests.java deleted file mode 100644 index 880d2823..00000000 --- a/2.1.x/chapter2-1/src/test/java/com/didispace/chapter21/Chapter21ApplicationTests.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.didispace.chapter21; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import static org.hamcrest.Matchers.equalTo; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - - -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter21ApplicationTests { - - private MockMvc mvc; - - @Before - public void setUp() { - mvc = MockMvcBuilders.standaloneSetup(new UserController()).build(); - } - - @Test - public void testUserController() throws Exception { - // 测试UserController - RequestBuilder request; - - // 1、get查一下user列表,应该为空 - request = get("/users/"); - mvc.perform(request) - .andExpect(status().isOk()) - .andExpect(content().string(equalTo("[]"))); - - // 2、post提交一个user - request = post("/users/") - .contentType(MediaType.APPLICATION_JSON) - .content("{\"id\":1,\"name\":\"测试大师\",\"age\":20}"); - mvc.perform(request) - .andExpect(content().string(equalTo("success"))); - - // 3、get获取user列表,应该有刚才插入的数据 - request = get("/users/"); - mvc.perform(request) - .andExpect(status().isOk()) - .andExpect(content().string(equalTo("[{\"id\":1,\"name\":\"测试大师\",\"age\":20}]"))); - - // 4、put修改id为1的user - request = put("/users/1") - .contentType(MediaType.APPLICATION_JSON) - .content("{\"name\":\"测试终极大师\",\"age\":30}"); - mvc.perform(request) - .andExpect(content().string(equalTo("success"))); - - // 5、get一个id为1的user - request = get("/users/1"); - mvc.perform(request) - .andExpect(content().string(equalTo("{\"id\":1,\"name\":\"测试终极大师\",\"age\":30}"))); - - // 6、del删除id为1的user - request = delete("/users/1"); - mvc.perform(request) - .andExpect(content().string(equalTo("success"))); - - // 7、get查一下user列表,应该为空 - request = get("/users/"); - mvc.perform(request) - .andExpect(status().isOk()) - .andExpect(content().string(equalTo("[]"))); - - } - -} diff --git a/2.1.x/chapter2-2/.gitignore b/2.1.x/chapter2-2/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter2-2/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter2-2/pom.xml b/2.1.x/chapter2-2/pom.xml deleted file mode 100644 index aa373bc4..00000000 --- a/2.1.x/chapter2-2/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter2-2 - 0.0.1-SNAPSHOT - chapter2-2 - Demo project for Spring Boot - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - com.spring4all - swagger-spring-boot-starter - 1.9.0.RELEASE - - - - org.projectlombok - lombok - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/Chapter22Application.java b/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/Chapter22Application.java deleted file mode 100644 index cd6963b8..00000000 --- a/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/Chapter22Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter22; - -import com.spring4all.swagger.EnableSwagger2Doc; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@EnableSwagger2Doc -@SpringBootApplication -public class Chapter22Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter22Application.class, args); - } - -} diff --git a/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/User.java b/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/User.java deleted file mode 100644 index 1a265300..00000000 --- a/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/User.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.didispace.chapter22; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -@Data -@ApiModel(description="用户实体") -public class User { - - @ApiModelProperty("用户编号") - private Long id; - @ApiModelProperty("用户姓名") - private String name; - @ApiModelProperty("用户年龄") - private Integer age; - -} \ No newline at end of file diff --git a/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/UserController.java b/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/UserController.java deleted file mode 100644 index cc517afb..00000000 --- a/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/UserController.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.didispace.chapter22; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - -import java.util.*; - -@Api(tags = "用户管理") -@RestController -@RequestMapping(value = "/users") // 通过这里配置使下面的映射都在/users下 -public class UserController { - - // 创建线程安全的Map,模拟users信息的存储 - static Map users = Collections.synchronizedMap(new HashMap<>()); - - @GetMapping("/") - @ApiOperation(value = "获取用户列表") - public List getUserList() { - List r = new ArrayList<>(users.values()); - return r; - } - - @PostMapping("/") - @ApiOperation(value = "创建用户", notes = "根据User对象创建用户") - public String postUser(@RequestBody User user) { - users.put(user.getId(), user); - return "success"; - } - - @GetMapping("/{id}") - @ApiOperation(value = "获取用户详细信息", notes = "根据url的id来获取用户详细信息") - public User getUser(@PathVariable Long id) { - return users.get(id); - } - - @PutMapping("/{id}") - @ApiImplicitParam(paramType = "path", dataType = "Long", name = "id", value = "用户编号", required = true, example = "1") - @ApiOperation(value = "更新用户详细信息", notes = "根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息") - public String putUser(@PathVariable Long id, @RequestBody User user) { - User u = users.get(id); - u.setName(user.getName()); - u.setAge(user.getAge()); - users.put(id, u); - return "success"; - } - - @DeleteMapping("/{id}") - @ApiOperation(value = "删除用户", notes = "根据url的id来指定删除对象") - public String deleteUser(@PathVariable Long id) { - users.remove(id); - return "success"; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter2-2/src/main/resources/application.properties b/2.1.x/chapter2-2/src/main/resources/application.properties deleted file mode 100644 index 55ec2942..00000000 --- a/2.1.x/chapter2-2/src/main/resources/application.properties +++ /dev/null @@ -1,13 +0,0 @@ - - -swagger.title=spring-boot-starter-swagger -swagger.description=Starter for swagger 2.x -swagger.version=1.9.0.RELEASE -swagger.license=Apache License, Version 2.0 -swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html -swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-swagger -swagger.contact.name=didi -swagger.contact.url=http://blog.didispace.com -swagger.contact.email=dyc87112@qq.com -swagger.base-package=com.didispace -swagger.base-path=/** \ No newline at end of file diff --git a/2.1.x/chapter2-3/.gitignore b/2.1.x/chapter2-3/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter2-3/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter2-3/pom.xml b/2.1.x/chapter2-3/pom.xml deleted file mode 100644 index 284c9d0d..00000000 --- a/2.1.x/chapter2-3/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter2-3 - 0.0.1-SNAPSHOT - chapter2-3 - Demo project for Spring Boot - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - com.spring4all - swagger-spring-boot-starter - 1.9.0.RELEASE - - - - org.projectlombok - lombok - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/Chapter23Application.java b/2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/Chapter23Application.java deleted file mode 100644 index 7ecdd42d..00000000 --- a/2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/Chapter23Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter23; - -import com.spring4all.swagger.EnableSwagger2Doc; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@EnableSwagger2Doc -@SpringBootApplication -public class Chapter23Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter23Application.class, args); - } - -} diff --git a/2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/User.java b/2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/User.java deleted file mode 100644 index 12f85c88..00000000 --- a/2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/User.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.didispace.chapter23; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import javax.validation.constraints.*; - -@Data -@ApiModel(description = "用户实体") -public class User { - - @ApiModelProperty("用户编号") - private Long id; - - @NotNull - @Size(min = 2, max = 5) - @ApiModelProperty("用户姓名") - private String name; - - @NotNull - @Max(100) - @Min(10) - @ApiModelProperty("用户年龄") - private Integer age; - - @NotNull - @Email - @ApiModelProperty("用户邮箱") - private String email; - -} \ No newline at end of file diff --git a/2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/UserController.java b/2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/UserController.java deleted file mode 100644 index 963ac4c4..00000000 --- a/2.1.x/chapter2-3/src/main/java/com/didispace/chapter23/UserController.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.didispace.chapter23; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.*; - -@Api(tags = "用户管理") -@RestController -@RequestMapping(value = "/users") // 通过这里配置使下面的映射都在/users下 -public class UserController { - - // 创建线程安全的Map,模拟users信息的存储 - static Map users = Collections.synchronizedMap(new HashMap<>()); - - @GetMapping("/") - @ApiOperation(value = "获取用户列表") - public List getUserList() { - List r = new ArrayList<>(users.values()); - return r; - } - - @PostMapping("/") - @ApiOperation(value = "创建用户", notes = "根据User对象创建用户") - public String postUser(@Valid @RequestBody User user) { - users.put(user.getId(), user); - return "success"; - } - - @GetMapping("/{id}") - @ApiOperation(value = "获取用户详细信息", notes = "根据url的id来获取用户详细信息") - public User getUser(@PathVariable Long id) { - return users.get(id); - } - - @PutMapping("/{id}") - @ApiImplicitParam(paramType = "path", dataType = "Long", name = "id", value = "用户编号", required = true, example = "1") - @ApiOperation(value = "更新用户详细信息", notes = "根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息") - public String putUser(@PathVariable Long id, @RequestBody User user) { - User u = users.get(id); - u.setName(user.getName()); - u.setAge(user.getAge()); - users.put(id, u); - return "success"; - } - - @DeleteMapping("/{id}") - @ApiOperation(value = "删除用户", notes = "根据url的id来指定删除对象") - public String deleteUser(@PathVariable Long id) { - users.remove(id); - return "success"; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter2-3/src/main/resources/application.properties b/2.1.x/chapter2-3/src/main/resources/application.properties deleted file mode 100644 index 55ec2942..00000000 --- a/2.1.x/chapter2-3/src/main/resources/application.properties +++ /dev/null @@ -1,13 +0,0 @@ - - -swagger.title=spring-boot-starter-swagger -swagger.description=Starter for swagger 2.x -swagger.version=1.9.0.RELEASE -swagger.license=Apache License, Version 2.0 -swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html -swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-swagger -swagger.contact.name=didi -swagger.contact.url=http://blog.didispace.com -swagger.contact.email=dyc87112@qq.com -swagger.base-package=com.didispace -swagger.base-path=/** \ No newline at end of file diff --git a/2.1.x/chapter2-4/.gitignore b/2.1.x/chapter2-4/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter2-4/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter2-4/pom.xml b/2.1.x/chapter2-4/pom.xml deleted file mode 100644 index 8dcad73d..00000000 --- a/2.1.x/chapter2-4/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter2-4 - 0.0.1-SNAPSHOT - chapter2-4 - Demo project for Spring Boot - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - com.spring4all - swagger-spring-boot-starter - 1.9.0.RELEASE - - - - org.projectlombok - lombok - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/Chapter24Application.java b/2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/Chapter24Application.java deleted file mode 100644 index 736bc4f3..00000000 --- a/2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/Chapter24Application.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.didispace.chapter24; - -import com.spring4all.swagger.EnableSwagger2Doc; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.Tag; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.ArrayList; -import java.util.List; - -@EnableSwagger2Doc -@SpringBootApplication -public class Chapter24Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter24Application.class, args); - } - - @Api(tags = {"1-教师管理","3-教学管理"}) - @RestController - @RequestMapping(value = "/teacher") - static class TeacherController { - - @ApiOperation(value = "xxx") - @GetMapping("/xxx") - public String xxx() { - return "xxx"; - } - - } - - @Api(tags = {"2-学生管理"}) - @RestController - @RequestMapping(value = "/student") - static class StudentController { - - @ApiOperation(value = "获取学生清单", tags = "3-教学管理") - @GetMapping("/list") - public String bbb() { - return "bbb"; - } - - @ApiOperation("获取教某个学生的老师清单") - @GetMapping("/his-teachers") - public String ccc() { - return "ccc"; - } - - @ApiOperation("创建一个学生") - @PostMapping("/aaa") - public String aaa() { - return "aaa"; - } - - } - -} diff --git a/2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/User.java b/2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/User.java deleted file mode 100644 index 1d13b648..00000000 --- a/2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/User.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.didispace.chapter24; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import javax.validation.constraints.*; - -@Data -@ApiModel(description = "用户实体") -public class User { - - @ApiModelProperty(value = "用户编号", position = 1) - private Long id; - - @NotNull - @Size(min = 2, max = 5) - @ApiModelProperty(value = "用户姓名", position = 2) - private String name; - - @NotNull - @Max(100) - @Min(10) - @ApiModelProperty(value = "用户年龄", position = 3) - private Integer age; - - @NotNull - @Email - @ApiModelProperty(value = "用户邮箱", position = 4) - private String email; - -} \ No newline at end of file diff --git a/2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/UserController.java b/2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/UserController.java deleted file mode 100644 index 871a2d9b..00000000 --- a/2.1.x/chapter2-4/src/main/java/com/didispace/chapter24/UserController.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.didispace.chapter24; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.*; - -@Api(tags = "用户管理") -@RestController -@RequestMapping(value = "/users") // 通过这里配置使下面的映射都在/users下 -public class UserController { - - // 创建线程安全的Map,模拟users信息的存储 - static Map users = Collections.synchronizedMap(new HashMap<>()); - - @GetMapping("/") - @ApiOperation(value = "获取用户列表") - public List getUserList() { - List r = new ArrayList<>(users.values()); - return r; - } - - @PostMapping("/") - @ApiOperation(value = "创建用户", notes = "根据User对象创建用户") - public String postUser(@Valid @RequestBody User user) { - users.put(user.getId(), user); - return "success"; - } - - @GetMapping("/{id}") - @ApiOperation(value = "获取用户详细信息", notes = "根据url的id来获取用户详细信息") - public User getUser(@PathVariable Long id) { - return users.get(id); - } - - @PutMapping("/{id}") - @ApiImplicitParam(paramType = "path", dataType = "Long", name = "id", value = "用户编号", required = true, example = "1") - @ApiOperation(value = "更新用户详细信息", notes = "根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息") - public String putUser(@PathVariable Long id, @RequestBody User user) { - User u = users.get(id); - u.setName(user.getName()); - u.setAge(user.getAge()); - users.put(id, u); - return "success"; - } - - @DeleteMapping("/{id}") - @ApiOperation(value = "删除用户", notes = "根据url的id来指定删除对象") - public String deleteUser(@PathVariable Long id) { - users.remove(id); - return "success"; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter2-4/src/main/resources/application.properties b/2.1.x/chapter2-4/src/main/resources/application.properties deleted file mode 100644 index 335a5f4b..00000000 --- a/2.1.x/chapter2-4/src/main/resources/application.properties +++ /dev/null @@ -1,16 +0,0 @@ - - -swagger.title=spring-boot-starter-swagger -swagger.description=Starter for swagger 2.x -swagger.version=1.9.0.RELEASE -swagger.license=Apache License, Version 2.0 -swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html -swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-swagger -swagger.contact.name=didi -swagger.contact.url=http://blog.didispace.com -swagger.contact.email=dyc87112@qq.com -swagger.base-package=com.didispace -swagger.base-path=/** - -swagger.ui-config.tags-sorter=alpha -swagger.ui-config.operations-sorter=alpha \ No newline at end of file diff --git a/2.1.x/chapter2-5/.gitignore b/2.1.x/chapter2-5/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter2-5/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter2-5/pom.xml b/2.1.x/chapter2-5/pom.xml deleted file mode 100644 index 9ffaafe8..00000000 --- a/2.1.x/chapter2-5/pom.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter2-5 - 0.0.1-SNAPSHOT - chapter2-5 - Demo project for Spring Boot - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - com.spring4all - swagger-spring-boot-starter - 1.9.0.RELEASE - - - - org.projectlombok - lombok - - - - org.springframework.boot - spring-boot-starter-test - test - - - - io.github.swagger2markup - swagger2markup - 1.3.3 - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - io.github.swagger2markup - swagger2markup-maven-plugin - 1.3.3 - - http://localhost:8080/v2/api-docs - src/docs/asciidoc/generated-by-plugin - - ASCIIDOC - - - - - - org.asciidoctor - asciidoctor-maven-plugin - 1.5.6 - - src/docs/asciidoc/generated - src/docs/asciidoc/html - html - coderay - - left - - - - - - - - - - false - - jcenter-releases - jcenter - http://jcenter.bintray.com - - - - diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/definitions.adoc b/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/definitions.adoc deleted file mode 100644 index 3a20e7fb..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/definitions.adoc +++ /dev/null @@ -1,22 +0,0 @@ - -[[_definitions]] -== Definitions - -[[_user]] -=== User -用户实体 - - -[options="header", cols=".^3,.^11,.^4"] -|=== -|Name|Description|Schema -|**age** + -__optional__|用户年龄|integer (int32) -|**id** + -__optional__|用户编号|integer (int64) -|**name** + -__optional__|用户姓名|string -|=== - - - diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/overview.adoc b/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/overview.adoc deleted file mode 100644 index 4b9eefbf..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/overview.adoc +++ /dev/null @@ -1,38 +0,0 @@ -= spring-boot-starter-swagger - - -[[_overview]] -== Overview -Starter for swagger 2.x - - -=== Version information -[%hardbreaks] -__Version__ : 1.9.0.RELEASE - - -=== Contact information -[%hardbreaks] -__Contact__ : didi -__Contact Email__ : dyc87112@qq.com - - -=== License information -[%hardbreaks] -__License__ : Apache License, Version 2.0 -__License URL__ : https://www.apache.org/licenses/LICENSE-2.0.html -__Terms of service__ : https://github.com/dyc87112/spring-boot-starter-swagger - - -=== URI scheme -[%hardbreaks] -__Host__ : localhost:8080 -__BasePath__ : / - - -=== Tags - -* 用户管理 : User Controller - - - diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/paths.adoc b/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/paths.adoc deleted file mode 100644 index 5e9cf92f..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/paths.adoc +++ /dev/null @@ -1,265 +0,0 @@ - -[[_paths]] -== Paths - -[[_postuserusingpost]] -=== 创建用户 -.... -POST /users/ -.... - - -==== Description -根据User对象创建用户 - - -==== Parameters - -[options="header", cols=".^2,.^3,.^9,.^4"] -|=== -|Type|Name|Description|Schema -|**Body**|**user** + -__required__|user|<<_user,User>> -|=== - - -==== Responses - -[options="header", cols=".^2,.^14,.^4"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|string -|**201**|Created|No Content -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|**404**|Not Found|No Content -|=== - - -==== Consumes - -* `application/json` - - -==== Produces - -* `*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3,.^4,.^13"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - -[[_getuserlistusingget]] -=== 获取用户列表 -.... -GET /users/ -.... - - -==== Responses - -[options="header", cols=".^2,.^14,.^4"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|< <<_user,User>> > array -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|**404**|Not Found|No Content -|=== - - -==== Produces - -* `*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3,.^4,.^13"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - -[[_getuserusingget]] -=== 获取用户详细信息 -.... -GET /users/{id} -.... - - -==== Description -根据url的id来获取用户详细信息 - - -==== Parameters - -[options="header", cols=".^2,.^3,.^9,.^4"] -|=== -|Type|Name|Description|Schema -|**Path**|**id** + -__required__|id|integer (int64) -|=== - - -==== Responses - -[options="header", cols=".^2,.^14,.^4"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|<<_user,User>> -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|**404**|Not Found|No Content -|=== - - -==== Produces - -* `*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3,.^4,.^13"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - -[[_putuserusingput]] -=== 更新用户详细信息 -.... -PUT /users/{id} -.... - - -==== Description -根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息 - - -==== Parameters - -[options="header", cols=".^2,.^3,.^9,.^4"] -|=== -|Type|Name|Description|Schema -|**Path**|**id** + -__required__|用户编号|integer (int64) -|**Body**|**user** + -__required__|user|<<_user,User>> -|=== - - -==== Responses - -[options="header", cols=".^2,.^14,.^4"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|string -|**201**|Created|No Content -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|**404**|Not Found|No Content -|=== - - -==== Consumes - -* `application/json` - - -==== Produces - -* `*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3,.^4,.^13"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - -[[_deleteuserusingdelete]] -=== 删除用户 -.... -DELETE /users/{id} -.... - - -==== Description -根据url的id来指定删除对象 - - -==== Parameters - -[options="header", cols=".^2,.^3,.^9,.^4"] -|=== -|Type|Name|Description|Schema -|**Path**|**id** + -__required__|id|integer (int64) -|=== - - -==== Responses - -[options="header", cols=".^2,.^14,.^4"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|string -|**204**|No Content|No Content -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|=== - - -==== Produces - -* `*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3,.^4,.^13"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - - diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/security.adoc b/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/security.adoc deleted file mode 100644 index 01db83a5..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/generated-by-plugin/security.adoc +++ /dev/null @@ -1,13 +0,0 @@ - -[[_securityscheme]] -== Security - -[[_authorization]] -=== Authorization -[%hardbreaks] -__Type__ : apiKey -__Name__ : TOKEN -__In__ : HEADER - - - diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/generated/definitions.adoc b/2.1.x/chapter2-5/src/docs/asciidoc/generated/definitions.adoc deleted file mode 100644 index a739bda5..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/generated/definitions.adoc +++ /dev/null @@ -1,22 +0,0 @@ - -[[_definitions]] -== Definitions - -[[_user]] -=== User -用户实体 - - -[options="header", cols=".^3a,.^11a,.^4a"] -|=== -|Name|Description|Schema -|**age** + -__optional__|用户年龄|integer (int32) -|**id** + -__optional__|用户编号|integer (int64) -|**name** + -__optional__|用户姓名|string -|=== - - - diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/generated/overview.adoc b/2.1.x/chapter2-5/src/docs/asciidoc/generated/overview.adoc deleted file mode 100644 index 4b9eefbf..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/generated/overview.adoc +++ /dev/null @@ -1,38 +0,0 @@ -= spring-boot-starter-swagger - - -[[_overview]] -== Overview -Starter for swagger 2.x - - -=== Version information -[%hardbreaks] -__Version__ : 1.9.0.RELEASE - - -=== Contact information -[%hardbreaks] -__Contact__ : didi -__Contact Email__ : dyc87112@qq.com - - -=== License information -[%hardbreaks] -__License__ : Apache License, Version 2.0 -__License URL__ : https://www.apache.org/licenses/LICENSE-2.0.html -__Terms of service__ : https://github.com/dyc87112/spring-boot-starter-swagger - - -=== URI scheme -[%hardbreaks] -__Host__ : localhost:8080 -__BasePath__ : / - - -=== Tags - -* 用户管理 : User Controller - - - diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/generated/paths.adoc b/2.1.x/chapter2-5/src/docs/asciidoc/generated/paths.adoc deleted file mode 100644 index 6fa4471d..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/generated/paths.adoc +++ /dev/null @@ -1,265 +0,0 @@ - -[[_paths]] -== Paths - -[[_postuserusingpost]] -=== 创建用户 -.... -POST /users/ -.... - - -==== Description -根据User对象创建用户 - - -==== Parameters - -[options="header", cols=".^2a,.^3a,.^9a,.^4a"] -|=== -|Type|Name|Description|Schema -|**Body**|**user** + -__required__|user|<<_user,User>> -|=== - - -==== Responses - -[options="header", cols=".^2a,.^14a,.^4a"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|string -|**201**|Created|No Content -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|**404**|Not Found|No Content -|=== - - -==== Consumes - -* `application/json` - - -==== Produces - -* `\*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3a,.^4a,.^13a"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - -[[_getuserlistusingget]] -=== 获取用户列表 -.... -GET /users/ -.... - - -==== Responses - -[options="header", cols=".^2a,.^14a,.^4a"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|< <<_user,User>> > array -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|**404**|Not Found|No Content -|=== - - -==== Produces - -* `\*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3a,.^4a,.^13a"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - -[[_getuserusingget]] -=== 获取用户详细信息 -.... -GET /users/{id} -.... - - -==== Description -根据url的id来获取用户详细信息 - - -==== Parameters - -[options="header", cols=".^2a,.^3a,.^9a,.^4a"] -|=== -|Type|Name|Description|Schema -|**Path**|**id** + -__required__|id|integer (int64) -|=== - - -==== Responses - -[options="header", cols=".^2a,.^14a,.^4a"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|<<_user,User>> -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|**404**|Not Found|No Content -|=== - - -==== Produces - -* `\*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3a,.^4a,.^13a"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - -[[_putuserusingput]] -=== 更新用户详细信息 -.... -PUT /users/{id} -.... - - -==== Description -根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息 - - -==== Parameters - -[options="header", cols=".^2a,.^3a,.^9a,.^4a"] -|=== -|Type|Name|Description|Schema -|**Path**|**id** + -__required__|用户编号|integer (int64) -|**Body**|**user** + -__required__|user|<<_user,User>> -|=== - - -==== Responses - -[options="header", cols=".^2a,.^14a,.^4a"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|string -|**201**|Created|No Content -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|**404**|Not Found|No Content -|=== - - -==== Consumes - -* `application/json` - - -==== Produces - -* `\*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3a,.^4a,.^13a"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - -[[_deleteuserusingdelete]] -=== 删除用户 -.... -DELETE /users/{id} -.... - - -==== Description -根据url的id来指定删除对象 - - -==== Parameters - -[options="header", cols=".^2a,.^3a,.^9a,.^4a"] -|=== -|Type|Name|Description|Schema -|**Path**|**id** + -__required__|id|integer (int64) -|=== - - -==== Responses - -[options="header", cols=".^2a,.^14a,.^4a"] -|=== -|HTTP Code|Description|Schema -|**200**|OK|string -|**204**|No Content|No Content -|**401**|Unauthorized|No Content -|**403**|Forbidden|No Content -|=== - - -==== Produces - -* `\*/*` - - -==== Tags - -* 用户管理 - - -==== Security - -[options="header", cols=".^3a,.^4a,.^13a"] -|=== -|Type|Name|Scopes -|**apiKey**|**<<_authorization,Authorization>>**|global -|=== - - - diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/generated/security.adoc b/2.1.x/chapter2-5/src/docs/asciidoc/generated/security.adoc deleted file mode 100644 index 01db83a5..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/generated/security.adoc +++ /dev/null @@ -1,13 +0,0 @@ - -[[_securityscheme]] -== Security - -[[_authorization]] -=== Authorization -[%hardbreaks] -__Type__ : apiKey -__Name__ : TOKEN -__In__ : HEADER - - - diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/html/definitions.html b/2.1.x/chapter2-5/src/docs/asciidoc/html/definitions.html deleted file mode 100644 index 1a9a17f8..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/html/definitions.html +++ /dev/null @@ -1,603 +0,0 @@ - - - - - - - -Definitions - - - - - - -
-
-

Definitions

-
-
-

User

-
-

用户实体

-
- ----- - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescriptionSchema
-

age
-optional

-
-

用户年龄

-
-

integer (int32)

-
-

id
-optional

-
-

用户编号

-
-

integer (int64)

-
-

name
-optional

-
-

用户姓名

-
-

string

-
-
-
-
-
- - - \ No newline at end of file diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/html/overview.html b/2.1.x/chapter2-5/src/docs/asciidoc/html/overview.html deleted file mode 100644 index 842077bb..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/html/overview.html +++ /dev/null @@ -1,591 +0,0 @@ - - - - - - - -spring-boot-starter-swagger - - - - - - -
-
-

Overview

-
-
-

Starter for swagger 2.x

-
-
-

Version information

-
-

Version : 1.9.0.RELEASE

-
-
-
-

Contact information

-
-

Contact : didi
-Contact Email : dyc87112@qq.com

-
-
-
-

License information

-
-

License : Apache License, Version 2.0
-License URL : https://www.apache.org/licenses/LICENSE-2.0.html
-Terms of service : https://github.com/dyc87112/spring-boot-starter-swagger

-
-
-
-

URI scheme

-
-

Host : localhost:8080
-BasePath : /

-
-
-
-

Tags

-
-
    -
  • -

    用户管理 : User Controller

    -
  • -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/html/paths.html b/2.1.x/chapter2-5/src/docs/asciidoc/html/paths.html deleted file mode 100644 index 4b3d92d4..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/html/paths.html +++ /dev/null @@ -1,1379 +0,0 @@ - - - - - - - -Paths - - - - - - -
-
-

Paths

-
-
-

创建用户

-
-
-
POST /users/
-
-
-
-

Description

-
-

根据User对象创建用户

-
-
-
-

Parameters

- ------ - - - - - - - - - - - - - - - - -
TypeNameDescriptionSchema
-

Body

-
-

user
-required

-
-

user

-
-

User

-
-
-
-

Responses

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HTTP CodeDescriptionSchema
-

200

-
-

OK

-
-

string

-
-

201

-
-

Created

-
-

No Content

-
-

401

-
-

Unauthorized

-
-

No Content

-
-

403

-
-

Forbidden

-
-

No Content

-
-

404

-
-

Not Found

-
-

No Content

-
-
-
-

Consumes

-
-
    -
  • -

    application/json

    -
  • -
-
-
-
-

Produces

-
-
    -
  • -

    */*

    -
  • -
-
-
-
-

Tags

-
-
    -
  • -

    用户管理

    -
  • -
-
-
-
-

Security

- ----- - - - - - - - - - - - - - - -
TypeNameScopes
-

apiKey

-
-

global

-
-
-
-
-

获取用户列表

-
-
-
GET /users/
-
-
-
-

Responses

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HTTP CodeDescriptionSchema
-

200

-
-

OK

-
-

< User > array

-
-

401

-
-

Unauthorized

-
-

No Content

-
-

403

-
-

Forbidden

-
-

No Content

-
-

404

-
-

Not Found

-
-

No Content

-
-
-
-

Produces

-
-
    -
  • -

    */*

    -
  • -
-
-
-
-

Tags

-
-
    -
  • -

    用户管理

    -
  • -
-
-
-
-

Security

- ----- - - - - - - - - - - - - - - -
TypeNameScopes
-

apiKey

-
-

global

-
-
-
-
-

获取用户详细信息

-
-
-
GET /users/{id}
-
-
-
-

Description

-
-

根据url的id来获取用户详细信息

-
-
-
-

Parameters

- ------ - - - - - - - - - - - - - - - - -
TypeNameDescriptionSchema
-

Path

-
-

id
-required

-
-

id

-
-

integer (int64)

-
-
-
-

Responses

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HTTP CodeDescriptionSchema
-

200

-
-

OK

-
-

User

-
-

401

-
-

Unauthorized

-
-

No Content

-
-

403

-
-

Forbidden

-
-

No Content

-
-

404

-
-

Not Found

-
-

No Content

-
-
-
-

Produces

-
-
    -
  • -

    */*

    -
  • -
-
-
-
-

Tags

-
-
    -
  • -

    用户管理

    -
  • -
-
-
-
-

Security

- ----- - - - - - - - - - - - - - - -
TypeNameScopes
-

apiKey

-
-

global

-
-
-
-
-

更新用户详细信息

-
-
-
PUT /users/{id}
-
-
-
-

Description

-
-

根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息

-
-
-
-

Parameters

- ------ - - - - - - - - - - - - - - - - - - - - - - -
TypeNameDescriptionSchema
-

Path

-
-

id
-required

-
-

用户编号

-
-

integer (int64)

-
-

Body

-
-

user
-required

-
-

user

-
-

User

-
-
-
-

Responses

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HTTP CodeDescriptionSchema
-

200

-
-

OK

-
-

string

-
-

201

-
-

Created

-
-

No Content

-
-

401

-
-

Unauthorized

-
-

No Content

-
-

403

-
-

Forbidden

-
-

No Content

-
-

404

-
-

Not Found

-
-

No Content

-
-
-
-

Consumes

-
-
    -
  • -

    application/json

    -
  • -
-
-
-
-

Produces

-
-
    -
  • -

    */*

    -
  • -
-
-
-
-

Tags

-
-
    -
  • -

    用户管理

    -
  • -
-
-
-
-

Security

- ----- - - - - - - - - - - - - - - -
TypeNameScopes
-

apiKey

-
-

global

-
-
-
-
-

删除用户

-
-
-
DELETE /users/{id}
-
-
-
-

Description

-
-

根据url的id来指定删除对象

-
-
-
-

Parameters

- ------ - - - - - - - - - - - - - - - - -
TypeNameDescriptionSchema
-

Path

-
-

id
-required

-
-

id

-
-

integer (int64)

-
-
-
-

Responses

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HTTP CodeDescriptionSchema
-

200

-
-

OK

-
-

string

-
-

204

-
-

No Content

-
-

No Content

-
-

401

-
-

Unauthorized

-
-

No Content

-
-

403

-
-

Forbidden

-
-

No Content

-
-
-
-

Produces

-
-
    -
  • -

    */*

    -
  • -
-
-
-
-

Tags

-
-
    -
  • -

    用户管理

    -
  • -
-
-
-
-

Security

- ----- - - - - - - - - - - - - - - -
TypeNameScopes
-

apiKey

-
-

global

-
-
-
-
-
-
- - - \ No newline at end of file diff --git a/2.1.x/chapter2-5/src/docs/asciidoc/html/security.html b/2.1.x/chapter2-5/src/docs/asciidoc/html/security.html deleted file mode 100644 index 34676fab..00000000 --- a/2.1.x/chapter2-5/src/docs/asciidoc/html/security.html +++ /dev/null @@ -1,553 +0,0 @@ - - - - - - - -Security - - - - - - -
-
-

Security

-
-
-

Authorization

-
-

Type : apiKey
-Name : TOKEN
-In : HEADER

-
-
-
-
-
- - - \ No newline at end of file diff --git a/2.1.x/chapter2-5/src/docs/confluence/generated/definitions.txt b/2.1.x/chapter2-5/src/docs/confluence/generated/definitions.txt deleted file mode 100644 index 6792429a..00000000 --- a/2.1.x/chapter2-5/src/docs/confluence/generated/definitions.txt +++ /dev/null @@ -1,14 +0,0 @@ - -h2. Definitions {anchor:definitions} - -h3. User {anchor:user} -用户实体 - - -||Name||Description||Schema|| -|*age*\\ \\ _optional_||用户年龄||integer (int32)| -|*id*\\ \\ _optional_||用户编号||integer (int64)| -|*name*\\ \\ _optional_||用户姓名||string| - - - diff --git a/2.1.x/chapter2-5/src/docs/confluence/generated/overview.txt b/2.1.x/chapter2-5/src/docs/confluence/generated/overview.txt deleted file mode 100644 index af12d61b..00000000 --- a/2.1.x/chapter2-5/src/docs/confluence/generated/overview.txt +++ /dev/null @@ -1,33 +0,0 @@ -h1. spring-boot-starter-swagger - - -h2. Overview {anchor:overview} -Starter for swagger 2.x - - -h3. Version information -_Version_ : 1.9.0.RELEASE - - -h3. Contact information -_Contact_ : didi\\ -_Contact Email_ : dyc87112@qq.com - - -h3. License information -_License_ : Apache License, Version 2.0\\ -_License URL_ : https://www.apache.org/licenses/LICENSE-2.0.html\\ -_Terms of service_ : https://github.com/dyc87112/spring-boot-starter-swagger - - -h3. URI scheme -_Host_ : localhost:8080\\ -_BasePath_ : / - - -h3. Tags - -* 用户管理 : User Controller - - - diff --git a/2.1.x/chapter2-5/src/docs/confluence/generated/paths.txt b/2.1.x/chapter2-5/src/docs/confluence/generated/paths.txt deleted file mode 100644 index 5b169e5d..00000000 --- a/2.1.x/chapter2-5/src/docs/confluence/generated/paths.txt +++ /dev/null @@ -1,212 +0,0 @@ - -h2. Paths {anchor:paths} - -h3. 创建用户 {anchor:postuserusingpost} -{noformat} -POST /users/ -{noformat} - - -h4. Description -根据User对象创建用户 - - -h4. Parameters - -||Type||Name||Description||Schema|| -|*Body*|*user*\\ \\ _required_||user||[User|#user]| - - -h4. Responses - -||HTTP Code||Description||Schema|| -|*200*||OK||string| -|*201*||Created||No Content| -|*401*||Unauthorized||No Content| -|*403*||Forbidden||No Content| -|*404*||Not Found||No Content| - - -h4. Consumes - -* {noformat}application/json{noformat} - - -h4. Produces - -* {noformat}\*/*{noformat} - - -h4. Tags - -* 用户管理 - - -h4. Security - -||Type||Name||Scopes|| -|*apiKey*|*[Authorization|#authorization]*||global| - - -h3. 获取用户列表 {anchor:getuserlistusingget} -{noformat} -GET /users/ -{noformat} - - -h4. Responses - -||HTTP Code||Description||Schema|| -|*200*||OK||< [User|#user] > array| -|*401*||Unauthorized||No Content| -|*403*||Forbidden||No Content| -|*404*||Not Found||No Content| - - -h4. Produces - -* {noformat}\*/*{noformat} - - -h4. Tags - -* 用户管理 - - -h4. Security - -||Type||Name||Scopes|| -|*apiKey*|*[Authorization|#authorization]*||global| - - -h3. 获取用户详细信息 {anchor:getuserusingget} -{noformat} -GET /users/{id} -{noformat} - - -h4. Description -根据url的id来获取用户详细信息 - - -h4. Parameters - -||Type||Name||Description||Schema|| -|*Path*|*id*\\ \\ _required_||id||integer (int64)| - - -h4. Responses - -||HTTP Code||Description||Schema|| -|*200*||OK||[User|#user]| -|*401*||Unauthorized||No Content| -|*403*||Forbidden||No Content| -|*404*||Not Found||No Content| - - -h4. Produces - -* {noformat}\*/*{noformat} - - -h4. Tags - -* 用户管理 - - -h4. Security - -||Type||Name||Scopes|| -|*apiKey*|*[Authorization|#authorization]*||global| - - -h3. 更新用户详细信息 {anchor:putuserusingput} -{noformat} -PUT /users/{id} -{noformat} - - -h4. Description -根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息 - - -h4. Parameters - -||Type||Name||Description||Schema|| -|*Path*|*id*\\ \\ _required_||用户编号||integer (int64)| -|*Body*|*user*\\ \\ _required_||user||[User|#user]| - - -h4. Responses - -||HTTP Code||Description||Schema|| -|*200*||OK||string| -|*201*||Created||No Content| -|*401*||Unauthorized||No Content| -|*403*||Forbidden||No Content| -|*404*||Not Found||No Content| - - -h4. Consumes - -* {noformat}application/json{noformat} - - -h4. Produces - -* {noformat}\*/*{noformat} - - -h4. Tags - -* 用户管理 - - -h4. Security - -||Type||Name||Scopes|| -|*apiKey*|*[Authorization|#authorization]*||global| - - -h3. 删除用户 {anchor:deleteuserusingdelete} -{noformat} -DELETE /users/{id} -{noformat} - - -h4. Description -根据url的id来指定删除对象 - - -h4. Parameters - -||Type||Name||Description||Schema|| -|*Path*|*id*\\ \\ _required_||id||integer (int64)| - - -h4. Responses - -||HTTP Code||Description||Schema|| -|*200*||OK||string| -|*204*||No Content||No Content| -|*401*||Unauthorized||No Content| -|*403*||Forbidden||No Content| - - -h4. Produces - -* {noformat}\*/*{noformat} - - -h4. Tags - -* 用户管理 - - -h4. Security - -||Type||Name||Scopes|| -|*apiKey*|*[Authorization|#authorization]*||global| - - - diff --git a/2.1.x/chapter2-5/src/docs/confluence/generated/security.txt b/2.1.x/chapter2-5/src/docs/confluence/generated/security.txt deleted file mode 100644 index 7594f1b5..00000000 --- a/2.1.x/chapter2-5/src/docs/confluence/generated/security.txt +++ /dev/null @@ -1,10 +0,0 @@ - -h2. Security {anchor:securityscheme} - -h3. Authorization {anchor:authorization} -_Type_ : apiKey\\ -_Name_ : TOKEN\\ -_In_ : HEADER - - - diff --git a/2.1.x/chapter2-5/src/docs/markdown/generated/definitions.md b/2.1.x/chapter2-5/src/docs/markdown/generated/definitions.md deleted file mode 100644 index 4eaff931..00000000 --- a/2.1.x/chapter2-5/src/docs/markdown/generated/definitions.md +++ /dev/null @@ -1,17 +0,0 @@ - - -## Definitions - - -### User -用户实体 - - -|Name|Description|Schema| -|---|---|---| -|**age**
*optional*|用户年龄|integer (int32)| -|**id**
*optional*|用户编号|integer (int64)| -|**name**
*optional*|用户姓名|string| - - - diff --git a/2.1.x/chapter2-5/src/docs/markdown/generated/overview.md b/2.1.x/chapter2-5/src/docs/markdown/generated/overview.md deleted file mode 100644 index d360d5a8..00000000 --- a/2.1.x/chapter2-5/src/docs/markdown/generated/overview.md +++ /dev/null @@ -1,34 +0,0 @@ -# spring-boot-starter-swagger - - - -## Overview -Starter for swagger 2.x - - -### Version information -*Version* : 1.9.0.RELEASE - - -### Contact information -*Contact* : didi -*Contact Email* : dyc87112@qq.com - - -### License information -*License* : Apache License, Version 2.0 -*License URL* : https://www.apache.org/licenses/LICENSE-2.0.html -*Terms of service* : https://github.com/dyc87112/spring-boot-starter-swagger - - -### URI scheme -*Host* : localhost:8080 -*BasePath* : / - - -### Tags - -* 用户管理 : User Controller - - - diff --git a/2.1.x/chapter2-5/src/docs/markdown/generated/paths.md b/2.1.x/chapter2-5/src/docs/markdown/generated/paths.md deleted file mode 100644 index d056676a..00000000 --- a/2.1.x/chapter2-5/src/docs/markdown/generated/paths.md +++ /dev/null @@ -1,232 +0,0 @@ - - -## Paths - - -### 创建用户 -``` -POST /users/ -``` - - -#### Description -根据User对象创建用户 - - -#### Parameters - -|Type|Name|Description|Schema| -|---|---|---|---| -|**Body**|**user**
*required*|user|[User](#user)| - - -#### Responses - -|HTTP Code|Description|Schema| -|---|---|---| -|**200**|OK|string| -|**201**|Created|No Content| -|**401**|Unauthorized|No Content| -|**403**|Forbidden|No Content| -|**404**|Not Found|No Content| - - -#### Consumes - -* `application/json` - - -#### Produces - -* `\*/*` - - -#### Tags - -* 用户管理 - - -#### Security - -|Type|Name|Scopes| -|---|---|---| -|**apiKey**|**[Authorization](#authorization)**|global| - - - -### 获取用户列表 -``` -GET /users/ -``` - - -#### Responses - -|HTTP Code|Description|Schema| -|---|---|---| -|**200**|OK|< [User](#user) > array| -|**401**|Unauthorized|No Content| -|**403**|Forbidden|No Content| -|**404**|Not Found|No Content| - - -#### Produces - -* `\*/*` - - -#### Tags - -* 用户管理 - - -#### Security - -|Type|Name|Scopes| -|---|---|---| -|**apiKey**|**[Authorization](#authorization)**|global| - - - -### 获取用户详细信息 -``` -GET /users/{id} -``` - - -#### Description -根据url的id来获取用户详细信息 - - -#### Parameters - -|Type|Name|Description|Schema| -|---|---|---|---| -|**Path**|**id**
*required*|id|integer (int64)| - - -#### Responses - -|HTTP Code|Description|Schema| -|---|---|---| -|**200**|OK|[User](#user)| -|**401**|Unauthorized|No Content| -|**403**|Forbidden|No Content| -|**404**|Not Found|No Content| - - -#### Produces - -* `\*/*` - - -#### Tags - -* 用户管理 - - -#### Security - -|Type|Name|Scopes| -|---|---|---| -|**apiKey**|**[Authorization](#authorization)**|global| - - - -### 更新用户详细信息 -``` -PUT /users/{id} -``` - - -#### Description -根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息 - - -#### Parameters - -|Type|Name|Description|Schema| -|---|---|---|---| -|**Path**|**id**
*required*|用户编号|integer (int64)| -|**Body**|**user**
*required*|user|[User](#user)| - - -#### Responses - -|HTTP Code|Description|Schema| -|---|---|---| -|**200**|OK|string| -|**201**|Created|No Content| -|**401**|Unauthorized|No Content| -|**403**|Forbidden|No Content| -|**404**|Not Found|No Content| - - -#### Consumes - -* `application/json` - - -#### Produces - -* `\*/*` - - -#### Tags - -* 用户管理 - - -#### Security - -|Type|Name|Scopes| -|---|---|---| -|**apiKey**|**[Authorization](#authorization)**|global| - - - -### 删除用户 -``` -DELETE /users/{id} -``` - - -#### Description -根据url的id来指定删除对象 - - -#### Parameters - -|Type|Name|Description|Schema| -|---|---|---|---| -|**Path**|**id**
*required*|id|integer (int64)| - - -#### Responses - -|HTTP Code|Description|Schema| -|---|---|---| -|**200**|OK|string| -|**204**|No Content|No Content| -|**401**|Unauthorized|No Content| -|**403**|Forbidden|No Content| - - -#### Produces - -* `\*/*` - - -#### Tags - -* 用户管理 - - -#### Security - -|Type|Name|Scopes| -|---|---|---| -|**apiKey**|**[Authorization](#authorization)**|global| - - - diff --git a/2.1.x/chapter2-5/src/docs/markdown/generated/security.md b/2.1.x/chapter2-5/src/docs/markdown/generated/security.md deleted file mode 100644 index 09ee31c4..00000000 --- a/2.1.x/chapter2-5/src/docs/markdown/generated/security.md +++ /dev/null @@ -1,12 +0,0 @@ - - -## Security - - -### Authorization -*Type* : apiKey -*Name* : TOKEN -*In* : HEADER - - - diff --git a/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/Chapter25Application.java b/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/Chapter25Application.java deleted file mode 100644 index b8c92652..00000000 --- a/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/Chapter25Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter25; - -import com.spring4all.swagger.EnableSwagger2Doc; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@EnableSwagger2Doc -@SpringBootApplication -public class Chapter25Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter25Application.class, args); - } - -} diff --git a/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/User.java b/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/User.java deleted file mode 100644 index d929259d..00000000 --- a/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/User.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.didispace.chapter25; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -@Data -@ApiModel(description="用户实体") -public class User { - - @ApiModelProperty("用户编号") - private Long id; - @ApiModelProperty("用户姓名") - private String name; - @ApiModelProperty("用户年龄") - private Integer age; - -} \ No newline at end of file diff --git a/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/UserController.java b/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/UserController.java deleted file mode 100644 index ac333420..00000000 --- a/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/UserController.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.didispace.chapter25; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - -import java.util.*; - -@Api(tags = "用户管理") -@RestController -@RequestMapping(value = "/users") // 通过这里配置使下面的映射都在/users下 -public class UserController { - - // 创建线程安全的Map,模拟users信息的存储 - static Map users = Collections.synchronizedMap(new HashMap<>()); - - @GetMapping("/") - @ApiOperation(value = "获取用户列表") - public List getUserList() { - List r = new ArrayList<>(users.values()); - return r; - } - - @PostMapping("/") - @ApiOperation(value = "创建用户", notes = "根据User对象创建用户") - public String postUser(@RequestBody User user) { - users.put(user.getId(), user); - return "success"; - } - - @GetMapping("/{id}") - @ApiOperation(value = "获取用户详细信息", notes = "根据url的id来获取用户详细信息") - public User getUser(@PathVariable Long id) { - return users.get(id); - } - - @PutMapping("/{id}") - @ApiImplicitParam(paramType = "path", dataType = "Long", name = "id", value = "用户编号", required = true, example = "1") - @ApiOperation(value = "更新用户详细信息", notes = "根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息") - public String putUser(@PathVariable Long id, @RequestBody User user) { - User u = users.get(id); - u.setName(user.getName()); - u.setAge(user.getAge()); - users.put(id, u); - return "success"; - } - - @DeleteMapping("/{id}") - @ApiOperation(value = "删除用户", notes = "根据url的id来指定删除对象") - public String deleteUser(@PathVariable Long id) { - users.remove(id); - return "success"; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter2-5/src/main/resources/application.properties b/2.1.x/chapter2-5/src/main/resources/application.properties deleted file mode 100644 index 55ec2942..00000000 --- a/2.1.x/chapter2-5/src/main/resources/application.properties +++ /dev/null @@ -1,13 +0,0 @@ - - -swagger.title=spring-boot-starter-swagger -swagger.description=Starter for swagger 2.x -swagger.version=1.9.0.RELEASE -swagger.license=Apache License, Version 2.0 -swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html -swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-swagger -swagger.contact.name=didi -swagger.contact.url=http://blog.didispace.com -swagger.contact.email=dyc87112@qq.com -swagger.base-package=com.didispace -swagger.base-path=/** \ No newline at end of file diff --git a/2.1.x/chapter2-5/src/test/java/com/didispace/chapter25/DemoApplicationTests.java b/2.1.x/chapter2-5/src/test/java/com/didispace/chapter25/DemoApplicationTests.java deleted file mode 100644 index d36e438e..00000000 --- a/2.1.x/chapter2-5/src/test/java/com/didispace/chapter25/DemoApplicationTests.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.didispace.chapter25; - -import io.github.swagger2markup.Swagger2MarkupConfig; -import io.github.swagger2markup.Swagger2MarkupConverter; -import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; -import io.github.swagger2markup.markup.builder.MarkupLanguage; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.net.URL; -import java.nio.file.Path; -import java.nio.file.Paths; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class DemoApplicationTests { - - @Test - public void generateAsciiDocs() throws Exception { - - URL remoteSwaggerFile = new URL("http://localhost:8080/v2/api-docs"); - Path outputDirectory = Paths.get("src/docs/asciidoc/generated"); - - // 输出Ascii格式 - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() - .withMarkupLanguage(MarkupLanguage.ASCIIDOC) - .build(); - - Swagger2MarkupConverter.from(remoteSwaggerFile) - .withConfig(config) - .build() - .toFolder(outputDirectory); - } - - @Test - public void generateMarkdownDocs() throws Exception { - - URL remoteSwaggerFile = new URL("http://localhost:8080/v2/api-docs"); - Path outputDirectory = Paths.get("src/docs/markdown/generated"); - - // 输出Ascii格式 - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() - .withMarkupLanguage(MarkupLanguage.MARKDOWN) - .build(); - - Swagger2MarkupConverter.from(remoteSwaggerFile) - .withConfig(config) - .build() - .toFolder(outputDirectory); - } - - @Test - public void generateConfluenceDocs() throws Exception { - - URL remoteSwaggerFile = new URL("http://localhost:8080/v2/api-docs"); - Path outputDirectory = Paths.get("src/docs/confluence/generated"); - - // 输出Ascii格式 - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() - .withMarkupLanguage(MarkupLanguage.CONFLUENCE_MARKUP) - .build(); - - Swagger2MarkupConverter.from(remoteSwaggerFile) - .withConfig(config) - .build() - .toFolder(outputDirectory); - } - -} \ No newline at end of file diff --git a/2.1.x/chapter2-6/.gitignore b/2.1.x/chapter2-6/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter2-6/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter2-6/pom.xml b/2.1.x/chapter2-6/pom.xml deleted file mode 100644 index 09ba9399..00000000 --- a/2.1.x/chapter2-6/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter2-6 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/Chapter26Application.java b/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/Chapter26Application.java deleted file mode 100644 index ab89e203..00000000 --- a/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/Chapter26Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter26; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter26Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter26Application.class, args); - } - -} diff --git a/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/User.java b/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/User.java deleted file mode 100644 index 60e131cd..00000000 --- a/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/User.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.didispace.chapter26; - -import lombok.Data; - -@Data -public class User { - - private Long id; - private String name; - private Integer age; - -} \ No newline at end of file diff --git a/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/UserController.java b/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/UserController.java deleted file mode 100644 index a84cf8d4..00000000 --- a/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/UserController.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.didispace.chapter26; - -import org.springframework.web.bind.annotation.*; - -import java.util.*; - -@RestController -@RequestMapping(value = "/users") // 通过这里配置使下面的映射都在/users下 -public class UserController { - - // 创建线程安全的Map,模拟users信息的存储 - static Map users = Collections.synchronizedMap(new HashMap<>()); - - @GetMapping("/") - public List getUserList() { - List r = new ArrayList<>(users.values()); - return r; - } - - @PostMapping("/") - public String postUser(@RequestBody User user) { - users.put(user.getId(), user); - return "success"; - } - - @GetMapping("/{id}") - public User getUser(@PathVariable Long id) { - return users.get(id); - } - - @PutMapping("/{id}") - public String putUser(@PathVariable Long id, @RequestBody User user) { - User u = users.get(id); - u.setName(user.getName()); - u.setAge(user.getAge()); - users.put(id, u); - return "success"; - } - - @DeleteMapping("/{id}") - public String deleteUser(@PathVariable Long id) { - users.remove(id); - return "success"; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter2-6/src/main/resources/application.properties b/2.1.x/chapter2-6/src/main/resources/application.properties deleted file mode 100644 index eae6a38f..00000000 --- a/2.1.x/chapter2-6/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -# 打印RequestMapping中的所有接口信息 -logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping=trace - diff --git a/2.1.x/chapter2-7/.gitignore b/2.1.x/chapter2-7/.gitignore deleted file mode 100644 index 2af7cefb..00000000 --- a/2.1.x/chapter2-7/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ \ No newline at end of file diff --git a/2.1.x/chapter2-7/pom.xml b/2.1.x/chapter2-7/pom.xml deleted file mode 100644 index 882a8176..00000000 --- a/2.1.x/chapter2-7/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.2.3.RELEASE - - - - com.didispace - chapter2-7 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - io.springfox - springfox-boot-starter - 3.0.0 - - - - org.projectlombok - lombok - provided - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - - - false - - jcenter-releases - jcenter - http://jcenter.bintray.com - - - - diff --git a/2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/Chapter27Application.java b/2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/Chapter27Application.java deleted file mode 100644 index 7a6a667b..00000000 --- a/2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/Chapter27Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter27; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import springfox.documentation.oas.annotations.EnableOpenApi; - -@EnableOpenApi -@SpringBootApplication -public class Chapter27Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter27Application.class, args); - } - -} diff --git a/2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/User.java b/2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/User.java deleted file mode 100644 index 25c99ae8..00000000 --- a/2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/User.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.didispace.demo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.validation.constraints.*; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@ApiModel("用户基本信息") -public class User { - - @ApiModelProperty("姓名") - @Size(max = 20) - private String name; - @ApiModelProperty("年龄") - @Max(150) - @Min(1) - private Integer age; - @NotNull - private String address; - @Pattern(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$") - private String email; - -} \ No newline at end of file diff --git a/2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/UserController.java b/2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/UserController.java deleted file mode 100644 index fcfb546d..00000000 --- a/2.1.x/chapter2-7/src/main/java/com/didispace/chapter27/UserController.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.didispace.demo; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; -import springfox.documentation.annotations.ApiIgnore; - -import javax.validation.Valid; -import java.util.ArrayList; -import java.util.List; - -@Api(tags="用户管理") -@RestController -public class UserController { - - @ApiOperation("创建用户") - @PostMapping("/users") - public User create(@RequestBody @Valid User user) { - return user; - } - - @ApiOperation("用户详情") - @GetMapping("/users/{id}") - public User findById(@PathVariable Long id) { - return new User("bbb", 21, "上海", "aaa@bbb.com"); - } - - @ApiOperation("用户列表") - @GetMapping("/users") - public List list(@ApiParam("查看第几页") @RequestParam int pageIndex, - @ApiParam("每页多少条") @RequestParam int pageSize) { - List result = new ArrayList<>(); - result.add(new User("aaa", 50, "北京", "aaa@ccc.com")); - result.add(new User("bbb", 21, "广州", "aaa@ddd.com")); - return result; - } - - @ApiIgnore - @DeleteMapping("/users/{id}") - public String deleteById(@PathVariable Long id) { - return "delete user : " + id; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter2-7/src/main/resources/application.properties b/2.1.x/chapter2-7/src/main/resources/application.properties deleted file mode 100644 index d910c856..00000000 --- a/2.1.x/chapter2-7/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping=trace - diff --git a/2.1.x/chapter3-1/.gitignore b/2.1.x/chapter3-1/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-1/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-1/pom.xml b/2.1.x/chapter3-1/pom.xml deleted file mode 100644 index 4621591e..00000000 --- a/2.1.x/chapter3-1/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-1 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-jdbc - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/Chapter31Application.java b/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/Chapter31Application.java deleted file mode 100644 index c83da9dd..00000000 --- a/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/Chapter31Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter31; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter31Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter31Application.class, args); - } - -} diff --git a/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/User.java b/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/User.java deleted file mode 100644 index 5c54cf36..00000000 --- a/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/User.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter31; - -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -public class User { - - private String name; - private Integer age; - -} \ No newline at end of file diff --git a/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/UserService.java b/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/UserService.java deleted file mode 100644 index 2ce0b727..00000000 --- a/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/UserService.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.didispace.chapter31; - -import java.util.List; - -public interface UserService { - - /** - * 新增一个用户 - * - * @param name - * @param age - */ - int create(String name, Integer age); - - /** - * 根据name查询用户 - * - * @param name - * @return - */ - List getByName(String name); - - /** - * 根据name删除用户 - * - * @param name - */ - int deleteByName(String name); - - /** - * 获取用户总量 - */ - int getAllUsers(); - - /** - * 删除所有用户 - */ - int deleteAllUsers(); - -} \ No newline at end of file diff --git a/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/UserServiceImpl.java b/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/UserServiceImpl.java deleted file mode 100644 index 3cb55fb2..00000000 --- a/2.1.x/chapter3-1/src/main/java/com/didispace/chapter31/UserServiceImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.didispace.chapter31; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; - -@Service -public class UserServiceImpl implements UserService { - - private JdbcTemplate jdbcTemplate; - - UserServiceImpl(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - } - - @Override - public int create(String name, Integer age) { - return jdbcTemplate.update("insert into USER(NAME, AGE) values(?, ?)", name, age); - } - - @Override - public List getByName(String name) { - List users = jdbcTemplate.query("select NAME, AGE from USER where NAME = ?", (resultSet, i) -> { - User user = new User(); - user.setName(resultSet.getString("NAME")); - user.setAge(resultSet.getInt("AGE")); - return user; - }, name); - return users; - } - - @Override - public int deleteByName(String name) { - return jdbcTemplate.update("delete from USER where NAME = ?", name); - } - - @Override - public int getAllUsers() { - return jdbcTemplate.queryForObject("select count(1) from USER", Integer.class); - } - - @Override - public int deleteAllUsers() { - return jdbcTemplate.update("delete from USER"); - } - -} \ No newline at end of file diff --git a/2.1.x/chapter3-1/src/main/resources/application.properties b/2.1.x/chapter3-1/src/main/resources/application.properties deleted file mode 100644 index 66ff8fe4..00000000 --- a/2.1.x/chapter3-1/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password= -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver \ No newline at end of file diff --git a/2.1.x/chapter3-1/src/test/java/com/didispace/chapter31/Chapter31ApplicationTests.java b/2.1.x/chapter3-1/src/test/java/com/didispace/chapter31/Chapter31ApplicationTests.java deleted file mode 100644 index 2905f545..00000000 --- a/2.1.x/chapter3-1/src/test/java/com/didispace/chapter31/Chapter31ApplicationTests.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.didispace.chapter31; - -import org.junit.Assert; -import org.junit.Before; -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.http.MediaType; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -import static org.hamcrest.Matchers.equalTo; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - - -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter31ApplicationTests { - - @Autowired - private UserService userSerivce; - - @Before - public void setUp() { - // 准备,清空user表 - userSerivce.deleteAllUsers(); - } - - @Test - public void test() throws Exception { - // 插入5个用户 - userSerivce.create("Tom", 10); - userSerivce.create("Mike", 11); - userSerivce.create("Didispace", 30); - userSerivce.create("Oscar", 21); - userSerivce.create("Linda", 17); - - // 查询名为Oscar的用户,判断年龄是否匹配 - List userList = userSerivce.getByName("Oscar"); - Assert.assertEquals(21, userList.get(0).getAge().intValue()); - - // 查数据库,应该有5个用户 - Assert.assertEquals(5, userSerivce.getAllUsers()); - - // 删除两个用户 - userSerivce.deleteByName("Tom"); - userSerivce.deleteByName("Mike"); - - // 查数据库,应该有5个用户 - Assert.assertEquals(3, userSerivce.getAllUsers()); - - } - -} diff --git a/2.1.x/chapter3-10/.gitignore b/2.1.x/chapter3-10/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-10/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-10/pom.xml b/2.1.x/chapter3-10/pom.xml deleted file mode 100644 index 9b2abc07..00000000 --- a/2.1.x/chapter3-10/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-10 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/Chapter310Application.java b/2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/Chapter310Application.java deleted file mode 100644 index 72a7dd3e..00000000 --- a/2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/Chapter310Application.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.didispace.chapter310; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@SpringBootApplication -public class Chapter310Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter310Application.class, args); - } - - @RestController - static class TextController { - - @GetMapping("/hello") - public String hello() { - return "hello world"; - } - - } - -} diff --git a/2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/User.java b/2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/User.java deleted file mode 100644 index a2347ea8..00000000 --- a/2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/User.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.didispace.chapter310; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.*; -import javax.validation.constraints.Max; - -@Entity -@Data -@NoArgsConstructor -public class User { - - @Id - @GeneratedValue - private Long id; - - private String name; - @Max(50) - private Integer age; - - public User(String name, Integer age) { - this.name = name; - this.age = age; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/UserRepository.java b/2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/UserRepository.java deleted file mode 100644 index 366e1d21..00000000 --- a/2.1.x/chapter3-10/src/main/java/com/didispace/chapter310/UserRepository.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.didispace.chapter310; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -/** - * Created by 程序猿DD/翟永超 on 2020/7/9. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -public interface UserRepository extends JpaRepository { - - User findByName(String name); - - User findByNameAndAge(String name, Integer age); - - @Query("from User u where u.name=:name") - User findUser(@Param("name") String name); - -} diff --git a/2.1.x/chapter3-10/src/main/resources/application.properties b/2.1.x/chapter3-10/src/main/resources/application.properties deleted file mode 100644 index 7238387a..00000000 --- a/2.1.x/chapter3-10/src/main/resources/application.properties +++ /dev/null @@ -1,7 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password=12345678 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - -spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect -spring.jpa.hibernate.ddl-auto=create diff --git a/2.1.x/chapter3-10/src/test/java/com/didispace/chapter310/Chapter310ApplicationTests.java b/2.1.x/chapter3-10/src/test/java/com/didispace/chapter310/Chapter310ApplicationTests.java deleted file mode 100644 index 02fee65b..00000000 --- a/2.1.x/chapter3-10/src/test/java/com/didispace/chapter310/Chapter310ApplicationTests.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.didispace.chapter310; - -import lombok.extern.slf4j.Slf4j; -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.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter310ApplicationTests { - - @Autowired - private UserRepository userRepository; - - @Test - @Transactional - public void test() throws Exception { - // 创建10条记录 - userRepository.save(new User("AAA", 10)); - userRepository.save(new User("BBB", 20)); - userRepository.save(new User("CCC", 30)); - userRepository.save(new User("DDD", 40)); - userRepository.save(new User("EEE", 50)); - userRepository.save(new User("FFF", 60)); - userRepository.save(new User("GGG", 70)); - userRepository.save(new User("HHH", 80)); - userRepository.save(new User("III", 90)); - userRepository.save(new User("JJJ", 100)); - - // 测试findAll, 查询所有记录 - Assert.assertEquals(10, userRepository.findAll().size()); - - // 测试findByName, 查询姓名为FFF的User - Assert.assertEquals(60, userRepository.findByName("FFF").getAge().longValue()); - - // 测试findUser, 查询姓名为FFF的User - Assert.assertEquals(60, userRepository.findUser("FFF").getAge().longValue()); - - // 测试findByNameAndAge, 查询姓名为FFF并且年龄为60的User - Assert.assertEquals("FFF", userRepository.findByNameAndAge("FFF", 60).getName()); - - // 测试删除姓名为AAA的User - userRepository.delete(userRepository.findByName("AAA")); - - // 测试findAll, 查询所有记录, 验证上面的删除是否成功 - Assert.assertEquals(9, userRepository.findAll().size()); - - } - -} diff --git a/2.1.x/chapter3-2/.gitignore b/2.1.x/chapter3-2/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-2/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-2/pom.xml b/2.1.x/chapter3-2/pom.xml deleted file mode 100644 index 2de383a2..00000000 --- a/2.1.x/chapter3-2/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-2 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-jdbc - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/Chapter32Application.java b/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/Chapter32Application.java deleted file mode 100644 index d782cff1..00000000 --- a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/Chapter32Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter32; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter32Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter32Application.class, args); - } - -} diff --git a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/User.java b/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/User.java deleted file mode 100644 index 7553c2e2..00000000 --- a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/User.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter32; - -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -public class User { - - private String name; - private Integer age; - -} \ No newline at end of file diff --git a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/UserService.java b/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/UserService.java deleted file mode 100644 index c4e3cd02..00000000 --- a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/UserService.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.didispace.chapter32; - -import java.util.List; - -public interface UserService { - - /** - * 新增一个用户 - * - * @param name - * @param age - */ - int create(String name, Integer age); - - /** - * 根据name查询用户 - * - * @param name - * @return - */ - List getByName(String name); - - /** - * 根据name删除用户 - * - * @param name - */ - int deleteByName(String name); - - /** - * 获取用户总量 - */ - int getAllUsers(); - - /** - * 删除所有用户 - */ - int deleteAllUsers(); - -} \ No newline at end of file diff --git a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/UserServiceImpl.java b/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/UserServiceImpl.java deleted file mode 100644 index 9fb1bd08..00000000 --- a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/UserServiceImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.didispace.chapter32; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; - -@Service -public class UserServiceImpl implements UserService { - - private JdbcTemplate jdbcTemplate; - - UserServiceImpl(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - } - - @Override - public int create(String name, Integer age) { - return jdbcTemplate.update("insert into USER(NAME, AGE) values(?, ?)", name, age); - } - - @Override - public List getByName(String name) { - List users = jdbcTemplate.query("select NAME, AGE from USER where NAME = ?", (resultSet, i) -> { - User user = new User(); - user.setName(resultSet.getString("NAME")); - user.setAge(resultSet.getInt("AGE")); - return user; - }, name); - return users; - } - - @Override - public int deleteByName(String name) { - return jdbcTemplate.update("delete from USER where NAME = ?", name); - } - - @Override - public int getAllUsers() { - return jdbcTemplate.queryForObject("select count(1) from USER", Integer.class); - } - - @Override - public int deleteAllUsers() { - return jdbcTemplate.update("delete from USER"); - } - -} \ No newline at end of file diff --git a/2.1.x/chapter3-2/src/main/resources/application.properties b/2.1.x/chapter3-2/src/main/resources/application.properties deleted file mode 100644 index b0d32069..00000000 --- a/2.1.x/chapter3-2/src/main/resources/application.properties +++ /dev/null @@ -1,17 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password= -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - -# 最小空闲连接,默认值10,小于0或大于maximum-pool-size,都会重置为maximum-pool-size -spring.datasource.hikari.minimum-idle=10 -# 最大连接数,小于等于0会被重置为默认值10;大于零小于1会被重置为minimum-idle的值 -spring.datasource.hikari.maximum-pool-size=20 -# 空闲连接超时时间,默认值600000(10分钟),大于等于max-lifetime且max-lifetime>0,会被重置为0;不等于0且小于10秒,会被重置为10秒。 -spring.datasource.hikari.idle-timeout=500000 -# 连接最大存活时间.不等于0且小于30秒,会被重置为默认值30分钟.设置应该比mysql设置的超时时间短 -spring.datasource.hikari.max-lifetime=540000 -# 连接超时时间:毫秒,小于250毫秒,否则被重置为默认值30秒 -spring.datasource.hikari.connection-timeout=60000 -# 用于测试连接是否可用的查询语句 -spring.datasource.hikari.connection-test-query=SELECT 1 diff --git a/2.1.x/chapter3-2/src/test/java/com/didispace/chapter32/Chapter32ApplicationTests.java b/2.1.x/chapter3-2/src/test/java/com/didispace/chapter32/Chapter32ApplicationTests.java deleted file mode 100644 index e23dd01c..00000000 --- a/2.1.x/chapter3-2/src/test/java/com/didispace/chapter32/Chapter32ApplicationTests.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.didispace.chapter32; - -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.Before; -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.http.MediaType; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.transaction.annotation.Transactional; - -import javax.sql.DataSource; -import java.util.List; - -import static org.hamcrest.Matchers.equalTo; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter32ApplicationTests { - - @Autowired - private UserService userSerivce; - - @Autowired - private DataSource dataSource; - - @Before - public void setUp() { - // 准备,清空user表 - userSerivce.deleteAllUsers(); - - } - - @Test - public void test() throws Exception { - // 插入5个用户 - userSerivce.create("Tom", 10); - userSerivce.create("Mike", 11); - userSerivce.create("Didispace", 30); - userSerivce.create("Oscar", 21); - userSerivce.create("Linda", 17); - - // 查询名为Oscar的用户,判断年龄是否匹配 - List userList = userSerivce.getByName("Oscar"); - Assert.assertEquals(21, userList.get(0).getAge().intValue()); - - // 查数据库,应该有5个用户 - Assert.assertEquals(5, userSerivce.getAllUsers()); - - // 删除两个用户 - userSerivce.deleteByName("Tom"); - userSerivce.deleteByName("Mike"); - - // 查数据库,应该有5个用户 - Assert.assertEquals(3, userSerivce.getAllUsers()); - - } - -} diff --git a/2.1.x/chapter3-3/.gitignore b/2.1.x/chapter3-3/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-3/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-3/pom.xml b/2.1.x/chapter3-3/pom.xml deleted file mode 100644 index c83eddc6..00000000 --- a/2.1.x/chapter3-3/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-3 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-jdbc - - - - com.alibaba - druid-spring-boot-starter - 1.1.21 - - - - org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/Chapter33Application.java b/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/Chapter33Application.java deleted file mode 100644 index 4653f680..00000000 --- a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/Chapter33Application.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.didispace.chapter33; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@SpringBootApplication -public class Chapter33Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter33Application.class, args); - } - - @RestController - static class TextController { - - @GetMapping("/hello") - public String hello() { - return "hello world"; - } - - } - -} diff --git a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/User.java b/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/User.java deleted file mode 100644 index ac0b9460..00000000 --- a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/User.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter33; - -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -public class User { - - private String name; - private Integer age; - -} \ No newline at end of file diff --git a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserController.java b/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserController.java deleted file mode 100644 index f88d0dc0..00000000 --- a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserController.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.didispace.chapter33; - -import lombok.AllArgsConstructor; -import lombok.Data; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * Created by 程序猿DD/翟永超 on 2020/2/8. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -@Data -@AllArgsConstructor -@RestController -public class UserController { - - private UserService userService; - - @PostMapping("/user") - public int create(@RequestBody User user) { - return userService.create(user.getName(), user.getAge()); - } - - @GetMapping("/user/{name}") - public List getByName(@PathVariable String name) { - return userService.getByName(name); - } - - @DeleteMapping("/user/{name}") - public int deleteByName(@PathVariable String name) { - return userService.deleteByName(name); - } - - @GetMapping("/user/count") - public int getAllUsers() { - return userService.getAllUsers(); - } - - @DeleteMapping("/user/all") - public int deleteAllUsers() { - return userService.deleteAllUsers(); - } - -} diff --git a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserService.java b/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserService.java deleted file mode 100644 index 7eddffb5..00000000 --- a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserService.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.didispace.chapter33; - -import java.util.List; - -public interface UserService { - - /** - * 新增一个用户 - * - * @param name - * @param age - */ - int create(String name, Integer age); - - /** - * 根据name查询用户 - * - * @param name - * @return - */ - List getByName(String name); - - /** - * 根据name删除用户 - * - * @param name - */ - int deleteByName(String name); - - /** - * 获取用户总量 - */ - int getAllUsers(); - - /** - * 删除所有用户 - */ - int deleteAllUsers(); - -} \ No newline at end of file diff --git a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserServiceImpl.java b/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserServiceImpl.java deleted file mode 100644 index 43f0f79a..00000000 --- a/2.1.x/chapter3-3/src/main/java/com/didispace/chapter33/UserServiceImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.didispace.chapter33; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; - -@Service -public class UserServiceImpl implements UserService { - - private JdbcTemplate jdbcTemplate; - - UserServiceImpl(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - } - - @Override - public int create(String name, Integer age) { - return jdbcTemplate.update("insert into USER(NAME, AGE) values(?, ?)", name, age); - } - - @Override - public List getByName(String name) { - List users = jdbcTemplate.query("select NAME, AGE from USER where NAME = ?", (resultSet, i) -> { - User user = new User(); - user.setName(resultSet.getString("NAME")); - user.setAge(resultSet.getInt("AGE")); - return user; - }, name); - return users; - } - - @Override - public int deleteByName(String name) { - return jdbcTemplate.update("delete from USER where NAME = ?", name); - } - - @Override - public int getAllUsers() { - return jdbcTemplate.queryForObject("select count(1) from USER", Integer.class); - } - - @Override - public int deleteAllUsers() { - return jdbcTemplate.update("delete from USER"); - } - -} \ No newline at end of file diff --git a/2.1.x/chapter3-3/src/main/resources/application.properties b/2.1.x/chapter3-3/src/main/resources/application.properties deleted file mode 100644 index 26f3a97b..00000000 --- a/2.1.x/chapter3-3/src/main/resources/application.properties +++ /dev/null @@ -1,29 +0,0 @@ - -# 基础配置 -spring.datasource.druid.url=jdbc:mysql://localhost:3306/test -spring.datasource.druid.username=root -spring.datasource.druid.password= -spring.datasource.druid.driver-class-name=com.mysql.cj.jdbc.Driver - -# 连接池配置 -spring.datasource.druid.initialSize=10 -spring.datasource.druid.maxActive=20 -spring.datasource.druid.maxWait=60000 -spring.datasource.druid.minIdle=1 -spring.datasource.druid.timeBetweenEvictionRunsMillis=60000 -spring.datasource.druid.minEvictableIdleTimeMillis=300000 -spring.datasource.druid.testWhileIdle=true -spring.datasource.druid.testOnBorrow=true -spring.datasource.druid.testOnReturn=false -spring.datasource.druid.poolPreparedStatements=true -spring.datasource.druid.maxOpenPreparedStatements=20 -spring.datasource.druid.validationQuery=SELECT 1 -spring.datasource.druid.validation-query-timeout=500 -spring.datasource.druid.filters=stat,wall - -# 监控配置 -spring.datasource.druid.stat-view-servlet.enabled=true -spring.datasource.druid.stat-view-servlet.url-pattern=/druid/* -spring.datasource.druid.stat-view-servlet.reset-enable=true -spring.datasource.druid.stat-view-servlet.login-username=admin -spring.datasource.druid.stat-view-servlet.login-password=admin diff --git a/2.1.x/chapter3-3/src/test/java/com/didispace/chapter33/Chapter33ApplicationTests.java b/2.1.x/chapter3-3/src/test/java/com/didispace/chapter33/Chapter33ApplicationTests.java deleted file mode 100644 index f86be74a..00000000 --- a/2.1.x/chapter3-3/src/test/java/com/didispace/chapter33/Chapter33ApplicationTests.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.didispace.chapter33; - -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.Before; -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.http.MediaType; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.RequestBuilder; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.transaction.annotation.Transactional; - -import javax.sql.DataSource; -import java.util.List; - -import static org.hamcrest.Matchers.equalTo; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter33ApplicationTests { - - @Autowired - private UserService userSerivce; - - @Autowired - private DataSource dataSource; - - @Before - public void setUp() { - // 准备,清空user表 - userSerivce.deleteAllUsers(); - - } - - @Test - public void test() throws Exception { - // 插入5个用户 - userSerivce.create("Tom", 10); - userSerivce.create("Mike", 11); - userSerivce.create("Didispace", 30); - userSerivce.create("Oscar", 21); - userSerivce.create("Linda", 17); - - // 查询名为Oscar的用户,判断年龄是否匹配 - List userList = userSerivce.getByName("Oscar"); - Assert.assertEquals(21, userList.get(0).getAge().intValue()); - - // 查数据库,应该有5个用户 - Assert.assertEquals(5, userSerivce.getAllUsers()); - - // 删除两个用户 - userSerivce.deleteByName("Tom"); - userSerivce.deleteByName("Mike"); - - // 查数据库,应该有5个用户 - Assert.assertEquals(3, userSerivce.getAllUsers()); - - } - -} diff --git a/2.1.x/chapter3-4/.gitignore b/2.1.x/chapter3-4/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-4/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-4/pom.xml b/2.1.x/chapter3-4/pom.xml deleted file mode 100644 index 602beb6d..00000000 --- a/2.1.x/chapter3-4/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-4 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/Chapter34Application.java b/2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/Chapter34Application.java deleted file mode 100644 index 4b9e8193..00000000 --- a/2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/Chapter34Application.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.didispace.chapter34; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@SpringBootApplication -public class Chapter34Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter34Application.class, args); - } - - @RestController - static class TextController { - - @GetMapping("/hello") - public String hello() { - return "hello world"; - } - - } - -} diff --git a/2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/User.java b/2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/User.java deleted file mode 100644 index 701ed4d4..00000000 --- a/2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/User.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.didispace.chapter34; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -@Data -@NoArgsConstructor -public class User { - - @Id - @GeneratedValue - private Long id; - - private String name; - private Integer age; - - public User(String name, Integer age) { - this.name = name; - this.age = age; - } -} \ No newline at end of file diff --git a/2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/UserRepository.java b/2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/UserRepository.java deleted file mode 100644 index 17533dd3..00000000 --- a/2.1.x/chapter3-4/src/main/java/com/didispace/chapter34/UserRepository.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.didispace.chapter34; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -/** - * Created by 程序猿DD/翟永超 on 2020/2/15. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -public interface UserRepository extends JpaRepository { - - User findByName(String name); - - User findByNameAndAge(String name, Integer age); - - @Query("from User u where u.name=:name") - User findUser(@Param("name") String name); - -} diff --git a/2.1.x/chapter3-4/src/main/resources/application.properties b/2.1.x/chapter3-4/src/main/resources/application.properties deleted file mode 100644 index 44c64de2..00000000 --- a/2.1.x/chapter3-4/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password= -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - -spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/2.1.x/chapter3-4/src/test/java/com/didispace/chapter34/Chapter34ApplicationTests.java b/2.1.x/chapter3-4/src/test/java/com/didispace/chapter34/Chapter34ApplicationTests.java deleted file mode 100644 index e104e22c..00000000 --- a/2.1.x/chapter3-4/src/test/java/com/didispace/chapter34/Chapter34ApplicationTests.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.didispace.chapter34; - -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.Before; -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 javax.sql.DataSource; -import java.util.List; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter34ApplicationTests { - - @Autowired - private UserRepository userRepository; - - @Test - public void test() throws Exception { - // 创建10条记录 - userRepository.save(new User("AAA", 10)); - userRepository.save(new User("BBB", 20)); - userRepository.save(new User("CCC", 30)); - userRepository.save(new User("DDD", 40)); - userRepository.save(new User("EEE", 50)); - userRepository.save(new User("FFF", 60)); - userRepository.save(new User("GGG", 70)); - userRepository.save(new User("HHH", 80)); - userRepository.save(new User("III", 90)); - userRepository.save(new User("JJJ", 100)); - - // 测试findAll, 查询所有记录 - Assert.assertEquals(10, userRepository.findAll().size()); - - // 测试findByName, 查询姓名为FFF的User - Assert.assertEquals(60, userRepository.findByName("FFF").getAge().longValue()); - - // 测试findUser, 查询姓名为FFF的User - Assert.assertEquals(60, userRepository.findUser("FFF").getAge().longValue()); - - // 测试findByNameAndAge, 查询姓名为FFF并且年龄为60的User - Assert.assertEquals("FFF", userRepository.findByNameAndAge("FFF", 60).getName()); - - // 测试删除姓名为AAA的User - userRepository.delete(userRepository.findByName("AAA")); - - // 测试findAll, 查询所有记录, 验证上面的删除是否成功 - Assert.assertEquals(9, userRepository.findAll().size()); - - } - -} diff --git a/2.1.x/chapter3-5/.gitignore b/2.1.x/chapter3-5/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-5/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-5/pom.xml b/2.1.x/chapter3-5/pom.xml deleted file mode 100644 index 2cb4f499..00000000 --- a/2.1.x/chapter3-5/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-5 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 2.1.1 - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/Chapter35Application.java b/2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/Chapter35Application.java deleted file mode 100644 index 48e71f85..00000000 --- a/2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/Chapter35Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter35; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter35Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter35Application.class, args); - } - -} diff --git a/2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/User.java b/2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/User.java deleted file mode 100644 index d815f4c1..00000000 --- a/2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/User.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.didispace.chapter35; - -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -public class User { - - private Long id; - - private String name; - private Integer age; - - public User(String name, Integer age) { - this.name = name; - this.age = age; - } -} \ No newline at end of file diff --git a/2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/UserMapper.java b/2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/UserMapper.java deleted file mode 100644 index 17f6aa18..00000000 --- a/2.1.x/chapter3-5/src/main/java/com/didispace/chapter35/UserMapper.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.didispace.chapter35; - -import org.apache.ibatis.annotations.Insert; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -/** - * Created by 程序猿DD/翟永超 on 2020/2/15. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -@Mapper -public interface UserMapper { - - @Select("SELECT * FROM USER WHERE NAME = #{name}") - User findByName(@Param("name") String name); - - @Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})") - int insert(@Param("name") String name, @Param("age") Integer age); - -} diff --git a/2.1.x/chapter3-5/src/main/resources/application.properties b/2.1.x/chapter3-5/src/main/resources/application.properties deleted file mode 100644 index 779d89b9..00000000 --- a/2.1.x/chapter3-5/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password=12345678 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/2.1.x/chapter3-5/src/test/java/com/didispace/chapter35/Chapter35ApplicationTests.java b/2.1.x/chapter3-5/src/test/java/com/didispace/chapter35/Chapter35ApplicationTests.java deleted file mode 100644 index b6de7a08..00000000 --- a/2.1.x/chapter3-5/src/test/java/com/didispace/chapter35/Chapter35ApplicationTests.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.didispace.chapter35; - -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.Before; -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.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import javax.sql.DataSource; -import java.util.List; - -@RunWith(SpringRunner.class) -@SpringBootTest -@Transactional -public class Chapter35ApplicationTests { - - @Autowired - private UserMapper userMapper; - - @Test - @Rollback - public void test() throws Exception { - userMapper.insert("AAA", 20); - User u = userMapper.findByName("AAA"); - Assert.assertEquals(20, u.getAge().intValue()); - } - -} diff --git a/2.1.x/chapter3-6/.gitignore b/2.1.x/chapter3-6/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-6/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-6/pom.xml b/2.1.x/chapter3-6/pom.xml deleted file mode 100644 index 2f515975..00000000 --- a/2.1.x/chapter3-6/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-6 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 2.1.1 - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/Chapter36Application.java b/2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/Chapter36Application.java deleted file mode 100644 index 2ce02b15..00000000 --- a/2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/Chapter36Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter36; - -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@MapperScan("com.didispace.chapter36.mapper") -@SpringBootApplication -public class Chapter36Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter36Application.class, args); - } - -} diff --git a/2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/entity/User.java b/2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/entity/User.java deleted file mode 100644 index 6196ed6d..00000000 --- a/2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/entity/User.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.didispace.chapter36.entity; - -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -public class User { - - private Long id; - - private String name; - private Integer age; - - public User(String name, Integer age) { - this.name = name; - this.age = age; - } -} \ No newline at end of file diff --git a/2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/mapper/UserMapper.java b/2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/mapper/UserMapper.java deleted file mode 100644 index cd361f46..00000000 --- a/2.1.x/chapter3-6/src/main/java/com/didispace/chapter36/mapper/UserMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.didispace.chapter36.mapper; - -import com.didispace.chapter36.entity.User; -import org.apache.ibatis.annotations.Param; - -/** - * Created by 程序猿DD/翟永超 on 2020/2/28. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -public interface UserMapper { - - User findByName(@Param("name") String name); - - int insert(@Param("name") String name, @Param("age") Integer age); - -} diff --git a/2.1.x/chapter3-6/src/main/resources/application.properties b/2.1.x/chapter3-6/src/main/resources/application.properties deleted file mode 100644 index ec5cde49..00000000 --- a/2.1.x/chapter3-6/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password=12345678 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - -mybatis.mapper-locations=classpath:mapper/*.xml diff --git a/2.1.x/chapter3-6/src/main/resources/mapper/UserMapper.xml b/2.1.x/chapter3-6/src/main/resources/mapper/UserMapper.xml deleted file mode 100644 index 520d290e..00000000 --- a/2.1.x/chapter3-6/src/main/resources/mapper/UserMapper.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age}) - - \ No newline at end of file diff --git a/2.1.x/chapter3-6/src/test/java/com/didispace/chapter36/Chapter36ApplicationTests.java b/2.1.x/chapter3-6/src/test/java/com/didispace/chapter36/Chapter36ApplicationTests.java deleted file mode 100644 index aab8acb1..00000000 --- a/2.1.x/chapter3-6/src/test/java/com/didispace/chapter36/Chapter36ApplicationTests.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.didispace.chapter36; - -import com.didispace.chapter36.entity.User; -import com.didispace.chapter36.mapper.UserMapper; -import lombok.extern.slf4j.Slf4j; -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.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -@Transactional -public class Chapter36ApplicationTests { - - @Autowired - private UserMapper userMapper; - - @Test - @Rollback - public void test() throws Exception { - userMapper.insert("AAA", 20); - User u = userMapper.findByName("AAA"); - Assert.assertEquals(20, u.getAge().intValue()); - } - -} diff --git a/2.1.x/chapter3-7/.gitignore b/2.1.x/chapter3-7/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-7/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-7/pom.xml b/2.1.x/chapter3-7/pom.xml deleted file mode 100644 index f8314a33..00000000 --- a/2.1.x/chapter3-7/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-7 - 0.0.1-SNAPSHOT - 使用JDBCTemplate的多数据源配置 - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-jdbc - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/Chapter37Application.java b/2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/Chapter37Application.java deleted file mode 100644 index 92be7068..00000000 --- a/2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/Chapter37Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter37; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter37Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter37Application.class, args); - } - -} diff --git a/2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/DataSourceConfiguration.java b/2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/DataSourceConfiguration.java deleted file mode 100644 index f821153b..00000000 --- a/2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/DataSourceConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.didispace.chapter37; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.jdbc.core.JdbcTemplate; - -import javax.sql.DataSource; - -@Configuration -public class DataSourceConfiguration { - - @Primary - @Bean - @ConfigurationProperties(prefix = "spring.datasource.primary") - public DataSource primaryDataSource() { - return DataSourceBuilder.create().build(); - } - - @Bean - @ConfigurationProperties(prefix = "spring.datasource.secondary") - public DataSource secondaryDataSource() { - return DataSourceBuilder.create().build(); - } - - @Bean - public JdbcTemplate primaryJdbcTemplate(@Qualifier("primaryDataSource") DataSource primaryDataSource) { - return new JdbcTemplate(primaryDataSource); - } - - @Bean - public JdbcTemplate secondaryJdbcTemplate(@Qualifier("secondaryDataSource") DataSource secondaryDataSource) { - return new JdbcTemplate(secondaryDataSource); - } - -} diff --git a/2.1.x/chapter3-7/src/main/resources/application.properties b/2.1.x/chapter3-7/src/main/resources/application.properties deleted file mode 100644 index 25937c84..00000000 --- a/2.1.x/chapter3-7/src/main/resources/application.properties +++ /dev/null @@ -1,11 +0,0 @@ -# pring boot 1.x的配置:spring.datasource.primary.url=jdbc:mysql://localhost:3306/test1 -spring.datasource.primary.jdbc-url=jdbc:mysql://localhost:3306/test1 -spring.datasource.primary.username=root -spring.datasource.primary.password=123456 -spring.datasource.primary.driver-class-name=com.mysql.cj.jdbc.Driver - -# spring boot 1.x的配置:spring.datasource.secondary.url=jdbc:mysql://localhost:3306/test2 -spring.datasource.secondary.jdbc-url=jdbc:mysql://localhost:3306/test2 -spring.datasource.secondary.username=root -spring.datasource.secondary.password=123456 -spring.datasource.secondary.driver-class-name=com.mysql.cj.jdbc.Driver \ No newline at end of file diff --git a/2.1.x/chapter3-7/src/test/java/com/didispace/chapter37/Chapter37ApplicationTests.java b/2.1.x/chapter3-7/src/test/java/com/didispace/chapter37/Chapter37ApplicationTests.java deleted file mode 100644 index 5aa8a72f..00000000 --- a/2.1.x/chapter3-7/src/test/java/com/didispace/chapter37/Chapter37ApplicationTests.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.didispace.chapter37; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.junit4.SpringRunner; - - -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter37ApplicationTests { - - @Autowired - protected JdbcTemplate primaryJdbcTemplate; - - @Autowired - protected JdbcTemplate secondaryJdbcTemplate; - - @Before - public void setUp() { - primaryJdbcTemplate.update("DELETE FROM USER "); - secondaryJdbcTemplate.update("DELETE FROM USER "); - } - - @Test - public void test() throws Exception { - // 往第一个数据源中插入 2 条数据 - primaryJdbcTemplate.update("insert into user(name,age) values(?, ?)", "aaa", 20); - primaryJdbcTemplate.update("insert into user(name,age) values(?, ?)", "bbb", 30); - - // 往第二个数据源中插入 1 条数据,若插入的是第一个数据源,则会主键冲突报错 - secondaryJdbcTemplate.update("insert into user(name,age) values(?, ?)", "ccc", 20); - - // 查一下第一个数据源中是否有 2 条数据,验证插入是否成功 - Assert.assertEquals("2", primaryJdbcTemplate.queryForObject("select count(1) from user", String.class)); - - // 查一下第一个数据源中是否有 1 条数据,验证插入是否成功 - Assert.assertEquals("1", secondaryJdbcTemplate.queryForObject("select count(1) from user", String.class)); - } - -} diff --git a/2.1.x/chapter3-8/.gitignore b/2.1.x/chapter3-8/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-8/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-8/pom.xml b/2.1.x/chapter3-8/pom.xml deleted file mode 100644 index cd677906..00000000 --- a/2.1.x/chapter3-8/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-8 - 0.0.1-SNAPSHOT - 使用spring-data-jpa的多数据源配置 - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/Chapter38Application.java b/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/Chapter38Application.java deleted file mode 100644 index d2e5f499..00000000 --- a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/Chapter38Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter38; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@SpringBootApplication -public class Chapter38Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter38Application.class, args); - } - -} diff --git a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/DataSourceConfiguration.java b/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/DataSourceConfiguration.java deleted file mode 100644 index 6470beb6..00000000 --- a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/DataSourceConfiguration.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.didispace.chapter38; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.jdbc.core.JdbcTemplate; - -import javax.sql.DataSource; - -@Configuration -public class DataSourceConfiguration { - - @Primary - @Bean - @ConfigurationProperties(prefix = "spring.datasource.primary") - public DataSource primaryDataSource() { - return DataSourceBuilder.create().build(); - } - - @Bean - @ConfigurationProperties(prefix = "spring.datasource.secondary") - public DataSource secondaryDataSource() { - return DataSourceBuilder.create().build(); - } - -} diff --git a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/PrimaryConfig.java b/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/PrimaryConfig.java deleted file mode 100644 index 3bcfadc0..00000000 --- a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/PrimaryConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.didispace.chapter38; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings; -import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; -import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.persistence.EntityManager; -import javax.sql.DataSource; -import java.util.Map; - -@Configuration -@EnableTransactionManagement -@EnableJpaRepositories( - entityManagerFactoryRef="entityManagerFactoryPrimary", - transactionManagerRef="transactionManagerPrimary", - basePackages= { "com.didispace.chapter38.p" }) //设置Repository所在位置 -public class PrimaryConfig { - - @Autowired - @Qualifier("primaryDataSource") - private DataSource primaryDataSource; - - @Autowired - private JpaProperties jpaProperties; - @Autowired - private HibernateProperties hibernateProperties; - - private Map getVendorProperties() { - return hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings()); - } - - @Primary - @Bean(name = "entityManagerPrimary") - public EntityManager entityManager(EntityManagerFactoryBuilder builder) { - return entityManagerFactoryPrimary(builder).getObject().createEntityManager(); - } - - @Primary - @Bean(name = "entityManagerFactoryPrimary") - public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary (EntityManagerFactoryBuilder builder) { -// HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); -// jpaVendorAdapter.setGenerateDdl(true); - return builder - .dataSource(primaryDataSource) - .packages("com.didispace.chapter38.p") //设置实体类所在位置 - .persistenceUnit("primaryPersistenceUnit") - .properties(getVendorProperties()) - .build(); - } - - @Primary - @Bean(name = "transactionManagerPrimary") - public PlatformTransactionManager transactionManagerPrimary(EntityManagerFactoryBuilder builder) { - return new JpaTransactionManager(entityManagerFactoryPrimary(builder).getObject()); - } - - -} \ No newline at end of file diff --git a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/SecondaryConfig.java b/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/SecondaryConfig.java deleted file mode 100644 index 7b8df6a3..00000000 --- a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/SecondaryConfig.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.didispace.chapter38; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings; -import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; -import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.persistence.EntityManager; -import javax.sql.DataSource; -import java.util.Map; - -@Configuration -@EnableTransactionManagement -@EnableJpaRepositories( - entityManagerFactoryRef="entityManagerFactorySecondary", - transactionManagerRef="transactionManagerSecondary", - basePackages= { "com.didispace.chapter38.s" }) //设置Repository所在位置 -public class SecondaryConfig { - - @Autowired - @Qualifier("secondaryDataSource") - private DataSource secondaryDataSource; - - @Autowired - private JpaProperties jpaProperties; - @Autowired - private HibernateProperties hibernateProperties; - - private Map getVendorProperties() { - return hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings()); - } - - @Bean(name = "entityManagerSecondary") - public EntityManager entityManager(EntityManagerFactoryBuilder builder) { - return entityManagerFactorySecondary(builder).getObject().createEntityManager(); - } - - @Bean(name = "entityManagerFactorySecondary") - public LocalContainerEntityManagerFactoryBean entityManagerFactorySecondary (EntityManagerFactoryBuilder builder) { - return builder - .dataSource(secondaryDataSource) - .packages("com.didispace.chapter38.s") //设置实体类所在位置 - .persistenceUnit("secondaryPersistenceUnit") - .properties(getVendorProperties()) - .build(); - } - - @Bean(name = "transactionManagerSecondary") - PlatformTransactionManager transactionManagerSecondary(EntityManagerFactoryBuilder builder) { - return new JpaTransactionManager(entityManagerFactorySecondary(builder).getObject()); - } - -} \ No newline at end of file diff --git a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/p/User.java b/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/p/User.java deleted file mode 100644 index 83aaf3c9..00000000 --- a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/p/User.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.didispace.chapter38.p; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -@Data -@NoArgsConstructor -public class User { - - @Id - @GeneratedValue - private Long id; - - private String name; - private Integer age; - - public User(String name, Integer age) { - this.name = name; - this.age = age; - } -} \ No newline at end of file diff --git a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/p/UserRepository.java b/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/p/UserRepository.java deleted file mode 100644 index e91080e1..00000000 --- a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/p/UserRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter38.p; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -/** - * Created by 程序猿DD/翟永超 on 2020/6/22. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -public interface UserRepository extends JpaRepository { - -} diff --git a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/s/Message.java b/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/s/Message.java deleted file mode 100644 index 956178b8..00000000 --- a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/s/Message.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.didispace.chapter38.s; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -@Data -@NoArgsConstructor -public class Message { - - @Id - @GeneratedValue - private Long id; - - private String title; - private String message; - - public Message(String title, String message) { - this.title = title; - this.message = message; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/s/MessageRepository.java b/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/s/MessageRepository.java deleted file mode 100644 index 13360488..00000000 --- a/2.1.x/chapter3-8/src/main/java/com/didispace/chapter38/s/MessageRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.didispace.chapter38.s; - -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * Created by 程序猿DD/翟永超 on 2020/6/22. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -public interface MessageRepository extends JpaRepository { - - -} diff --git a/2.1.x/chapter3-8/src/main/resources/application.properties b/2.1.x/chapter3-8/src/main/resources/application.properties deleted file mode 100644 index 0d82f6cd..00000000 --- a/2.1.x/chapter3-8/src/main/resources/application.properties +++ /dev/null @@ -1,16 +0,0 @@ -# pring boot 1.x的配置:spring.datasource.primary.url=jdbc:mysql://localhost:3306/test1 -spring.datasource.primary.jdbc-url=jdbc:mysql://localhost:3306/test1 -spring.datasource.primary.username=root -spring.datasource.primary.password=12345678 -spring.datasource.primary.driver-class-name=com.mysql.cj.jdbc.Driver - -# spring boot 1.x的配置:spring.datasource.secondary.url=jdbc:mysql://localhost:3306/test2 -spring.datasource.secondary.jdbc-url=jdbc:mysql://localhost:3306/test2 -spring.datasource.secondary.username=root -spring.datasource.secondary.password=12345678 -spring.datasource.secondary.driver-class-name=com.mysql.cj.jdbc.Driver - -# 日志打印执行的SQL -spring.jpa.show-sql=true -# Hibernate的DDL策略 -spring.jpa.hibernate.ddl-auto=create-drop diff --git a/2.1.x/chapter3-8/src/test/java/com/didispace/chapter38/Chapter38ApplicationTests.java b/2.1.x/chapter3-8/src/test/java/com/didispace/chapter38/Chapter38ApplicationTests.java deleted file mode 100644 index 9c9ef3e7..00000000 --- a/2.1.x/chapter3-8/src/test/java/com/didispace/chapter38/Chapter38ApplicationTests.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.didispace.chapter38; - -import com.didispace.chapter38.p.User; -import com.didispace.chapter38.p.UserRepository; -import com.didispace.chapter38.s.Message; -import com.didispace.chapter38.s.MessageRepository; -import lombok.extern.slf4j.Slf4j; -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.test.context.junit4.SpringRunner; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter38ApplicationTests { - - @Autowired - private UserRepository userRepository; - @Autowired - private MessageRepository messageRepository; - - @Test - public void test() throws Exception { - userRepository.save(new User("aaa", 10)); - userRepository.save(new User("bbb", 20)); - userRepository.save(new User("ccc", 30)); - userRepository.save(new User("ddd", 40)); - userRepository.save(new User("eee", 50)); - - Assert.assertEquals(5, userRepository.findAll().size()); - - messageRepository.save(new Message("o1", "aaaaaaaaaa")); - messageRepository.save(new Message("o2", "bbbbbbbbbb")); - messageRepository.save(new Message("o3", "cccccccccc")); - - Assert.assertEquals(3, messageRepository.findAll().size()); - } - -} diff --git a/2.1.x/chapter3-9/.gitignore b/2.1.x/chapter3-9/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter3-9/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter3-9/pom.xml b/2.1.x/chapter3-9/pom.xml deleted file mode 100644 index f8572620..00000000 --- a/2.1.x/chapter3-9/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter3-9 - 0.0.1-SNAPSHOT - 使用MyBatis的多数据源配置 - - - 1.8 - - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 2.1.1 - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/Chapter39Application.java b/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/Chapter39Application.java deleted file mode 100644 index eb46b057..00000000 --- a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/Chapter39Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter39; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter39Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter39Application.class, args); - } - -} diff --git a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/DataSourceConfiguration.java b/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/DataSourceConfiguration.java deleted file mode 100644 index 6eaae095..00000000 --- a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/DataSourceConfiguration.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.didispace.chapter39; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -import javax.sql.DataSource; - -@Configuration -public class DataSourceConfiguration { - - @Primary - @Bean - @ConfigurationProperties(prefix = "spring.datasource.primary") - public DataSource primaryDataSource() { - return DataSourceBuilder.create().build(); - } - - @Bean - @ConfigurationProperties(prefix = "spring.datasource.secondary") - public DataSource secondaryDataSource() { - return DataSourceBuilder.create().build(); - } - -} diff --git a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/PrimaryConfig.java b/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/PrimaryConfig.java deleted file mode 100644 index f6d1bbe5..00000000 --- a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/PrimaryConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.didispace.chapter39; - -import org.apache.ibatis.session.SqlSessionFactory; -import org.mybatis.spring.SqlSessionFactoryBean; -import org.mybatis.spring.SqlSessionTemplate; -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.sql.DataSource; - -@Configuration -@MapperScan( - basePackages = "com.didispace.chapter39.p", - sqlSessionFactoryRef = "sqlSessionFactoryPrimary", - sqlSessionTemplateRef = "sqlSessionTemplatePrimary") -public class PrimaryConfig { - - private DataSource primaryDataSource; - - public PrimaryConfig(@Qualifier("primaryDataSource") DataSource primaryDataSource) { - this.primaryDataSource = primaryDataSource; - } - - @Bean - public SqlSessionFactory sqlSessionFactoryPrimary() throws Exception { - SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); - bean.setDataSource(primaryDataSource); - return bean.getObject(); - } - - @Bean - public SqlSessionTemplate sqlSessionTemplatePrimary() throws Exception { - return new SqlSessionTemplate(sqlSessionFactoryPrimary()); - } - -} \ No newline at end of file diff --git a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/SecondaryConfig.java b/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/SecondaryConfig.java deleted file mode 100644 index bdb17fba..00000000 --- a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/SecondaryConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.didispace.chapter39; - -import org.apache.ibatis.session.SqlSessionFactory; -import org.mybatis.spring.SqlSessionFactoryBean; -import org.mybatis.spring.SqlSessionTemplate; -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.sql.DataSource; - -@Configuration -@MapperScan( - basePackages = "com.didispace.chapter39.s", - sqlSessionFactoryRef = "sqlSessionFactorySecondary", - sqlSessionTemplateRef = "sqlSessionTemplateSecondary") -public class SecondaryConfig { - - private DataSource secondaryDataSource; - - public SecondaryConfig(@Qualifier("secondaryDataSource") DataSource secondaryDataSource) { - this.secondaryDataSource = secondaryDataSource; - } - - @Bean - public SqlSessionFactory sqlSessionFactorySecondary() throws Exception { - SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); - bean.setDataSource(secondaryDataSource); - return bean.getObject(); - } - - @Bean - public SqlSessionTemplate sqlSessionTemplateSecondary() throws Exception { - return new SqlSessionTemplate(sqlSessionFactorySecondary()); - } - -} \ No newline at end of file diff --git a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/p/entity/UserPrimary.java b/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/p/entity/UserPrimary.java deleted file mode 100644 index f4c2a299..00000000 --- a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/p/entity/UserPrimary.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.didispace.chapter39.p.entity; - -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -public class UserPrimary { - - private Long id; - - private String name; - private Integer age; - - public UserPrimary(String name, Integer age) { - this.name = name; - this.age = age; - } -} \ No newline at end of file diff --git a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/p/mapper/UserMapperPrimary.java b/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/p/mapper/UserMapperPrimary.java deleted file mode 100644 index 869ab546..00000000 --- a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/p/mapper/UserMapperPrimary.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.didispace.chapter39.p.mapper; - -import com.didispace.chapter39.p.entity.UserPrimary; -import org.apache.ibatis.annotations.Delete; -import org.apache.ibatis.annotations.Insert; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -/** - * Created by 程序猿DD/翟永超 on 2020/2/28. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -public interface UserMapperPrimary { - - @Select("SELECT * FROM USER WHERE NAME = #{name}") - UserPrimary findByName(@Param("name") String name); - - @Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})") - int insert(@Param("name") String name, @Param("age") Integer age); - - @Delete("DELETE FROM USER") - int deleteAll(); - -} diff --git a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/s/entity/UserSecondary.java b/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/s/entity/UserSecondary.java deleted file mode 100644 index fdd64dff..00000000 --- a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/s/entity/UserSecondary.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.didispace.chapter39.s.entity; - -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -public class UserSecondary { - - private Long id; - - private String name; - private Integer age; - - public UserSecondary(String name, Integer age) { - this.name = name; - this.age = age; - } -} \ No newline at end of file diff --git a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/s/mapper/UserMapperSecondary.java b/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/s/mapper/UserMapperSecondary.java deleted file mode 100644 index bb4b004c..00000000 --- a/2.1.x/chapter3-9/src/main/java/com/didispace/chapter39/s/mapper/UserMapperSecondary.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.didispace.chapter39.s.mapper; - -import com.didispace.chapter39.s.entity.UserSecondary; -import org.apache.ibatis.annotations.Delete; -import org.apache.ibatis.annotations.Insert; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -/** - * Created by 程序猿DD/翟永超 on 2020/2/28. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -public interface UserMapperSecondary { - - @Select("SELECT * FROM USER WHERE NAME = #{name}") - UserSecondary findByName(@Param("name") String name); - - @Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})") - int insert(@Param("name") String name, @Param("age") Integer age); - - @Delete("DELETE FROM USER") - int deleteAll(); -} diff --git a/2.1.x/chapter3-9/src/main/resources/application.properties b/2.1.x/chapter3-9/src/main/resources/application.properties deleted file mode 100644 index 87777023..00000000 --- a/2.1.x/chapter3-9/src/main/resources/application.properties +++ /dev/null @@ -1,13 +0,0 @@ -# pring boot 1.x的配置:spring.datasource.primary.url=jdbc:mysql://localhost:3306/test1 -spring.datasource.primary.jdbc-url=jdbc:mysql://localhost:3306/test1 -spring.datasource.primary.username=root -spring.datasource.primary.password=12345678 -spring.datasource.primary.driver-class-name=com.mysql.cj.jdbc.Driver - -# spring boot 1.x的配置:spring.datasource.secondary.url=jdbc:mysql://localhost:3306/test2 -spring.datasource.secondary.jdbc-url=jdbc:mysql://localhost:3306/test2 -spring.datasource.secondary.username=root -spring.datasource.secondary.password=12345678 -spring.datasource.secondary.driver-class-name=com.mysql.cj.jdbc.Driver - -#mybatis.mapper-locations=classpath:mapper/*.xml diff --git a/2.1.x/chapter3-9/src/main/resources/mapper.primary/UserMapper.xml b/2.1.x/chapter3-9/src/main/resources/mapper.primary/UserMapper.xml deleted file mode 100644 index 6eae360b..00000000 --- a/2.1.x/chapter3-9/src/main/resources/mapper.primary/UserMapper.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age}) - - - \ No newline at end of file diff --git a/2.1.x/chapter3-9/src/main/resources/mapper.secondary/UserMapper.xml b/2.1.x/chapter3-9/src/main/resources/mapper.secondary/UserMapper.xml deleted file mode 100644 index 361cd16e..00000000 --- a/2.1.x/chapter3-9/src/main/resources/mapper.secondary/UserMapper.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age}) - - - \ No newline at end of file diff --git a/2.1.x/chapter3-9/src/test/java/com/didispace/chapter39/Chapter39ApplicationTests.java b/2.1.x/chapter3-9/src/test/java/com/didispace/chapter39/Chapter39ApplicationTests.java deleted file mode 100644 index a1bd3a81..00000000 --- a/2.1.x/chapter3-9/src/test/java/com/didispace/chapter39/Chapter39ApplicationTests.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.didispace.chapter39; - -import com.didispace.chapter39.p.entity.UserPrimary; -import com.didispace.chapter39.p.mapper.UserMapperPrimary; -import com.didispace.chapter39.s.entity.UserSecondary; -import com.didispace.chapter39.s.mapper.UserMapperSecondary; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.Before; -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 org.springframework.transaction.annotation.Transactional; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -@Transactional -public class Chapter39ApplicationTests { - - @Autowired - private UserMapperPrimary userMapperPrimary; - @Autowired - private UserMapperSecondary userMapperSecondary; - - @Before - public void setUp() { - // 清空测试表,保证每次结果一样 - userMapperPrimary.deleteAll(); - userMapperSecondary.deleteAll(); - } - - @Test - public void test() throws Exception { - // 往Primary数据源插入一条数据 - userMapperPrimary.insert("AAA", 20); - - // 从Primary数据源查询刚才插入的数据,配置正确就可以查询到 - UserPrimary userPrimary = userMapperPrimary.findByName("AAA"); - Assert.assertEquals(20, userPrimary.getAge().intValue()); - - // 从Secondary数据源查询刚才插入的数据,配置正确应该是查询不到的 - UserSecondary userSecondary = userMapperSecondary.findByName("AAA"); - Assert.assertNull(userSecondary); - - // 往Secondary数据源插入一条数据 - userMapperSecondary.insert("BBB", 20); - - // 从Primary数据源查询刚才插入的数据,配置正确应该是查询不到的 - userPrimary = userMapperPrimary.findByName("BBB"); - Assert.assertNull(userPrimary); - - // 从Secondary数据源查询刚才插入的数据,配置正确就可以查询到 - userSecondary = userMapperSecondary.findByName("BBB"); - Assert.assertEquals(20, userSecondary.getAge().intValue()); - } - -} diff --git a/2.1.x/chapter4-1/.gitignore b/2.1.x/chapter4-1/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter4-1/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter4-1/pom.xml b/2.1.x/chapter4-1/pom.xml deleted file mode 100644 index e8191b85..00000000 --- a/2.1.x/chapter4-1/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter4-1 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter4-1/src/main/java/com/didispace/chapter41/Chapter41Application.java b/2.1.x/chapter4-1/src/main/java/com/didispace/chapter41/Chapter41Application.java deleted file mode 100644 index 8ec9c806..00000000 --- a/2.1.x/chapter4-1/src/main/java/com/didispace/chapter41/Chapter41Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter41; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter41Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter41Application.class, args); - } - -} diff --git a/2.1.x/chapter4-1/src/main/java/com/didispace/chapter41/HelloController.java b/2.1.x/chapter4-1/src/main/java/com/didispace/chapter41/HelloController.java deleted file mode 100644 index 314074d1..00000000 --- a/2.1.x/chapter4-1/src/main/java/com/didispace/chapter41/HelloController.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.didispace.chapter41; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; - -@Controller -public class HelloController { - - @GetMapping("/") - public String index(ModelMap map) { - // 加入一个属性,用来在模板中读取 - map.addAttribute("host", "http://blog.didispace.com/"); - - // return模板文件的名称,对应src/main/resources/templates/index.html - return "index"; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter4-1/src/main/resources/application.properties b/2.1.x/chapter4-1/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/2.1.x/chapter4-1/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/2.1.x/chapter4-1/src/main/resources/templates/index.html b/2.1.x/chapter4-1/src/main/resources/templates/index.html deleted file mode 100644 index 32cbfe84..00000000 --- a/2.1.x/chapter4-1/src/main/resources/templates/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - -

Hello World

- - \ No newline at end of file diff --git a/2.1.x/chapter4-2/.gitignore b/2.1.x/chapter4-2/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter4-2/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter4-2/pom.xml b/2.1.x/chapter4-2/pom.xml deleted file mode 100644 index d6022db9..00000000 --- a/2.1.x/chapter4-2/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter4-2 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter4-2/src/main/java/com/didispace/chapter42/Chapter42Application.java b/2.1.x/chapter4-2/src/main/java/com/didispace/chapter42/Chapter42Application.java deleted file mode 100644 index 00b646c5..00000000 --- a/2.1.x/chapter4-2/src/main/java/com/didispace/chapter42/Chapter42Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.didispace.chapter42; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Chapter42Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter42Application.class, args); - } - -} diff --git a/2.1.x/chapter4-2/src/main/java/com/didispace/chapter42/HelloController.java b/2.1.x/chapter4-2/src/main/java/com/didispace/chapter42/HelloController.java deleted file mode 100644 index 0e01264b..00000000 --- a/2.1.x/chapter4-2/src/main/java/com/didispace/chapter42/HelloController.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.didispace.chapter42; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; - -@Controller -public class HelloController { - - @GetMapping("/") - public String index(ModelMap map) { - // return模板文件的名称,对应src/main/resources/templates/index.html - return "index"; - } - -} \ No newline at end of file diff --git a/2.1.x/chapter4-2/src/main/resources/application.properties b/2.1.x/chapter4-2/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/2.1.x/chapter4-2/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/2.1.x/chapter4-2/src/main/resources/templates/index.html b/2.1.x/chapter4-2/src/main/resources/templates/index.html deleted file mode 100644 index 7c8a648b..00000000 --- a/2.1.x/chapter4-2/src/main/resources/templates/index.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - Spring Boot中使用ECharts - - - -
- - - - \ No newline at end of file diff --git a/2.1.x/chapter5-1/.gitignore b/2.1.x/chapter5-1/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter5-1/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter5-1/pom.xml b/2.1.x/chapter5-1/pom.xml deleted file mode 100644 index 2af64776..00000000 --- a/2.1.x/chapter5-1/pom.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter5-1 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-cache - - - - org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/Chapter51Application.java b/2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/Chapter51Application.java deleted file mode 100644 index b855c592..00000000 --- a/2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/Chapter51Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter51; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cache.annotation.EnableCaching; - -@EnableCaching -@SpringBootApplication -public class Chapter51Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter51Application.class, args); - } - -} diff --git a/2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/User.java b/2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/User.java deleted file mode 100644 index 55ae4a76..00000000 --- a/2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/User.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.didispace.chapter51; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -@Data -@NoArgsConstructor -public class User { - - @Id - @GeneratedValue - private Long id; - - private String name; - private Integer age; - - public User(String name, Integer age) { - this.name = name; - this.age = age; - } -} \ No newline at end of file diff --git a/2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/UserRepository.java b/2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/UserRepository.java deleted file mode 100644 index 2785e7ae..00000000 --- a/2.1.x/chapter5-1/src/main/java/com/didispace/chapter51/UserRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.didispace.chapter51; - -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -/** - * Created by 程序猿DD/翟永超 on 2020/7/13. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -@CacheConfig(cacheNames = "users") -public interface UserRepository extends JpaRepository { - - @Cacheable - User findByName(String name); - - User findByNameAndAge(String name, Integer age); - - @Query("from User u where u.name=:name") - User findUser(@Param("name") String name); - -} diff --git a/2.1.x/chapter5-1/src/main/resources/application.properties b/2.1.x/chapter5-1/src/main/resources/application.properties deleted file mode 100644 index ba1e5990..00000000 --- a/2.1.x/chapter5-1/src/main/resources/application.properties +++ /dev/null @@ -1,7 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password=12345678 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - -spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=create-drop \ No newline at end of file diff --git a/2.1.x/chapter5-1/src/test/java/com/didispace/chapter51/Chapter51ApplicationTests.java b/2.1.x/chapter5-1/src/test/java/com/didispace/chapter51/Chapter51ApplicationTests.java deleted file mode 100644 index 3d4dabbd..00000000 --- a/2.1.x/chapter5-1/src/test/java/com/didispace/chapter51/Chapter51ApplicationTests.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.didispace.chapter51; - -import lombok.extern.slf4j.Slf4j; -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.cache.CacheManager; -import org.springframework.test.context.junit4.SpringRunner; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter51ApplicationTests { - - @Autowired - private UserRepository userRepository; - - @Autowired - private CacheManager cacheManager; - - @Test - public void test() throws Exception { - // 创建1条记录 - userRepository.save(new User("AAA", 10)); - - User u1 = userRepository.findByName("AAA"); - System.out.println("第一次查询:" + u1.getAge()); - - User u2 = userRepository.findByName("AAA"); - System.out.println("第二次查询:" + u2.getAge()); - } - -} diff --git a/2.1.x/chapter5-2/.gitignore b/2.1.x/chapter5-2/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter5-2/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter5-2/pom.xml b/2.1.x/chapter5-2/pom.xml deleted file mode 100644 index bb82477e..00000000 --- a/2.1.x/chapter5-2/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter5-2 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-cache - - - - net.sf.ehcache - ehcache - - - - org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/Chapter52Application.java b/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/Chapter52Application.java deleted file mode 100644 index e4842885..00000000 --- a/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/Chapter52Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter52; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cache.annotation.EnableCaching; - -@EnableCaching -@SpringBootApplication -public class Chapter52Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter52Application.class, args); - } - -} diff --git a/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/User.java b/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/User.java deleted file mode 100644 index 9fb641f0..00000000 --- a/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/User.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.didispace.chapter52; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -@Data -@NoArgsConstructor -public class User { - - @Id - @GeneratedValue - private Long id; - - private String name; - private Integer age; - - public User(String name, Integer age) { - this.name = name; - this.age = age; - } -} \ No newline at end of file diff --git a/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/UserRepository.java b/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/UserRepository.java deleted file mode 100644 index 4dad3d06..00000000 --- a/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/UserRepository.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.didispace.chapter52; - -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -/** - * Created by 程序猿DD/翟永超 on 2020/7/14. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -@CacheConfig(cacheNames = "users") -public interface UserRepository extends JpaRepository { - - @Cacheable - User findByName(String name); - -} diff --git a/2.1.x/chapter5-2/src/main/resources/application.properties b/2.1.x/chapter5-2/src/main/resources/application.properties deleted file mode 100644 index ba1e5990..00000000 --- a/2.1.x/chapter5-2/src/main/resources/application.properties +++ /dev/null @@ -1,7 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password=12345678 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - -spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=create-drop \ No newline at end of file diff --git a/2.1.x/chapter5-2/src/main/resources/ehcache.xml b/2.1.x/chapter5-2/src/main/resources/ehcache.xml deleted file mode 100644 index c178cc9f..00000000 --- a/2.1.x/chapter5-2/src/main/resources/ehcache.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/2.1.x/chapter5-2/src/test/java/com/didispace/chapter52/Chapter52ApplicationTests.java b/2.1.x/chapter5-2/src/test/java/com/didispace/chapter52/Chapter52ApplicationTests.java deleted file mode 100644 index 76c505c9..00000000 --- a/2.1.x/chapter5-2/src/test/java/com/didispace/chapter52/Chapter52ApplicationTests.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.didispace.chapter52; - -import lombok.extern.slf4j.Slf4j; -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.cache.CacheManager; -import org.springframework.test.context.junit4.SpringRunner; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter52ApplicationTests { - - @Autowired - private UserRepository userRepository; - - @Autowired - private CacheManager cacheManager; - - @Test - public void test() throws Exception { - System.out.println("CacheManager type : " + cacheManager.getClass()); - - // 创建1条记录 - userRepository.save(new User("AAA", 10)); - - User u1 = userRepository.findByName("AAA"); - System.out.println("第一次查询:" + u1.getAge()); - - User u2 = userRepository.findByName("AAA"); - System.out.println("第二次查询:" + u2.getAge()); - } - -} diff --git a/2.1.x/chapter5-3/.gitignore b/2.1.x/chapter5-3/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter5-3/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter5-3/pom.xml b/2.1.x/chapter5-3/pom.xml deleted file mode 100644 index c0bb21fd..00000000 --- a/2.1.x/chapter5-3/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter5-3 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-cache - - - - net.sf.ehcache - ehcache - - - - org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/Chapter53Application.java b/2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/Chapter53Application.java deleted file mode 100644 index 3abe9f33..00000000 --- a/2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/Chapter53Application.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.didispace.chapter53; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cache.annotation.EnableCaching; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.rmi.registry.LocateRegistry; - -@EnableCaching -@SpringBootApplication -public class Chapter53Application { - - public static void main(String[] args) throws Exception { -// LocateRegistry.createRegistry(Integer.valueOf(System.getProperty("rmi.port"))); - SpringApplication.run(Chapter53Application.class, args); - } - - @RestController - static class HelloController { - - @Autowired - private UserRepository userRepository; - - @GetMapping("/create") - public void create() { - userRepository.save(new User("AAA", 10)); - } - - @GetMapping("/update") - public User update() { - User u1 = userRepository.findByName("AAA"); - u1.setAge(20); - u1 = userRepository.save(u1); - return u1; - } - - @GetMapping("/find") - public User find() { - User u1 = userRepository.findByName("AAA"); - System.out.println("查询AAA用户:" + u1.getAge()); - return u1; - } - - } - -} diff --git a/2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/User.java b/2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/User.java deleted file mode 100644 index 2986b7d4..00000000 --- a/2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/User.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.didispace.chapter53; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import java.io.Serializable; - -@Entity -@Data -@NoArgsConstructor -public class User implements Serializable { - - @Id - @GeneratedValue - private Long id; - - private String name; - private Integer age; - - public User(String name, Integer age) { - this.name = name; - this.age = age; - } -} diff --git a/2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/UserRepository.java b/2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/UserRepository.java deleted file mode 100644 index 4d52745e..00000000 --- a/2.1.x/chapter5-3/src/main/java/com/didispace/chapter53/UserRepository.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.didispace.chapter53; - -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -/** - * Created by 程序猿DD/翟永超 on 2020/7/16. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -@CacheConfig(cacheNames = "users") -public interface UserRepository extends JpaRepository { - - @Cacheable - User findByName(String name); - -} diff --git a/2.1.x/chapter5-3/src/main/resources/application.properties b/2.1.x/chapter5-3/src/main/resources/application.properties deleted file mode 100644 index 43e74c79..00000000 --- a/2.1.x/chapter5-3/src/main/resources/application.properties +++ /dev/null @@ -1,17 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password=12345678 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - -spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=create - -#logging.level.net.sf.ehcache=debug - -# 不同实例的配置 -#spring.cache.ehcache.config=classpath:ehcache-1.xml -#spring.cache.ehcache.config=classpath:ehcache-2.xml - -# 用不同命令启动不同实例 -#-Dserver.port=8001 -Dspring.cache.ehcache.config=classpath:ehcache-1.xml -#-Dserver.port=8002 -Dspring.cache.ehcache.config=classpath:ehcache-2.xml diff --git a/2.1.x/chapter5-3/src/main/resources/ehcache-1.xml b/2.1.x/chapter5-3/src/main/resources/ehcache-1.xml deleted file mode 100644 index fbc88162..00000000 --- a/2.1.x/chapter5-3/src/main/resources/ehcache-1.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/2.1.x/chapter5-3/src/main/resources/ehcache-2.xml b/2.1.x/chapter5-3/src/main/resources/ehcache-2.xml deleted file mode 100644 index 878b6be2..00000000 --- a/2.1.x/chapter5-3/src/main/resources/ehcache-2.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/2.1.x/chapter5-3/src/test/java/com/didispace/chapter53/Chapter53ApplicationTests.java b/2.1.x/chapter5-3/src/test/java/com/didispace/chapter53/Chapter53ApplicationTests.java deleted file mode 100644 index 0e9c2939..00000000 --- a/2.1.x/chapter5-3/src/test/java/com/didispace/chapter53/Chapter53ApplicationTests.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.didispace.chapter53; - -import lombok.extern.slf4j.Slf4j; -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.cache.CacheManager; -import org.springframework.test.context.junit4.SpringRunner; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter53ApplicationTests { - - @Autowired - private UserRepository userRepository; - - @Autowired - private CacheManager cacheManager; - - @Test - public void test() throws Exception { - System.out.println("CacheManager type : " + cacheManager.getClass()); - - // 创建1条记录 - userRepository.save(new User("AAA", 10)); - - User u1 = userRepository.findByName("AAA"); - System.out.println("第一次查询:" + u1.getAge()); - - User u2 = userRepository.findByName("AAA"); - System.out.println("第二次查询:" + u2.getAge()); - } - -} diff --git a/2.1.x/chapter5-4/.gitignore b/2.1.x/chapter5-4/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/2.1.x/chapter5-4/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/2.1.x/chapter5-4/pom.xml b/2.1.x/chapter5-4/pom.xml deleted file mode 100644 index c33d2854..00000000 --- a/2.1.x/chapter5-4/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.3.RELEASE - - - - com.didispace - chapter5-4 - 0.0.1-SNAPSHOT - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-data-redis - - - - org.apache.commons - commons-pool2 - - - - org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/Chapter54Application.java b/2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/Chapter54Application.java deleted file mode 100644 index f2789f8b..00000000 --- a/2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/Chapter54Application.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.didispace.chapter54; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cache.annotation.EnableCaching; - -@EnableCaching -@SpringBootApplication -public class Chapter54Application { - - public static void main(String[] args) { - SpringApplication.run(Chapter54Application.class, args); - } - -} diff --git a/2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/User.java b/2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/User.java deleted file mode 100644 index 11e2dc13..00000000 --- a/2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/User.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.didispace.chapter54; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import java.io.Serializable; - -@Entity -@Data -@NoArgsConstructor -public class User implements Serializable { - - @Id - @GeneratedValue - private Long id; - - private String name; - private Integer age; - - public User(String name, Integer age) { - this.name = name; - this.age = age; - } -} \ No newline at end of file diff --git a/2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/UserRepository.java b/2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/UserRepository.java deleted file mode 100644 index 4b14b113..00000000 --- a/2.1.x/chapter5-4/src/main/java/com/didispace/chapter54/UserRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.didispace.chapter54; - -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -/** - * Created by 程序猿DD/翟永超 on 2020/7/26. - *

- * Blog: http://blog.didispace.com/ - * Github: https://github.com/dyc87112/ - */ -@CacheConfig(cacheNames = "users") -public interface UserRepository extends JpaRepository { - - @Cacheable - User findByName(String name); - - User findByNameAndAge(String name, Integer age); - - @Query("from User u where u.name=:name") - User findUser(@Param("name") String name); - -} diff --git a/2.1.x/chapter5-4/src/main/resources/application.properties b/2.1.x/chapter5-4/src/main/resources/application.properties deleted file mode 100644 index 7136291e..00000000 --- a/2.1.x/chapter5-4/src/main/resources/application.properties +++ /dev/null @@ -1,16 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/test -spring.datasource.username=root -spring.datasource.password=12345678 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - -spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect -spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=create-drop - -spring.redis.host=localhost -spring.redis.port=6379 -spring.redis.lettuce.pool.max-idle=8 -spring.redis.lettuce.pool.max-active=8 -spring.redis.lettuce.pool.max-wait=-1ms -spring.redis.lettuce.pool.min-idle=0 -spring.redis.lettuce.shutdown-timeout=100ms diff --git a/2.1.x/chapter5-4/src/test/java/com/didispace/chapter54/Chapter54ApplicationTests.java b/2.1.x/chapter5-4/src/test/java/com/didispace/chapter54/Chapter54ApplicationTests.java deleted file mode 100644 index de5a7185..00000000 --- a/2.1.x/chapter5-4/src/test/java/com/didispace/chapter54/Chapter54ApplicationTests.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.didispace.chapter54; - -import lombok.extern.slf4j.Slf4j; -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.cache.CacheManager; -import org.springframework.test.context.junit4.SpringRunner; - -@Slf4j -@RunWith(SpringRunner.class) -@SpringBootTest -public class Chapter54ApplicationTests { - - @Autowired - private UserRepository userRepository; - - @Autowired - private CacheManager cacheManager; - - @Test - public void test() throws Exception { - System.out.println("CacheManager type : " + cacheManager.getClass()); - - // 创建1条记录 - userRepository.save(new User("AAA", 10)); - - User u1 = userRepository.findByName("AAA"); - System.out.println("第一次查询:" + u1.getAge()); - - User u2 = userRepository.findByName("AAA"); - System.out.println("第二次查询:" + u2.getAge()); - } - -} diff --git a/2.1.x/pom.xml b/2.1.x/pom.xml deleted file mode 100644 index 26b0293f..00000000 --- a/2.1.x/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - 4.0.0 - - com.didispace - SpringBoot-Learning - 2.0-SNAPSHOT - 全网Star最多的Spring Boot基础教程 - - - - chapter1-1 - - - chapter2-1 - chapter2-2 - chapter2-3 - chapter2-4 - chapter2-5 - chapter2-6 - chapter2-7 - - - - chapter3-1 - chapter3-2 - chapter3-3 - chapter3-4 - chapter3-5 - chapter3-6 - chapter3-7 - chapter3-8 - chapter3-9 - chapter3-10 - - - - - - chapter4-1 - chapter4-2 - - - chapter5-1 - chapter5-2 - chapter5-3 - chapter5-4 - - - - - - - - - - - - From bc2766b18bce90804ce04e4b184ea855f5d0146c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Fri, 8 Oct 2021 16:43:42 +0800 Subject: [PATCH 84/97] =?UTF-8?q?Spring=20Boot=202.x=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=95=99=E7=A8=8B=EF=BC=9A=E4=BD=BF=E7=94=A8PostgreSQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 1 + 2.x/README_zh.md | 2 +- 2.x/chapter6-4/pom.xml | 65 +++++++++++++++++++ .../chapter64/Chapter64Application.java | 14 ++++ .../com/didispace/chapter64/UserInfo.java | 26 ++++++++ .../chapter64/UserInfoRepository.java | 22 +++++++ .../src/main/resources/application.properties | 7 ++ .../didispace/chapter64/ApplicationTests.java | 51 +++++++++++++++ 2.x/pom.xml | 5 +- 9 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 2.x/chapter6-4/pom.xml create mode 100644 2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java create mode 100644 2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java create mode 100644 2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfoRepository.java create mode 100644 2.x/chapter6-4/src/main/resources/application.properties create mode 100644 2.x/chapter6-4/src/test/java/com/didispace/chapter64/ApplicationTests.java diff --git a/2.x/README.md b/2.x/README.md index a6627efd..ab41abb3 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -72,6 +72,7 @@ - [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) - [Spring Boot 2.x基础教程:使用LDAP来管理用户与组织数据](http://blog.didispace.com/spring-boot-learning-24-6-2/) - [Spring Boot 2.x基础教程:使用时序数据库InfluxDB](http://blog.didispace.com/spring-boot-learning-2-6-3/) +- [Spring Boot 2.x基础教程:使用PostgreSQL](http://blog.didispace.com/spring-boot-learning-2-6-4/) ### Web开发 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index fd94ee25..0f3471d0 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -73,7 +73,7 @@ - [Spring Boot 2.x基础教程:使用MongoDB](http://blog.didispace.com/spring-boot-learning-24-6-1/) - [Spring Boot 2.x基础教程:使用LDAP来管理用户与组织数据](http://blog.didispace.com/spring-boot-learning-24-6-2/) - [Spring Boot 2.x基础教程:使用时序数据库InfluxDB](http://blog.didispace.com/spring-boot-learning-2-6-3/) - +- [Spring Boot 2.x基础教程:使用PostgreSQL](http://blog.didispace.com/spring-boot-learning-2-6-4/) ### Web开发 diff --git a/2.x/chapter6-4/pom.xml b/2.x/chapter6-4/pom.xml new file mode 100644 index 00000000..c1683b06 --- /dev/null +++ b/2.x/chapter6-4/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + com.didispace + chapter6-4 + 1.0.0 + jar + 使用PostgreSQL数据库 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + + UTF-8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.postgresql + postgresql + runtime + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java new file mode 100644 index 00000000..83ebf477 --- /dev/null +++ b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java @@ -0,0 +1,14 @@ +package com.didispace.chapter64; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication +public class Chapter64Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter64Application.class, args); + } + +} diff --git a/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java new file mode 100644 index 00000000..cc83d361 --- /dev/null +++ b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java @@ -0,0 +1,26 @@ +package com.didispace.chapter64; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +@Data +@NoArgsConstructor +public class UserInfo { + + @Id + @GeneratedValue + private Long id; + + private String name; + private Integer age; + + public UserInfo(String name, Integer age) { + this.name = name; + this.age = age; + } +} \ No newline at end of file diff --git a/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfoRepository.java b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfoRepository.java new file mode 100644 index 00000000..85214e24 --- /dev/null +++ b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfoRepository.java @@ -0,0 +1,22 @@ +package com.didispace.chapter64; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +/** + * Created by 程序猿DD/翟永超 on 2021/10/08. + *

+ * Blog: http://blog.didispace.com/ + * Github: https://github.com/dyc87112/ + */ +public interface UserInfoRepository extends JpaRepository { + + UserInfo findByName(String name); + + UserInfo findByNameAndAge(String name, Integer age); + + @Query("from UserInfo u where u.name=:name") + UserInfo findUser(@Param("name") String name); + +} diff --git a/2.x/chapter6-4/src/main/resources/application.properties b/2.x/chapter6-4/src/main/resources/application.properties new file mode 100644 index 00000000..3c000bf2 --- /dev/null +++ b/2.x/chapter6-4/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.datasource.url=jdbc:postgresql://localhost:5432/test +spring.datasource.username=postgres +spring.datasource.password=123456 +spring.datasource.driver-class-name=org.postgresql.Driver + +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.properties.hibernate.hbm2ddl.auto=create \ No newline at end of file diff --git a/2.x/chapter6-4/src/test/java/com/didispace/chapter64/ApplicationTests.java b/2.x/chapter6-4/src/test/java/com/didispace/chapter64/ApplicationTests.java new file mode 100644 index 00000000..1ae64fb4 --- /dev/null +++ b/2.x/chapter6-4/src/test/java/com/didispace/chapter64/ApplicationTests.java @@ -0,0 +1,51 @@ +package com.didispace.chapter64; + + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@Slf4j +@SpringBootTest +public class ApplicationTests { + + @Autowired + private UserInfoRepository userRepository; + + @Test + public void test() throws Exception { + // 创建10条记录 + userRepository.save(new UserInfo("AAA", 10)); + userRepository.save(new UserInfo("BBB", 20)); + userRepository.save(new UserInfo("CCC", 30)); + userRepository.save(new UserInfo("DDD", 40)); + userRepository.save(new UserInfo("EEE", 50)); + userRepository.save(new UserInfo("FFF", 60)); + userRepository.save(new UserInfo("GGG", 70)); + userRepository.save(new UserInfo("HHH", 80)); + userRepository.save(new UserInfo("III", 90)); + userRepository.save(new UserInfo("JJJ", 100)); + + // 测试findAll, 查询所有记录 + Assertions.assertEquals(10, userRepository.findAll().size()); + + // 测试findByName, 查询姓名为FFF的User + Assertions.assertEquals(60, userRepository.findByName("FFF").getAge().longValue()); + + // 测试findUser, 查询姓名为FFF的User + Assertions.assertEquals(60, userRepository.findUser("FFF").getAge().longValue()); + + // 测试findByNameAndAge, 查询姓名为FFF并且年龄为60的User + Assertions.assertEquals("FFF", userRepository.findByNameAndAge("FFF", 60).getName()); + + // 测试删除姓名为AAA的User + userRepository.delete(userRepository.findByName("AAA")); + + // 测试findAll, 查询所有记录, 验证上面的删除是否成功 + Assertions.assertEquals(9, userRepository.findAll().size()); + + } + +} diff --git a/2.x/pom.xml b/2.x/pom.xml index 293aad51..4c21f4b1 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -64,11 +64,12 @@ chapter5-5 - + chapter6-1 chapter6-2 chapter6-3 - + chapter6-4 + chapter7-1 From 68f2ab0dc83e5cf23146f8e387a482347c6503fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Tue, 12 Oct 2021 13:38:03 +0800 Subject: [PATCH 85/97] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 13 ++++++++++--- 2.x/README_zh.md | 12 ++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index ab41abb3..94e15452 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -84,14 +84,17 @@ ### 任务管理 -**定时任务** +**定时任务:`@Scheduled`实现** - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) + +**定时任务:Elastic Job实现** + - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) -**异步任务** +**异步任务:`@Async`实现** - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) @@ -128,7 +131,11 @@ ## 我的公众号 - + + +## 推荐我的书 + +![Spring Boot微服务实战](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png) ## 特别赞助商 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 0f3471d0..aed820b3 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -7,6 +7,7 @@ **加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) **如何支持**: + 1. 关注我的公众号”**程序猿DD**“ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 @@ -85,14 +86,17 @@ ### 任务管理 -**定时任务** +**定时任务:`@Scheduled`实现** - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) + +**定时任务:Elastic Job实现** + - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) -**异步任务** +**异步任务:`@Async`实现** - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) @@ -136,11 +140,11 @@ ## 我的公众号 - + ## 推荐我的书 -![](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png "在这里输入图片标题") +![Spring Boot微服务实战](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png) ## 特别赞助商 From 34c2eb96f3b5000da2443cb253f95fd0c693552b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Fri, 29 Oct 2021 14:52:52 +0800 Subject: [PATCH 86/97] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 32 ++++++---- 2.x/README_zh.md | 32 ++++++---- 2.x/chapter4-5/pom.xml | 63 +++++++++++++++++++ .../com/didispace/chapter45/Application.java | 22 +++++++ .../didispace/chapter45/HelloController.java | 33 ++++++++++ .../chapter45/WebSecurityConfig.java | 36 +++++++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/templates/hello.html | 13 ++++ .../src/main/resources/templates/index.html | 12 ++++ .../src/main/resources/templates/login.html | 21 +++++++ 2.x/pom.xml | 9 +-- 11 files changed, 243 insertions(+), 30 deletions(-) create mode 100644 2.x/chapter4-5/pom.xml create mode 100644 2.x/chapter4-5/src/main/java/com/didispace/chapter45/Application.java create mode 100644 2.x/chapter4-5/src/main/java/com/didispace/chapter45/HelloController.java create mode 100644 2.x/chapter4-5/src/main/java/com/didispace/chapter45/WebSecurityConfig.java create mode 100644 2.x/chapter4-5/src/main/resources/application.properties create mode 100644 2.x/chapter4-5/src/main/resources/templates/hello.html create mode 100644 2.x/chapter4-5/src/main/resources/templates/index.html create mode 100644 2.x/chapter4-5/src/main/resources/templates/login.html diff --git a/2.x/README.md b/2.x/README.md index 94e15452..eb25e406 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -14,20 +14,20 @@ ## 教程目录(2.x版本) -连载中...Star关注支持一下,随时获得更新信息! +本教程内容持续更新连载中!**Star关注**支持一下,随时获得更新信息! -### 基础知识 +### 快速入门 - [Spring Boot 2.x基础教程:版本关系](http://blog.didispace.com/spring-cloud-alibaba-version/) - [Spring Boot 2.x基础教程:快速入门](http://blog.didispace.com/spring-boot-learning-21-1-1/) - [Spring Boot 2.x基础教程:工程结构推荐](http://blog.didispace.com/spring-boot-learning-21-1-2/) -### 配置文件 +### 配置详解 - [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/) -- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化](http://blog.didispace.com/spring-boot-learning-24-1-4/) - [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/) +- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:加密配置中的敏感信息](http://blog.didispace.com/spring-boot-learning-2-1-5/) ### API开发 @@ -56,7 +56,7 @@ - [Spring Boot 2.x基础教程:MyBatis的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-9/) - [Spring Boot 2.x基础教程:事务管理入门](http://blog.didispace.com/spring-boot-learning-21-3-10/) - [Spring Boot 2.x基础教程:使用Flyway管理数据库版本](http://blog.didispace.com/spring-boot-learning-24-3-11/) -- [Spring Boot 2.x基础教程:使用JTA实现分布式事务](http://blog.didispace.com/spring-boot-learning-24-3-12/) +- [Spring Boot 2.x基础教程:使用JTA实现多数据源的事务管理](http://blog.didispace.com/spring-boot-learning-24-3-12/) - [Spring Boot 2.x基础教程:2.5版本后数据脚本初始化的变动](http://blog.didispace.com/spring-boot-learning-25-3-13/) **加速利器:各种缓存的使用** @@ -79,34 +79,40 @@ - [Spring Boot 2.x基础教程:使用 Thymeleaf开发Web页面](http://blog.didispace.com/spring-boot-learning-21-4-1/) - [Spring Boot 2.x基础教程:使用 ECharts 绘制各种华丽的数据图表](http://blog.didispace.com/spring-boot-learning-21-4-2/) - [Spring Boot 2.x基础教程:实现文件上传](http://blog.didispace.com/spring-boot-learning-21-4-3/) -- [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) -- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) +- [Spring Boot 2.x基础教程:多个文件的上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) +- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](http://blog.didispace.com/spring-boot-learning-21-4-5/) ### 任务管理 -**定时任务:`@Scheduled`实现** +**定时任务** - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - -**定时任务:Elastic Job实现** - - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) -**异步任务:`@Async`实现** +**异步任务** - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) - [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) - [Spring Boot 2.x基础教程:配置线程池的拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) -### 常见问题 +### 其他内容 + +- [Spring Boot自定义启动Banner](http://blog.didispace.com/spring-boot-banner/) +- [实现邮件发送:简单邮件、附件邮件、嵌入资源的邮件、模板邮件](http://blog.didispace.com/springbootmailsender/) +- [使用Spring StateMachine框架实现状态机](http://blog.didispace.com/spring-statemachine/) +- [Spring Boot应用的后台运行配置](http://blog.didispace.com/spring-boot-run-backend/) + + +## 问题与思考 - [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) - [为什么启动时候API路径都没了?](http://blog.didispace.com/spring-boot-learning-21-2-6/) - [使用Java 8中LocalDate等时间日期类的问题解决](http://blog.didispace.com/Spring-Boot-And-Feign-Use-localdate/) - [Request header is too large 如何解决?](https://blog.didispace.com/request-header-is-too-large/) +- [Spring Boot自动化配置的利弊及解决之道](http://blog.didispace.com/spring-boot-disable-autoconfig/) ## 版本资讯 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index aed820b3..256943c1 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -16,20 +16,20 @@ ## 教程目录(2.x版本) -连载中...Star关注支持一下,随时获得更新信息! +本教程内容持续更新连载中!**Star关注**支持一下,随时获得更新信息! -### 基础知识 +### 快速入门 - [Spring Boot 2.x基础教程:版本关系](http://blog.didispace.com/spring-cloud-alibaba-version/) - [Spring Boot 2.x基础教程:快速入门](http://blog.didispace.com/spring-boot-learning-21-1-1/) - [Spring Boot 2.x基础教程:工程结构推荐](http://blog.didispace.com/spring-boot-learning-21-1-2/) -### 配置文件 +### 配置详解 - [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/) -- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化](http://blog.didispace.com/spring-boot-learning-24-1-4/) - [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/) +- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:加密配置中的敏感信息](http://blog.didispace.com/spring-boot-learning-2-1-5/) ### API开发 @@ -58,7 +58,7 @@ - [Spring Boot 2.x基础教程:MyBatis的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-9/) - [Spring Boot 2.x基础教程:事务管理入门](http://blog.didispace.com/spring-boot-learning-21-3-10/) - [Spring Boot 2.x基础教程:使用Flyway管理数据库版本](http://blog.didispace.com/spring-boot-learning-24-3-11/) -- [Spring Boot 2.x基础教程:使用JTA实现分布式事务](http://blog.didispace.com/spring-boot-learning-24-3-12/) +- [Spring Boot 2.x基础教程:使用JTA实现多数据源的事务管理](http://blog.didispace.com/spring-boot-learning-24-3-12/) - [Spring Boot 2.x基础教程:2.5版本后数据脚本初始化的变动](http://blog.didispace.com/spring-boot-learning-25-3-13/) **加速利器:各种缓存的使用** @@ -81,34 +81,40 @@ - [Spring Boot 2.x基础教程:使用 Thymeleaf开发Web页面](http://blog.didispace.com/spring-boot-learning-21-4-1/) - [Spring Boot 2.x基础教程:使用 ECharts 绘制各种华丽的数据图表](http://blog.didispace.com/spring-boot-learning-21-4-2/) - [Spring Boot 2.x基础教程:实现文件上传](http://blog.didispace.com/spring-boot-learning-21-4-3/) -- [Spring Boot 2.x基础教程:实现多文件上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) -- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) +- [Spring Boot 2.x基础教程:多个文件的上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) +- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](http://blog.didispace.com/spring-boot-learning-21-4-5/) ### 任务管理 -**定时任务:`@Scheduled`实现** +**定时任务** - [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1) - -**定时任务:Elastic Job实现** - - [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2) - [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3) - [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4) -**异步任务:`@Async`实现** +**异步任务** - [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5) - [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6) - [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) - [Spring Boot 2.x基础教程:配置线程池的拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) -### 常见问题 +### 其他内容 + +- [Spring Boot自定义启动Banner](http://blog.didispace.com/spring-boot-banner/) +- [实现邮件发送:简单邮件、附件邮件、嵌入资源的邮件、模板邮件](http://blog.didispace.com/springbootmailsender/) +- [使用Spring StateMachine框架实现状态机](http://blog.didispace.com/spring-statemachine/) +- [Spring Boot应用的后台运行配置](http://blog.didispace.com/spring-boot-run-backend/) + + +## 问题与思考 - [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) - [为什么启动时候API路径都没了?](http://blog.didispace.com/spring-boot-learning-21-2-6/) - [使用Java 8中LocalDate等时间日期类的问题解决](http://blog.didispace.com/Spring-Boot-And-Feign-Use-localdate/) - [Request header is too large 如何解决?](https://blog.didispace.com/request-header-is-too-large/) +- [Spring Boot自动化配置的利弊及解决之道](http://blog.didispace.com/spring-boot-disable-autoconfig/) ## 版本资讯 diff --git a/2.x/chapter4-5/pom.xml b/2.x/chapter4-5/pom.xml new file mode 100644 index 00000000..7120c77a --- /dev/null +++ b/2.x/chapter4-5/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter4-5 + 0.0.1-SNAPSHOT + Spring Security快速入门 + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-security + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + \ No newline at end of file diff --git a/2.x/chapter4-5/src/main/java/com/didispace/chapter45/Application.java b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/Application.java new file mode 100644 index 00000000..00d2d076 --- /dev/null +++ b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/Application.java @@ -0,0 +1,22 @@ +package com.didispace.chapter45; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + * + */ +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + + SpringApplication.run(Application.class, args); + + } + +} diff --git a/2.x/chapter4-5/src/main/java/com/didispace/chapter45/HelloController.java b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/HelloController.java new file mode 100644 index 00000000..849a125d --- /dev/null +++ b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/HelloController.java @@ -0,0 +1,33 @@ +package com.didispace.chapter45; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + * + */ +@Controller +public class HelloController { + + @RequestMapping("/") + public String index() { + return "index"; + } + + @RequestMapping("/hello") + public String hello() { + return "hello"; + } + + @RequestMapping(value = "/login", method = RequestMethod.GET) + public String login() { + return "login"; + } + +} \ No newline at end of file diff --git a/2.x/chapter4-5/src/main/java/com/didispace/chapter45/WebSecurityConfig.java b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/WebSecurityConfig.java new file mode 100644 index 00000000..30fffef5 --- /dev/null +++ b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/WebSecurityConfig.java @@ -0,0 +1,36 @@ +package com.didispace.chapter45; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .antMatchers("/", "/home").permitAll() + .anyRequest().authenticated() + .and() + .formLogin() + .loginPage("/login") + .permitAll() + .and() + .logout() + .permitAll(); + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth + .inMemoryAuthentication() + .withUser("user").password("password").roles("USER"); + } + +} \ No newline at end of file diff --git a/2.x/chapter4-5/src/main/resources/application.properties b/2.x/chapter4-5/src/main/resources/application.properties new file mode 100644 index 00000000..e69de29b diff --git a/2.x/chapter4-5/src/main/resources/templates/hello.html b/2.x/chapter4-5/src/main/resources/templates/hello.html new file mode 100644 index 00000000..51477131 --- /dev/null +++ b/2.x/chapter4-5/src/main/resources/templates/hello.html @@ -0,0 +1,13 @@ + + + + Hello World! + + +

Hello [[${#httpServletRequest.remoteUser}]]!

+
+ +
+ + \ No newline at end of file diff --git a/2.x/chapter4-5/src/main/resources/templates/index.html b/2.x/chapter4-5/src/main/resources/templates/index.html new file mode 100644 index 00000000..ffe28340 --- /dev/null +++ b/2.x/chapter4-5/src/main/resources/templates/index.html @@ -0,0 +1,12 @@ + + + + Spring Security入门 + + +

欢迎使用Spring Security!

+ +

点击 这里 打个招呼吧

+ + \ No newline at end of file diff --git a/2.x/chapter4-5/src/main/resources/templates/login.html b/2.x/chapter4-5/src/main/resources/templates/login.html new file mode 100644 index 00000000..f5cbe8e2 --- /dev/null +++ b/2.x/chapter4-5/src/main/resources/templates/login.html @@ -0,0 +1,21 @@ + + + + Spring Security Example + + +
+ 用户名或密码错 +
+
+ 您已注销成功 +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/2.x/pom.xml b/2.x/pom.xml index 4c21f4b1..947e5fea 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -54,7 +54,7 @@ chapter4-2 chapter4-3 chapter4-4 - + chapter4-5 chapter5-1 @@ -62,7 +62,7 @@ chapter5-3 chapter5-4 chapter5-5 - + chapter6-1 @@ -82,8 +82,9 @@ chapter7-8 - - chapter8-1 + + + From 8f6234f4faffd2c44c358b58e67390e49ac1eaed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Tue, 9 Nov 2021 15:11:29 +0800 Subject: [PATCH 87/97] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 3 ++- 2.x/README_zh.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index eb25e406..3facb5e3 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -106,8 +106,9 @@ - [Spring Boot应用的后台运行配置](http://blog.didispace.com/spring-boot-run-backend/) -## 问题与思考 +## 进阶与深入 +- [什么时候不要使用@Autowire](http://blog.didispace.com/when-not-use-autowire-in-spring-boot/) - [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) - [为什么启动时候API路径都没了?](http://blog.didispace.com/spring-boot-learning-21-2-6/) - [使用Java 8中LocalDate等时间日期类的问题解决](http://blog.didispace.com/Spring-Boot-And-Feign-Use-localdate/) diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 256943c1..e7101b86 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -108,8 +108,9 @@ - [Spring Boot应用的后台运行配置](http://blog.didispace.com/spring-boot-run-backend/) -## 问题与思考 +## 进阶与深入 +- [什么时候不要使用@Autowire](http://blog.didispace.com/when-not-use-autowire-in-spring-boot/) - [为什么加了@Transactional注解,事务没有回滚?](http://blog.didispace.com/transactional-not-rollback/) - [为什么启动时候API路径都没了?](http://blog.didispace.com/spring-boot-learning-21-2-6/) - [使用Java 8中LocalDate等时间日期类的问题解决](http://blog.didispace.com/Spring-Boot-And-Feign-Use-localdate/) From e31efa092b63dccec54f68ba8c58e8f405228f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Tue, 14 Dec 2021 12:48:23 +0800 Subject: [PATCH 88/97] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter1-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter1-4/pom.xml b/2.x/chapter1-4/pom.xml index 8c5539f1..5bbd4008 100644 --- a/2.x/chapter1-4/pom.xml +++ b/2.x/chapter1-4/pom.xml @@ -11,7 +11,7 @@ com.didispace chapter1-4 0.0.1-SNAPSHOT - chapter1-1 + chapter1-4 配置元数据的应用 From 5d825367496f6ad9c30510325b92e0e8f25fffb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Tue, 28 Dec 2021 18:28:43 +0800 Subject: [PATCH 89/97] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E4=B8=8ELogback=E9=85=8D=E7=BD=AE=E8=AF=A6?= =?UTF-8?q?=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 18 ++++------ 2.x/README_zh.md | 6 ++++ 2.x/chapter8-1/pom.xml | 19 +++------- .../com/didispace/chapter81/Application.java | 22 ------------ .../chapter81/Chapter81Application.java | 26 ++++++++++++++ .../didispace/chapter81/HelloController.java | 33 ----------------- .../chapter81/WebSecurityConfig.java | 36 ------------------- .../src/main/resources/application.properties | 14 ++++++++ .../src/main/resources/templates/hello.html | 13 ------- .../src/main/resources/templates/index.html | 12 ------- .../src/main/resources/templates/login.html | 21 ----------- 2.x/pom.xml | 4 +-- 12 files changed, 60 insertions(+), 164 deletions(-) delete mode 100644 2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java create mode 100644 2.x/chapter8-1/src/main/java/com/didispace/chapter81/Chapter81Application.java delete mode 100644 2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java delete mode 100644 2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java delete mode 100644 2.x/chapter8-1/src/main/resources/templates/hello.html delete mode 100644 2.x/chapter8-1/src/main/resources/templates/index.html delete mode 100644 2.x/chapter8-1/src/main/resources/templates/login.html diff --git a/2.x/README.md b/2.x/README.md index 3facb5e3..59541053 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -98,6 +98,12 @@ - [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) - [Spring Boot 2.x基础教程:配置线程池的拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) +### 日志管理 + +- [Spring Boot 2.x基础教程:默认日志管理与Logback配置详解](https://blog.didispace.com/spring-boot-learning-2-8-1) +- [Spring Boot 2.x基础教程:使用tinylog记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3) +- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3) + ### 其他内容 - [Spring Boot自定义启动Banner](http://blog.didispace.com/spring-boot-banner/) @@ -105,7 +111,6 @@ - [使用Spring StateMachine框架实现状态机](http://blog.didispace.com/spring-statemachine/) - [Spring Boot应用的后台运行配置](http://blog.didispace.com/spring-boot-run-backend/) - ## 进阶与深入 - [什么时候不要使用@Autowire](http://blog.didispace.com/when-not-use-autowire-in-spring-boot/) @@ -125,16 +130,7 @@ - [Spring Boot 2.0 新特性(一):配置绑定 2.0 全解析](http://blog.didispace.com/Spring-Boot-2-0-feature-1-relaxed-binding-2/) - [Spring Boot 2.0 新特性(二):新增事件ApplicationStartedEvent](http://blog.didispace.com/Spring-Boot-2-0-feature-2-ApplicationStartedEvent/) -### 2.x版本信息 - -- [Spring Boot 2.2 正式发布,大幅性能提升 + Java 13 支持](http://blog.didispace.com/spring-boot-2-2-release/) -- [Spring Boot 2.3.0 发布](/spring-boot-2-3-0-release/) -- [Spring Boot 2.3.0 放弃 Maven 转投 Gradle](/spring-boot-gradle/) -- [Spring Boot 2.3.2 发布,解决 Too many open files 导致的应用宕机问题](http://blog.didispace.com/spring-boot-2-3-2-release/) -- [Spring Boot 2.4.0 正式发布!全新的配置处理机制,拥抱云原生!](http://blog.didispace.com/spring-boot-2-4-0-ga/) -- [Spring Boot 2.4.1 发布,修正大量2.4全新配置机制的Bug](http://blog.didispace.com/spring-boot-2-4-1-release/) -- [Spring Boot 2.5.0 发布:支持Java16、Gradle 7、Datasource初始化调整](https://blog.didispace.com/spring-boot-2-5-0-release/) -- [Spring Boot 2.5.1 发布](https://blog.didispace.com/spring-boot-2-5-1-release/) +更多关于2.x的版本信息可查看[点击查看](http://www.springcloud.com.cn/) ## 我的公众号 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index e7101b86..3fc0779b 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -100,6 +100,12 @@ - [Spring Boot 2.x基础教程:如何隔离@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-7) - [Spring Boot 2.x基础教程:配置线程池的拒绝策略](https://blog.didispace.com/spring-boot-learning-2-7-8) +### 日志管理 + +- [Spring Boot 2.x基础教程:默认日志管理与Logback配置详解](https://blog.didispace.com/spring-boot-learning-2-8-1) +- [Spring Boot 2.x基础教程:使用tinylog记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3) +- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3) + ### 其他内容 - [Spring Boot自定义启动Banner](http://blog.didispace.com/spring-boot-banner/) diff --git a/2.x/chapter8-1/pom.xml b/2.x/chapter8-1/pom.xml index 81817f27..d60616ec 100644 --- a/2.x/chapter8-1/pom.xml +++ b/2.x/chapter8-1/pom.xml @@ -13,7 +13,7 @@ com.didispace chapter8-1 0.0.1-SNAPSHOT - Spring Security快速入门 + 默认日志管理与Logback配置详解 UTF-8 @@ -23,7 +23,7 @@ org.springframework.boot - spring-boot-starter + spring-boot-starter-web @@ -33,19 +33,10 @@ - org.springframework.boot - spring-boot-starter-web + org.projectlombok + lombok + provided - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-security - - diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java deleted file mode 100644 index f7a9e16e..00000000 --- a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.didispace; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * - * @author 程序猿DD - * @version 1.0.0 - * @blog http://blog.didispace.com - * - */ -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - - SpringApplication.run(Application.class, args); - - } - -} diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Chapter81Application.java b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Chapter81Application.java new file mode 100644 index 00000000..a8fec0e0 --- /dev/null +++ b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Chapter81Application.java @@ -0,0 +1,26 @@ +package com.didispace.chapter81; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog https://blog.didispace.com + */ +@Slf4j +@SpringBootApplication +public class Chapter81Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter81Application.class, args); + + log.error("Hello World"); + log.warn("Hello World"); + log.info("Hello World"); + log.debug("Hello World"); + log.trace("Hello World"); + } + +} diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java deleted file mode 100644 index f5a6770b..00000000 --- a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.didispace.chapter81; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -/** - * - * @author 程序猿DD - * @version 1.0.0 - * @blog http://blog.didispace.com - * - */ -@Controller -public class HelloController { - - @RequestMapping("/") - public String index() { - return "index"; - } - - @RequestMapping("/hello") - public String hello() { - return "hello"; - } - - @RequestMapping(value = "/login", method = RequestMethod.GET) - public String login() { - return "login"; - } - -} \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java b/2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java deleted file mode 100644 index 1f3da340..00000000 --- a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.didispace.chapter81; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -@Configuration -@EnableWebSecurity -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - .authorizeRequests() - .antMatchers("/", "/home").permitAll() - .anyRequest().authenticated() - .and() - .formLogin() - .loginPage("/login") - .permitAll() - .and() - .logout() - .permitAll(); - } - - @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - auth - .inMemoryAuthentication() - .withUser("user").password("password").roles("USER"); - } - -} \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/resources/application.properties b/2.x/chapter8-1/src/main/resources/application.properties index e69de29b..361847c5 100644 --- a/2.x/chapter8-1/src/main/resources/application.properties +++ b/2.x/chapter8-1/src/main/resources/application.properties @@ -0,0 +1,14 @@ +debug=true + +spring.output.ansi.enabled=detect + +logging.file.name=run.log +logging.file.path=./ + +logging.level.com.didispace=debug + +logging.logback.rollingpolicy.clean-history-on-start=false +logging.logback.rollingpolicy.file-name-pattern= +logging.logback.rollingpolicy.max-history=7 +logging.logback.rollingpolicy.max-file-size=10MB +logging.logback.rollingpolicy.total-size-cap=0B diff --git a/2.x/chapter8-1/src/main/resources/templates/hello.html b/2.x/chapter8-1/src/main/resources/templates/hello.html deleted file mode 100644 index 51477131..00000000 --- a/2.x/chapter8-1/src/main/resources/templates/hello.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Hello World! - - -

Hello [[${#httpServletRequest.remoteUser}]]!

-
- -
- - \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/resources/templates/index.html b/2.x/chapter8-1/src/main/resources/templates/index.html deleted file mode 100644 index ffe28340..00000000 --- a/2.x/chapter8-1/src/main/resources/templates/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - Spring Security入门 - - -

欢迎使用Spring Security!

- -

点击 这里 打个招呼吧

- - \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/resources/templates/login.html b/2.x/chapter8-1/src/main/resources/templates/login.html deleted file mode 100644 index f5cbe8e2..00000000 --- a/2.x/chapter8-1/src/main/resources/templates/login.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - Spring Security Example - - -
- 用户名或密码错 -
-
- 您已注销成功 -
-
-
-
-
-
- - \ No newline at end of file diff --git a/2.x/pom.xml b/2.x/pom.xml index 947e5fea..664ba7a3 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -82,8 +82,8 @@ chapter7-8 - - + + chapter8-1 From 0dd9c71c7cffe65bd0541c02c2c0e284849921a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 29 Dec 2021 18:02:14 +0800 Subject: [PATCH 90/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8log4j2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 3 +- 2.x/README_zh.md | 2 +- 2.x/chapter8-2/pom.xml | 59 +++++++++++++++++++ .../chapter82/Chapter82Application.java | 26 ++++++++ .../src/main/resources/application.properties | 14 +++++ 2.x/pom.xml | 3 +- 6 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 2.x/chapter8-2/pom.xml create mode 100644 2.x/chapter8-2/src/main/java/com/didispace/chapter82/Chapter82Application.java create mode 100644 2.x/chapter8-2/src/main/resources/application.properties diff --git a/2.x/README.md b/2.x/README.md index 59541053..4c21c833 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -101,8 +101,9 @@ ### 日志管理 - [Spring Boot 2.x基础教程:默认日志管理与Logback配置详解](https://blog.didispace.com/spring-boot-learning-2-8-1) +- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-2) - [Spring Boot 2.x基础教程:使用tinylog记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3) -- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3) + ### 其他内容 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index 3fc0779b..bc61108c 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -103,8 +103,8 @@ ### 日志管理 - [Spring Boot 2.x基础教程:默认日志管理与Logback配置详解](https://blog.didispace.com/spring-boot-learning-2-8-1) +- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-2) - [Spring Boot 2.x基础教程:使用tinylog记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3) -- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3) ### 其他内容 diff --git a/2.x/chapter8-2/pom.xml b/2.x/chapter8-2/pom.xml new file mode 100644 index 00000000..fd6eedf7 --- /dev/null +++ b/2.x/chapter8-2/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.6.1 + + + + com.didispace + chapter8-2 + 0.0.1-SNAPSHOT + 使用log4j2记录日志 + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.projectlombok + lombok + provided + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + \ No newline at end of file diff --git a/2.x/chapter8-2/src/main/java/com/didispace/chapter82/Chapter82Application.java b/2.x/chapter8-2/src/main/java/com/didispace/chapter82/Chapter82Application.java new file mode 100644 index 00000000..be62c0c2 --- /dev/null +++ b/2.x/chapter8-2/src/main/java/com/didispace/chapter82/Chapter82Application.java @@ -0,0 +1,26 @@ +package com.didispace.chapter82; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog https://blog.didispace.com + */ +@Slf4j +@SpringBootApplication +public class Chapter82Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter82Application.class, args); + + log.error("Hello World"); + log.warn("Hello World"); + log.info("Hello World"); + log.debug("Hello World"); + log.trace("Hello World"); + } + +} diff --git a/2.x/chapter8-2/src/main/resources/application.properties b/2.x/chapter8-2/src/main/resources/application.properties new file mode 100644 index 00000000..361847c5 --- /dev/null +++ b/2.x/chapter8-2/src/main/resources/application.properties @@ -0,0 +1,14 @@ +debug=true + +spring.output.ansi.enabled=detect + +logging.file.name=run.log +logging.file.path=./ + +logging.level.com.didispace=debug + +logging.logback.rollingpolicy.clean-history-on-start=false +logging.logback.rollingpolicy.file-name-pattern= +logging.logback.rollingpolicy.max-history=7 +logging.logback.rollingpolicy.max-file-size=10MB +logging.logback.rollingpolicy.total-size-cap=0B diff --git a/2.x/pom.xml b/2.x/pom.xml index 664ba7a3..618227a4 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -84,7 +84,8 @@ chapter8-1 - + chapter8-2 + From fc1f39b0f842780e5e366ce8226f1865209007b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Thu, 30 Dec 2021 10:59:19 +0800 Subject: [PATCH 91/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8log4j2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter8-2/pom.xml | 14 ++++++++++---- .../src/main/resources/application.properties | 14 +------------- 2.x/chapter8-2/src/main/resources/log4j2.xml | 13 +++++++++++++ 3 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 2.x/chapter8-2/src/main/resources/log4j2.xml diff --git a/2.x/chapter8-2/pom.xml b/2.x/chapter8-2/pom.xml index fd6eedf7..eeda9143 100644 --- a/2.x/chapter8-2/pom.xml +++ b/2.x/chapter8-2/pom.xml @@ -24,12 +24,18 @@ org.springframework.boot spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + - - - - + + org.springframework.boot + spring-boot-starter-log4j2 + org.springframework.boot diff --git a/2.x/chapter8-2/src/main/resources/application.properties b/2.x/chapter8-2/src/main/resources/application.properties index 361847c5..b642e6f9 100644 --- a/2.x/chapter8-2/src/main/resources/application.properties +++ b/2.x/chapter8-2/src/main/resources/application.properties @@ -1,14 +1,2 @@ -debug=true -spring.output.ansi.enabled=detect - -logging.file.name=run.log -logging.file.path=./ - -logging.level.com.didispace=debug - -logging.logback.rollingpolicy.clean-history-on-start=false -logging.logback.rollingpolicy.file-name-pattern= -logging.logback.rollingpolicy.max-history=7 -logging.logback.rollingpolicy.max-file-size=10MB -logging.logback.rollingpolicy.total-size-cap=0B +logging.config=classpath:log4j2.xml \ No newline at end of file diff --git a/2.x/chapter8-2/src/main/resources/log4j2.xml b/2.x/chapter8-2/src/main/resources/log4j2.xml new file mode 100644 index 00000000..18ca1279 --- /dev/null +++ b/2.x/chapter8-2/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + From 6f1bc8f6979d9966c6566201ecd74bd6332f54b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 9 Feb 2022 15:52:11 +0800 Subject: [PATCH 92/97] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/didispace/chapter14/HelloController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.x/chapter1-4/src/main/java/com/didispace/chapter14/HelloController.java b/2.x/chapter1-4/src/main/java/com/didispace/chapter14/HelloController.java index d19b5ef6..084af5b8 100644 --- a/2.x/chapter1-4/src/main/java/com/didispace/chapter14/HelloController.java +++ b/2.x/chapter1-4/src/main/java/com/didispace/chapter14/HelloController.java @@ -1,4 +1,4 @@ -package com.didispace.chapter11; +package com.didispace.chapter14; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; From 07fd7ad0c11cf443d52ccf47d37f1996d6323341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 9 Feb 2022 15:57:08 +0800 Subject: [PATCH 93/97] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 3 ++- 2.x/README_zh.md | 3 ++- README.md | 5 +++-- README_zh.md | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/2.x/README.md b/2.x/README.md index 4c21c833..b8940acb 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -4,7 +4,8 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 **如何支持**: diff --git a/2.x/README_zh.md b/2.x/README_zh.md index bc61108c..e0999d9f 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -4,7 +4,8 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 **如何支持**: diff --git a/README.md b/README.md index 84dea730..2bb8edeb 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,14 @@ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 ## 教程目录 该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。 -为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总。 +为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总,后续还会继续跟进3.x版本! 可以通过下面的链接,进入具体版本的教程目录: diff --git a/README_zh.md b/README_zh.md index 84dea730..1a7c9110 100644 --- a/README_zh.md +++ b/README_zh.md @@ -8,7 +8,8 @@ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 ## 教程目录 From fdd6b61af6a0512cc446e05244231dcfc2b8e1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 9 Feb 2022 15:59:11 +0800 Subject: [PATCH 94/97] =?UTF-8?q?2.x=E7=89=88=E6=9C=AC=E6=95=99=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/README.md | 1 + 2.x/README_zh.md | 1 + README.md | 1 + README_zh.md | 1 + 4 files changed, 4 insertions(+) diff --git a/2.x/README.md b/2.x/README.md index b8940acb..af580d69 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -5,6 +5,7 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! **加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + **Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 **如何支持**: diff --git a/2.x/README_zh.md b/2.x/README_zh.md index e0999d9f..70612143 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -5,6 +5,7 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! **加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + **Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 **如何支持**: diff --git a/README.md b/README.md index 2bb8edeb..916c7fa4 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ 3. 把该仓库分享给更多的朋友 **加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + **Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 ## 教程目录 diff --git a/README_zh.md b/README_zh.md index 1a7c9110..f75927c3 100644 --- a/README_zh.md +++ b/README_zh.md @@ -9,6 +9,7 @@ 3. 把该仓库分享给更多的朋友 **加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + **Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 ## 教程目录 From 8d265aa8e12488078752e05aa228a4f321bf52a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 9 Feb 2022 16:00:11 +0800 Subject: [PATCH 95/97] =?UTF-8?q?1.x=E7=89=88=E6=9C=AC=E6=95=99=E7=A8=8B?= =?UTF-8?q?=EF=BC=88=E5=B7=B2=E5=AE=8C=E7=BB=93=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.x/README.md | 1 + 1.x/README_zh.md | 1 + 2 files changed, 2 insertions(+) diff --git a/1.x/README.md b/1.x/README.md index a1fcc0fe..0fdaf52c 100644 --- a/1.x/README.md +++ b/1.x/README.md @@ -7,6 +7,7 @@ Spring Boot 2.x版本的教程可在`2.x`目录下查看。 + ## 教程目录(1.x版本) 本教程版本基于Spring Boot 1.3.x - 1.5.x,部分内容可能会有出入。如果您发现问题,首先看版本是否一致。如果还有问题,可以提Issue指出。 diff --git a/1.x/README_zh.md b/1.x/README_zh.md index a1fcc0fe..0fdaf52c 100644 --- a/1.x/README_zh.md +++ b/1.x/README_zh.md @@ -7,6 +7,7 @@ Spring Boot 2.x版本的教程可在`2.x`目录下查看。 + ## 教程目录(1.x版本) 本教程版本基于Spring Boot 1.3.x - 1.5.x,部分内容可能会有出入。如果您发现问题,首先看版本是否一致。如果还有问题,可以提Issue指出。 From fbf79267cf97695c6b91eac541ad3df040549e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Fri, 11 Feb 2022 18:51:25 +0800 Subject: [PATCH 96/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8tinylog=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter8-3/pom.xml | 60 +++++++++++++++++++ .../chapter83/Chapter83Application.java | 26 ++++++++ .../src/main/resources/application.properties | 1 + 2.x/pom.xml | 5 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 2.x/chapter8-3/pom.xml create mode 100644 2.x/chapter8-3/src/main/java/com/didispace/chapter83/Chapter83Application.java create mode 100644 2.x/chapter8-3/src/main/resources/application.properties diff --git a/2.x/chapter8-3/pom.xml b/2.x/chapter8-3/pom.xml new file mode 100644 index 00000000..7d640d1a --- /dev/null +++ b/2.x/chapter8-3/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.6.1 + + + + com.didispace + chapter8-3 + 0.0.1-SNAPSHOT + 使用tinylog记录日志 + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.projectlombok + lombok + provided + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + \ No newline at end of file diff --git a/2.x/chapter8-3/src/main/java/com/didispace/chapter83/Chapter83Application.java b/2.x/chapter8-3/src/main/java/com/didispace/chapter83/Chapter83Application.java new file mode 100644 index 00000000..8a68d462 --- /dev/null +++ b/2.x/chapter8-3/src/main/java/com/didispace/chapter83/Chapter83Application.java @@ -0,0 +1,26 @@ +package com.didispace.chapter83; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog https://blog.didispace.com + */ +@Slf4j +@SpringBootApplication +public class Chapter83Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter83Application.class, args); + + log.error("Hello World"); + log.warn("Hello World"); + log.info("Hello World"); + log.debug("Hello World"); + log.trace("Hello World"); + } + +} diff --git a/2.x/chapter8-3/src/main/resources/application.properties b/2.x/chapter8-3/src/main/resources/application.properties new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/2.x/chapter8-3/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/2.x/pom.xml b/2.x/pom.xml index 618227a4..f20e1714 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -85,7 +85,10 @@ chapter8-1 chapter8-2 - + chapter8-3 + + + From 4212d163da816c6fa5b28d59130318dac2379a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Mon, 14 Feb 2022 10:40:01 +0800 Subject: [PATCH 97/97] =?UTF-8?q?=E4=BD=BF=E7=94=A8tinylog=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.x/chapter8-3/pom.xml | 27 ++++++++++++++++--- .../src/main/resources/tinylog.properties | 2 ++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 2.x/chapter8-3/src/main/resources/tinylog.properties diff --git a/2.x/chapter8-3/pom.xml b/2.x/chapter8-3/pom.xml index 7d640d1a..d6a578e8 100644 --- a/2.x/chapter8-3/pom.xml +++ b/2.x/chapter8-3/pom.xml @@ -18,6 +18,7 @@ UTF-8 1.8 + 2.4.1 @@ -33,9 +34,29 @@ - org.springframework.boot - spring-boot-starter-test - test + org.tinylog + tinylog-api + ${tinylog.version} + + + org.tinylog + tinylog-impl + ${tinylog.version} + + + org.tinylog + slf4j-tinylog + ${tinylog.version} + + + org.tinylog + jcl-tinylog + ${tinylog.version} + + + org.tinylog + log4j1.2-api + ${tinylog.version} diff --git a/2.x/chapter8-3/src/main/resources/tinylog.properties b/2.x/chapter8-3/src/main/resources/tinylog.properties new file mode 100644 index 00000000..9eb1b999 --- /dev/null +++ b/2.x/chapter8-3/src/main/resources/tinylog.properties @@ -0,0 +1,2 @@ +writer=console +writer.format={date: HH:mm:ss.SSS} {level}: {message} \ No newline at end of file