diff --git a/1.x/README.md b/1.x/README.md index 4abf6dda..0fdaf52c 100644 --- a/1.x/README.md +++ b/1.x/README.md @@ -1,60 +1,12 @@ -# 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://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) - -**如何支持**: -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 4f9e75c1..0fdaf52c 100644 --- a/1.x/README_zh.md +++ b/1.x/README_zh.md @@ -1,63 +1,12 @@ -# 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://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) - -**如何支持**: -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 +119,6 @@ ## 我的公众号 - + -## 我出版的书 -![输入图片说明](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png "在这里输入图片标题") diff --git a/2.1.x/README.md b/2.1.x/README.md deleted file mode 100644 index de29ff83..00000000 --- a/2.1.x/README.md +++ /dev/null @@ -1,122 +0,0 @@ -# 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基础教程 - -## 我的公众号 - - - - diff --git a/2.1.x/README_zh.md b/2.1.x/README_zh.md deleted file mode 100644 index 301ec021..00000000 --- a/2.1.x/README_zh.md +++ /dev/null @@ -1,127 +0,0 @@ -# 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. 把该仓库分享给更多的朋友 - -如果您对文字类教程不感冒或者想要通过综合案例学习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 "在这里输入图片标题") 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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 - - - - - - - - - - - - diff --git a/2.x/README.md b/2.x/README.md index eef9aef7..af580d69 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -4,7 +4,9 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 **如何支持**: @@ -12,64 +14,25 @@ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 -## 特别赞助商 - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` - ## 教程目录(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基础教程: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/) -### 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/) @@ -77,6 +40,8 @@ - [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/) +- [Spring Boot 2.x基础教程:如何扩展XML格式的请求和响应](http://blog.didispace.com/spring-boot-learning-21-2-8/) ### 数据访问 @@ -93,7 +58,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基础教程:使用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/) **加速利器:各种缓存的使用** @@ -101,13 +67,61 @@ - [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/) +- [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开发 - [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基础教程:多个文件的上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) +- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](http://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) +- [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基础教程:配置线程池的拒绝策略](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基础教程:使用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自定义启动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/) + +## 进阶与深入 + +- [什么时候不要使用@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/) +- [Request header is too large 如何解决?](https://blog.didispace.com/request-header-is-too-large/) +- [Spring Boot自动化配置的利弊及解决之道](http://blog.didispace.com/spring-boot-disable-autoconfig/) ## 版本资讯 @@ -119,16 +133,52 @@ - [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/) +更多关于2.x的版本信息可查看[点击查看](http://www.springcloud.com.cn/) ## 我的公众号 - + + +## 推荐我的书 + +![Spring Boot微服务实战](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png) + +## 特别赞助商 + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + +
+> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` \ No newline at end of file diff --git a/2.x/README_zh.md b/2.x/README_zh.md index b7a36e10..70612143 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -4,73 +4,37 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 **如何支持**: + 1. 关注我的公众号”**程序猿DD**“ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 > **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
-## 特别赞助商 - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` - ## 教程目录(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基础教程: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/) -### 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 +42,8 @@ - [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/) +- [Spring Boot 2.x基础教程:如何扩展XML格式的请求和响应](http://blog.didispace.com/spring-boot-learning-21-2-8/) ### 数据访问 @@ -94,7 +60,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基础教程:使用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/) **加速利器:各种缓存的使用** @@ -102,13 +69,61 @@ - [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/) +- [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开发 - [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基础教程:多个文件的上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) +- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](http://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) +- [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基础教程:配置线程池的拒绝策略](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基础教程:使用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自定义启动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/) + + +## 进阶与深入 + +- [什么时候不要使用@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/) +- [Request header is too large 如何解决?](https://blog.didispace.com/request-header-is-too-large/) +- [Spring Boot自动化配置的利弊及解决之道](http://blog.didispace.com/spring-boot-disable-autoconfig/) ## 版本资讯 @@ -128,21 +143,60 @@ - [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/) ## 推荐内容 - [我的博客](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 "在这里输入图片标题") +![Spring Boot微服务实战](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png) + +## 特别赞助商 + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + +
+ +> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` \ No newline at end of file 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 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 { 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 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 diff --git a/2.x/chapter1-4/pom.xml b/2.x/chapter1-4/pom.xml index e64ae735..5bbd4008 100644 --- a/2.x/chapter1-4/pom.xml +++ b/2.x/chapter1-4/pom.xml @@ -11,8 +11,8 @@ com.didispace chapter1-4 0.0.1-SNAPSHOT - chapter1-1 - Demo project for Spring Boot + chapter1-4 + 配置元数据的应用 1.8 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; diff --git a/2.1.x/chapter1-1/.gitignore b/2.x/chapter1-5/.gitignore similarity index 100% rename from 2.1.x/chapter1-1/.gitignore rename to 2.x/chapter1-5/.gitignore diff --git a/2.x/chapter1-5/pom.xml b/2.x/chapter1-5/pom.xml new file mode 100644 index 00000000..a9c25152 --- /dev/null +++ b/2.x/chapter1-5/pom.xml @@ -0,0 +1,59 @@ + + + 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 + + + + com.github.ulisesbocchio + jasypt-spring-boot-starter + 3.0.3 + + + + org.projectlombok + lombok + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + com.github.ulisesbocchio + jasypt-maven-plugin + 3.0.3 + + + + + diff --git a/2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/Chapter37Application.java b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java similarity index 60% rename from 2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/Chapter37Application.java rename to 2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java index 92be7068..6b0c79d6 100644 --- a/2.1.x/chapter3-7/src/main/java/com/didispace/chapter37/Chapter37Application.java +++ b/2.x/chapter1-5/src/main/java/com/didispace/chapter15/Chapter15Application.java @@ -1,13 +1,13 @@ -package com.didispace.chapter37; +package com.didispace.chapter15; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class Chapter37Application { +public class Chapter15Application { public static void main(String[] args) { - SpringApplication.run(Chapter37Application.class, args); + SpringApplication.run(Chapter15Application.class, args); } } 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..b5780fe0 --- /dev/null +++ b/2.x/chapter1-5/src/main/resources/application.properties @@ -0,0 +1,10 @@ + +datasource.password=ENC(/AL9nJENCYCh9Pfzdf2xLPsqOZ6HwNgQ3AnMybFAMeOM5GphZlOK6PxzozwtCm+Q) + +jasypt.encryptor.password=didispace + +# mvn jasypt:encrypt -Djasypt.encryptor.password=didispace +# 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 new file mode 100644 index 00000000..db8ff86d --- /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.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; + +@Slf4j +@SpringBootTest +public class PropertiesTest { + + @Value("${datasource.password:}") + private String password; + + @Test + public void test() { + log.info("datasource.password : {}", password); + } + +} 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 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 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 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 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 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 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 diff --git a/2.1.x/chapter2-3/pom.xml b/2.x/chapter2-8/pom.xml similarity index 76% rename from 2.1.x/chapter2-3/pom.xml rename to 2.x/chapter2-8/pom.xml index 284c9d0d..86a98950 100644 --- a/2.1.x/chapter2-3/pom.xml +++ b/2.x/chapter2-8/pom.xml @@ -3,20 +3,21 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + com.didispace + chapter2-8 + 1.0.0 + jar + 如何扩展XML格式的请求和响应 + org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.5.1 - com.didispace - chapter2-3 - 0.0.1-SNAPSHOT - chapter2-3 - Demo project for Spring Boot - + UTF-8 1.8 @@ -27,23 +28,23 @@ - com.spring4all - swagger-spring-boot-starter - 1.9.0.RELEASE + org.springframework.boot + spring-boot-starter-test + test - org.projectlombok - lombok + com.fasterxml.jackson.dataformat + jackson-dataformat-xml - org.springframework.boot - spring-boot-starter-test - test + org.projectlombok + lombok - + + @@ -53,4 +54,4 @@ - + \ 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.1.x/chapter2-7/pom.xml b/2.x/chapter2-9/pom.xml similarity index 64% rename from 2.1.x/chapter2-7/pom.xml rename to 2.x/chapter2-9/pom.xml index 882a8176..9f670750 100644 --- a/2.1.x/chapter2-7/pom.xml +++ b/2.x/chapter2-9/pom.xml @@ -3,18 +3,20 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + com.didispace + chapter2-9 + 1.0.0 + jar + org.springframework.boot spring-boot-starter-parent - 2.2.3.RELEASE + 2.5.1 - com.didispace - chapter2-7 - 0.0.1-SNAPSHOT - + UTF-8 1.8 @@ -24,6 +26,12 @@ spring-boot-starter-web + + org.springframework.experimental + graphql-spring-boot-starter + 1.0.0-SNAPSHOT + + org.springframework.boot spring-boot-starter-test @@ -31,9 +39,8 @@ - io.springfox - springfox-boot-starter - 3.0.0 + com.fasterxml.jackson.dataformat + jackson-dataformat-xml @@ -43,7 +50,7 @@ - + @@ -55,13 +62,14 @@ - - false - - jcenter-releases - jcenter - http://jcenter.bintray.com + 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 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 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 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 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.1.x/chapter2-1/.gitignore b/2.x/chapter3-13/.gitignore similarity index 100% rename from 2.1.x/chapter2-1/.gitignore rename to 2.x/chapter3-13/.gitignore diff --git a/2.1.x/chapter3-1/pom.xml b/2.x/chapter3-13/pom.xml similarity index 91% rename from 2.1.x/chapter3-1/pom.xml rename to 2.x/chapter3-13/pom.xml index 4621591e..de7746d3 100644 --- a/2.1.x/chapter3-1/pom.xml +++ b/2.x/chapter3-13/pom.xml @@ -6,13 +6,14 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.5.0 com.didispace - chapter3-1 + chapter3-13 0.0.1-SNAPSHOT + 2.5版本之后的数据脚本初始化 1.8 diff --git a/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/Chapter21Application.java b/2.x/chapter3-13/src/main/java/com/didispace/chapter313/Chapter313Application.java similarity index 59% rename from 2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/Chapter21Application.java rename to 2.x/chapter3-13/src/main/java/com/didispace/chapter313/Chapter313Application.java index 936e8024..88768410 100644 --- a/2.1.x/chapter2-1/src/main/java/com/didispace/chapter21/Chapter21Application.java +++ b/2.x/chapter3-13/src/main/java/com/didispace/chapter313/Chapter313Application.java @@ -1,13 +1,13 @@ -package com.didispace.chapter21; +package com.didispace.chapter313; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class Chapter21Application { +public class Chapter313Application { public static void main(String[] args) { - SpringApplication.run(Chapter21Application.class, 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/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 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 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 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/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 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 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 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 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 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 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 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 diff --git a/2.1.x/chapter5-1/pom.xml b/2.x/chapter4-5/pom.xml similarity index 72% rename from 2.1.x/chapter5-1/pom.xml rename to 2.x/chapter4-5/pom.xml index 2af64776..7120c77a 100644 --- a/2.1.x/chapter5-1/pom.xml +++ b/2.x/chapter4-5/pom.xml @@ -6,64 +6,58 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.5.1 com.didispace - chapter5-1 + chapter4-5 0.0.1-SNAPSHOT + Spring Security快速入门 + UTF-8 1.8 org.springframework.boot - spring-boot-starter-web + spring-boot-starter org.springframework.boot - spring-boot-starter-data-jpa + spring-boot-starter-test + test org.springframework.boot - spring-boot-starter-cache + spring-boot-starter-web org.springframework.boot - spring-boot-starter-actuator + spring-boot-starter-thymeleaf - - - mysql - mysql-connector-java - - - - org.projectlombok - lombok - provided - - org.springframework.boot - spring-boot-starter-test - test + 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/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 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 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 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 diff --git a/2.1.x/chapter2-2/.gitignore b/2.x/chapter5-5/.gitignore similarity index 100% rename from 2.1.x/chapter2-2/.gitignore rename to 2.x/chapter5-5/.gitignore diff --git a/2.1.x/chapter3-4/pom.xml b/2.x/chapter5-5/pom.xml similarity index 85% rename from 2.1.x/chapter3-4/pom.xml rename to 2.x/chapter5-5/pom.xml index 602beb6d..dc1d2874 100644 --- a/2.1.x/chapter3-4/pom.xml +++ b/2.x/chapter5-5/pom.xml @@ -6,13 +6,14 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.5.1 com.didispace - chapter3-4 + chapter5-5 0.0.1-SNAPSHOT + 使用Redis的发布订阅 1.8 @@ -26,17 +27,17 @@ org.springframework.boot - spring-boot-starter-data-jpa + spring-boot-starter-data-redis - org.springframework.boot - spring-boot-starter-actuator + org.apache.commons + commons-pool2 - mysql - mysql-connector-java + org.springframework.boot + spring-boot-starter-actuator 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.1.x/chapter4-2/pom.xml b/2.x/chapter6-1/pom.xml old mode 100644 new mode 100755 similarity index 88% rename from 2.1.x/chapter4-2/pom.xml rename to 2.x/chapter6-1/pom.xml index d6022db9..10a0116e --- a/2.1.x/chapter4-2/pom.xml +++ b/2.x/chapter6-1/pom.xml @@ -6,13 +6,14 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.4.1 com.didispace - chapter4-2 + chapter6-1 0.0.1-SNAPSHOT + 使用MongoDB 1.8 @@ -26,7 +27,7 @@ org.springframework.boot - spring-boot-starter-thymeleaf + spring-boot-starter-data-mongodb diff --git a/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/Chapter26Application.java b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java old mode 100644 new mode 100755 similarity index 60% rename from 2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/Chapter26Application.java rename to 2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java index ab89e203..dfd534eb --- a/2.1.x/chapter2-6/src/main/java/com/didispace/chapter26/Chapter26Application.java +++ b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/Chapter61Application.java @@ -1,13 +1,13 @@ -package com.didispace.chapter26; +package com.didispace.chapter61; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class Chapter26Application { +public class Chapter61Application { public static void main(String[] args) { - SpringApplication.run(Chapter26Application.class, 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..e94f10c0 --- /dev/null +++ b/2.x/chapter6-1/src/main/java/com/didispace/chapter61/User.java @@ -0,0 +1,22 @@ +package com.didispace.chapter61; + +import lombok.AllArgsConstructor; +import lombok.Data; +import org.springframework.data.annotation.Id; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog http://blog.didispace.com + */ +@Data +@AllArgsConstructor +public class User { + + @Id + private Long id; + + private String username; + private Integer 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..0e2f083f --- /dev/null +++ b/2.x/chapter6-1/src/main/resources/application.properties @@ -0,0 +1,3 @@ +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 new file mode 100755 index 00000000..e1ee421a --- /dev/null +++ b/2.x/chapter6-1/src/test/java/com/didispace/chapter61/ApplicationTests.java @@ -0,0 +1,35 @@ +package com.didispace.chapter61; + +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; + +@SpringBootTest(classes = Chapter61Application.class) +public class ApplicationTests { + + @Autowired + private UserRepository userRepository; + + @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)); + Assertions.assertEquals(3, userRepository.findAll().size()); + + // 删除一个User,再验证User总数 + User u = userRepository.findById(1L).get(); + userRepository.delete(u); + Assertions.assertEquals(2, userRepository.findAll().size()); + + // 删除一个User,再验证User总数 + u = userRepository.findByUsername("mama"); + userRepository.delete(u); + Assertions.assertEquals(1, userRepository.findAll().size()); + } + +} diff --git a/2.1.x/chapter3-10/pom.xml b/2.x/chapter6-2/pom.xml similarity index 75% rename from 2.1.x/chapter3-10/pom.xml rename to 2.x/chapter6-2/pom.xml index 9b2abc07..dc1b63bd 100644 --- a/2.1.x/chapter3-10/pom.xml +++ b/2.x/chapter6-2/pom.xml @@ -3,40 +3,34 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + com.didispace + chapter6-2 + 1.0.0 + jar + 使用轻量级树状存储 LDAP + org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.5.1 - com.didispace - chapter3-10 - 0.0.1-SNAPSHOT - + UTF-8 1.8 - - org.springframework.boot - spring-boot-starter-web - org.springframework.boot - spring-boot-starter-data-jpa + spring-boot-starter-web org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java + spring-boot-starter-data-ldap @@ -45,13 +39,20 @@ provided + + com.unboundid + unboundid-ldapsdk + test + + org.springframework.boot spring-boot-starter-test test - + + @@ -61,4 +62,4 @@ - + \ No newline at end of file diff --git a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/Chapter32Application.java b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Chapter62Application.java similarity index 60% rename from 2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/Chapter32Application.java rename to 2.x/chapter6-2/src/main/java/com/didispace/chapter62/Chapter62Application.java index d782cff1..5baa9594 100644 --- a/2.1.x/chapter3-2/src/main/java/com/didispace/chapter32/Chapter32Application.java +++ b/2.x/chapter6-2/src/main/java/com/didispace/chapter62/Chapter62Application.java @@ -1,13 +1,13 @@ -package com.didispace.chapter32; +package com.didispace.chapter62; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class Chapter32Application { +public class Chapter62Application { public static void main(String[] args) { - SpringApplication.run(Chapter32Application.class, 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..cc078f67 --- /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 userName; + 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..d2726e89 --- /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 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..b1e2a2fd --- /dev/null +++ b/2.x/chapter6-2/src/test/java/com/didispace/chapter62/ApplicationTests.java @@ -0,0 +1,38 @@ +package com.didispace.chapter62; + +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 { + + @Autowired + private PersonRepository personRepository; + + @Test + public void findAll() { + + personRepository.findAll().forEach(p -> { + System.out.println(p); + }); + + } + + @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); + }); + } + +} 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..55e19357 --- /dev/null +++ b/2.x/chapter6-2/src/test/resources/application.properties @@ -0,0 +1,3 @@ +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 new file mode 100644 index 00000000..353a4939 --- /dev/null +++ b/2.x/chapter6-2/src/test/resources/ldap-server.ldif @@ -0,0 +1,20 @@ +dn: dc=didispace,dc=com +objectClass: top +objectClass: domain +objectclass: extensibleObject +dc: didispace + +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/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/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.1.x/chapter2-5/src/main/java/com/didispace/chapter25/Chapter25Application.java b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java similarity index 50% rename from 2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/Chapter25Application.java rename to 2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java index b8c92652..83ebf477 100644 --- a/2.1.x/chapter2-5/src/main/java/com/didispace/chapter25/Chapter25Application.java +++ b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java @@ -1,15 +1,14 @@ -package com.didispace.chapter25; +package com.didispace.chapter64; -import com.spring4all.swagger.EnableSwagger2Doc; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; -@EnableSwagger2Doc @SpringBootApplication -public class Chapter25Application { +public class Chapter64Application { public static void main(String[] args) { - SpringApplication.run(Chapter25Application.class, args); + SpringApplication.run(Chapter64Application.class, args); } } diff --git a/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/User.java b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java similarity index 76% rename from 2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/User.java rename to 2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java index 9fb641f0..cc83d361 100644 --- a/2.1.x/chapter5-2/src/main/java/com/didispace/chapter52/User.java +++ b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java @@ -1,4 +1,4 @@ -package com.didispace.chapter52; +package com.didispace.chapter64; import lombok.Data; import lombok.NoArgsConstructor; @@ -10,7 +10,7 @@ @Entity @Data @NoArgsConstructor -public class User { +public class UserInfo { @Id @GeneratedValue @@ -19,7 +19,7 @@ public class User { private String name; private Integer age; - public User(String name, Integer age) { + public UserInfo(String name, Integer age) { this.name = name; this.age = age; } 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/chapter7-1/pom.xml b/2.x/chapter7-1/pom.xml new file mode 100755 index 00000000..fc9142ad --- /dev/null +++ b/2.x/chapter7-1/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-1 + 0.0.1-SNAPSHOT + 使用@Scheduled实现定时任务 + + + 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/chapter7-2/pom.xml b/2.x/chapter7-2/pom.xml new file mode 100755 index 00000000..e1987da5 --- /dev/null +++ b/2.x/chapter7-2/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-2 + 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.1.x/chapter2-2/src/main/java/com/didispace/chapter22/Chapter22Application.java b/2.x/chapter7-2/src/main/java/com/didispace/chapter72/Chapter72Application.java old mode 100644 new mode 100755 similarity index 50% rename from 2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/Chapter22Application.java rename to 2.x/chapter7-2/src/main/java/com/didispace/chapter72/Chapter72Application.java index cd6963b8..236357d8 --- a/2.1.x/chapter2-2/src/main/java/com/didispace/chapter22/Chapter22Application.java +++ b/2.x/chapter7-2/src/main/java/com/didispace/chapter72/Chapter72Application.java @@ -1,15 +1,13 @@ -package com.didispace.chapter22; +package com.didispace.chapter72; -import com.spring4all.swagger.EnableSwagger2Doc; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@EnableSwagger2Doc @SpringBootApplication -public class Chapter22Application { +public class Chapter72Application { public static void main(String[] args) { - SpringApplication.run(Chapter22Application.class, 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..55d4ff9f --- /dev/null +++ b/2.x/chapter7-3/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter7-3 + 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-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..d1f535ae --- /dev/null +++ b/2.x/chapter7-3/src/main/java/com/didispace/chapter73/MyShardingJob.java @@ -0,0 +1,28 @@ +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) { + // sharding-total-count=3,所以任务被分为三个分片 + switch (context.getShardingItem()) { + case 0: + log.info("分片1:执行任务"); + break; + case 1: + log.info("分片2:执行任务"); + break; + case 2: + log.info("分片3:执行任务"); + 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..cb7d3cd8 --- /dev/null +++ b/2.x/chapter7-3/src/main/resources/application.properties @@ -0,0 +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 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 100644 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..4e651c3e --- /dev/null +++ b/2.x/chapter7-4/src/main/java/com/didispace/chapter74/MySimpleJob.java @@ -0,0 +1,17 @@ +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()); + } + +} \ 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..16a59e0f --- /dev/null +++ b/2.x/chapter7-4/src/main/resources/application.properties @@ -0,0 +1,8 @@ +spring.application.name=chapter74 + +elasticjob.reg-center.server-lists=localhost:2181 +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 * * * * ? +elasticjob.jobs.my-simple-job.sharding-total-count=1 diff --git a/2.1.x/chapter2-6/pom.xml b/2.x/chapter7-5/pom.xml old mode 100644 new mode 100755 similarity index 91% rename from 2.1.x/chapter2-6/pom.xml rename to 2.x/chapter7-5/pom.xml index 09ba9399..4ff53d56 --- a/2.1.x/chapter2-6/pom.xml +++ b/2.x/chapter7-5/pom.xml @@ -6,13 +6,14 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.5.1 com.didispace - chapter2-6 + chapter7-5 0.0.1-SNAPSHOT + 使用@Async实现异步任务 1.8 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..e2f1be13 --- /dev/null +++ b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/AsyncTasks.java @@ -0,0 +1,46 @@ +package com.didispace.chapter75; + +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-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..e8aef549 --- /dev/null +++ b/2.x/chapter7-5/src/main/java/com/didispace/chapter75/Chapter75Application.java @@ -0,0 +1,15 @@ +package com.didispace.chapter75; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; + +@EnableAsync +@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..af32b972 --- /dev/null +++ b/2.x/chapter7-5/src/test/java/com/didispace/chapter75/Chapter75ApplicationTests.java @@ -0,0 +1,33 @@ +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; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; + +@Slf4j +@SpringBootTest +public class Chapter75ApplicationTests { + + @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/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..66a01d8e --- /dev/null +++ b/2.x/chapter7-6/src/main/java/com/didispace/chapter76/AsyncTasks.java @@ -0,0 +1,47 @@ +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; +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("任务三完成"); + } + +} \ 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..070a4b71 --- /dev/null +++ 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 new file mode 100644 index 00000000..2a832502 --- /dev/null +++ b/2.x/chapter7-6/src/test/java/com/didispace/chapter76/Chapter76ApplicationTests.java @@ -0,0 +1,32 @@ +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; + +@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) + "毫秒"); + } + +} diff --git a/2.x/chapter7-7/pom.xml b/2.x/chapter7-7/pom.xml new file mode 100755 index 00000000..2a69afe0 --- /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-7 + 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..90185dc8 --- /dev/null +++ b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/AsyncTasks.java @@ -0,0 +1,36 @@ +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; + +@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-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..e598f26d --- /dev/null +++ b/2.x/chapter7-7/src/main/java/com/didispace/chapter77/Chapter77Application.java @@ -0,0 +1,55 @@ +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 Chapter77Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter77Application.class, args); + } + + @EnableAsync + @Configuration + class TaskPoolConfig { + + @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 new file mode 100644 index 00000000..e69de29b 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..d6479787 --- /dev/null +++ b/2.x/chapter7-7/src/test/java/com/didispace/chapter77/Chapter77ApplicationTests.java @@ -0,0 +1,40 @@ +package com.didispace.chapter77; + +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 Chapter77ApplicationTests { + + @Autowired + private AsyncTasks asyncTasks; + + @Test + public void test() throws Exception { + long start = System.currentTimeMillis(); + + // 线程池1 + CompletableFuture task1 = asyncTasks.doTaskOne("1"); + CompletableFuture task2 = asyncTasks.doTaskOne("2"); + CompletableFuture task3 = asyncTasks.doTaskOne("3"); + + // 线程池2 + CompletableFuture task4 = asyncTasks.doTaskTwo("4"); + CompletableFuture task5 = asyncTasks.doTaskTwo("5"); + CompletableFuture task6 = asyncTasks.doTaskTwo("6"); + + // 一起执行 + CompletableFuture.allOf(task1, task2, task3, task4, task5, task6).join(); + + long end = System.currentTimeMillis(); + + log.info("任务全部完成,总耗时:" + (end - start) + "毫秒"); + } + +} 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..5cb782f5 --- /dev/null +++ b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/AsyncTasks.java @@ -0,0 +1,26 @@ +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("任务完成"); + } + +} \ 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..f04169be --- /dev/null +++ b/2.x/chapter7-8/src/main/java/com/didispace/chapter78/Chapter78Application.java @@ -0,0 +1,60 @@ +package com.didispace.chapter78; + +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 java.util.concurrent.Executor; + +@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-"); + + /**配置拒绝策略**/ + + // 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; + } + + } + +} 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.1.x/chapter4-1/pom.xml b/2.x/chapter8-1/pom.xml similarity index 81% rename from 2.1.x/chapter4-1/pom.xml rename to 2.x/chapter8-1/pom.xml index e8191b85..d60616ec 100644 --- a/2.1.x/chapter4-1/pom.xml +++ b/2.x/chapter8-1/pom.xml @@ -6,15 +6,17 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.5.1 com.didispace - chapter4-1 + chapter8-1 0.0.1-SNAPSHOT + 默认日志管理与Logback配置详解 + UTF-8 1.8 @@ -26,7 +28,8 @@ org.springframework.boot - spring-boot-starter-thymeleaf + spring-boot-starter-test + test @@ -34,21 +37,18 @@ lombok provided - - - org.springframework.boot - spring-boot-starter-test - test - - + 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/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/resources/application.properties b/2.x/chapter8-1/src/main/resources/application.properties new file mode 100644 index 00000000..361847c5 --- /dev/null +++ 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.1.x/chapter3-8/pom.xml b/2.x/chapter8-2/pom.xml similarity index 72% rename from 2.1.x/chapter3-8/pom.xml rename to 2.x/chapter8-2/pom.xml index cd677906..eeda9143 100644 --- a/2.1.x/chapter3-8/pom.xml +++ b/2.x/chapter8-2/pom.xml @@ -6,16 +6,17 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.6.1 com.didispace - chapter3-8 + chapter8-2 0.0.1-SNAPSHOT - 使用spring-data-jpa的多数据源配置 + 使用log4j2记录日志 + UTF-8 1.8 @@ -23,21 +24,23 @@ org.springframework.boot spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + org.springframework.boot - spring-boot-starter-data-jpa + spring-boot-starter-log4j2 org.springframework.boot - spring-boot-starter-actuator - - - - mysql - mysql-connector-java + spring-boot-starter-test + test @@ -45,21 +48,18 @@ lombok provided - - - org.springframework.boot - spring-boot-starter-test - test - - + 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..b642e6f9 --- /dev/null +++ b/2.x/chapter8-2/src/main/resources/application.properties @@ -0,0 +1,2 @@ + +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 @@ + + + + + + + + + + + + + diff --git a/2.x/chapter8-3/pom.xml b/2.x/chapter8-3/pom.xml new file mode 100644 index 00000000..d6a578e8 --- /dev/null +++ b/2.x/chapter8-3/pom.xml @@ -0,0 +1,81 @@ + + + 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 + 2.4.1 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + + 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} + + + + 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.1.x/chapter1-1/src/main/resources/application.properties b/2.x/chapter8-3/src/main/resources/application.properties similarity index 100% rename from 2.1.x/chapter1-1/src/main/resources/application.properties rename to 2.x/chapter8-3/src/main/resources/application.properties 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 diff --git a/2.x/pom.xml b/2.x/pom.xml index e7db22a7..f20e1714 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基础教程 @@ -16,6 +17,7 @@ chapter1-2 chapter1-3 chapter1-4 + chapter1-5 chapter2-1 @@ -25,21 +27,24 @@ chapter2-5 chapter2-6 chapter2-7 - + chapter2-8 + + chapter3-1 chapter3-2 chapter3-3 chapter3-4 - chapter3-5 - chapter3-6 + chapter3-5 + chapter3-6 chapter3-7 chapter3-8 chapter3-9 chapter3-10 chapter3-11 - chapter3-12 + chapter3-12 + chapter3-13 @@ -49,22 +54,41 @@ chapter4-2 chapter4-3 chapter4-4 - + chapter4-5 chapter5-1 chapter5-2 chapter5-3 chapter5-4 - + chapter5-5 + - - - - - + + chapter6-1 + chapter6-2 + chapter6-3 + chapter6-4 + + + chapter7-1 + chapter7-2 + chapter7-3 + chapter7-4 + chapter7-5 + chapter7-6 + chapter7-7 + chapter7-8 + - + + chapter8-1 + chapter8-2 + chapter8-3 + + + + diff --git a/README.md b/README.md index 77d729ee..916c7fa4 100644 --- a/README.md +++ b/README.md @@ -1,73 +1,37 @@ # Spring Boot基础教程 -本项目内容为[《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://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) - **如何支持**: + 1. 关注我的公众号”**程序猿DD**“ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 + ## 教程目录 -- [Spring Boot 1.x 版本教程](./1.x) -- [Spring Boot 2.x 版本教程](./2.x) +该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。 -> **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
+为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总,后续还会继续跟进3.x版本! -## 特别赞助商 +可以通过下面的链接,进入具体版本的教程目录: - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
+- [Spring Boot 2.x](./2.x) +- [Spring Boot 1.x](./1.x) -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`didi@didispace.com` +> **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
## 推荐内容 - [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 +- [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):聊聊技术人的斜杠生活 -- [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 0c0946db..f75927c3 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1,76 +1,37 @@ # Spring Boot基础教程 -本项目内容为[《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://mp.weixin.qq.com/s/K0BHKqZohfK4jllzLyQA1g) - **如何支持**: + 1. 关注我的公众号”**程序猿DD**“ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 -## 教程目录 +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 -- [Spring Boot 1.x 版本教程](./1.x) -- [Spring Boot 2.x 版本教程](./2.x) +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 -> **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
+## 教程目录 -## 特别赞助商 +该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。 - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
+为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总。 -> 如果您也想赞助支持并出现在上表中的话,可以通过邮件联系我:`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 2.x](./2.x) +- [Spring Boot 1.x](./1.x) + +> **关注公众号:“程序猿DD”**,领取我整理的免费学习资料。
## 推荐内容 - [我的博客](http://blog.didispace.com):分享平时学习和实践过的技术内容 +- [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):聊聊技术人的斜杠生活 -- [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/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 +