diff --git a/1.x/README.md b/1.x/README.md index a1fcc0fe..0fdaf52c 100644 --- a/1.x/README.md +++ b/1.x/README.md @@ -7,6 +7,7 @@ Spring Boot 2.x版本的教程可在`2.x`目录下查看。 + ## 教程目录(1.x版本) 本教程版本基于Spring Boot 1.3.x - 1.5.x,部分内容可能会有出入。如果您发现问题,首先看版本是否一致。如果还有问题,可以提Issue指出。 diff --git a/1.x/README_zh.md b/1.x/README_zh.md index a1fcc0fe..0fdaf52c 100644 --- a/1.x/README_zh.md +++ b/1.x/README_zh.md @@ -7,6 +7,7 @@ Spring Boot 2.x版本的教程可在`2.x`目录下查看。 + ## 教程目录(1.x版本) 本教程版本基于Spring Boot 1.3.x - 1.5.x,部分内容可能会有出入。如果您发现问题,首先看版本是否一致。如果还有问题,可以提Issue指出。 diff --git a/2.x/README.md b/2.x/README.md index a6627efd..af580d69 100644 --- a/2.x/README.md +++ b/2.x/README.md @@ -4,7 +4,9 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 **如何支持**: @@ -14,20 +16,20 @@ ## 教程目录(2.x版本) -连载中...Star关注支持一下,随时获得更新信息! +本教程内容持续更新连载中!**Star关注**支持一下,随时获得更新信息! -### 基础知识 +### 快速入门 - [Spring Boot 2.x基础教程:版本关系](http://blog.didispace.com/spring-cloud-alibaba-version/) - [Spring Boot 2.x基础教程:快速入门](http://blog.didispace.com/spring-boot-learning-21-1-1/) - [Spring Boot 2.x基础教程:工程结构推荐](http://blog.didispace.com/spring-boot-learning-21-1-2/) -### 配置文件 +### 配置详解 - [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/) -- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化](http://blog.didispace.com/spring-boot-learning-24-1-4/) - [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/) +- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:加密配置中的敏感信息](http://blog.didispace.com/spring-boot-learning-2-1-5/) ### API开发 @@ -56,7 +58,7 @@ - [Spring Boot 2.x基础教程:MyBatis的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-9/) - [Spring Boot 2.x基础教程:事务管理入门](http://blog.didispace.com/spring-boot-learning-21-3-10/) - [Spring Boot 2.x基础教程:使用Flyway管理数据库版本](http://blog.didispace.com/spring-boot-learning-24-3-11/) -- [Spring Boot 2.x基础教程:使用JTA实现分布式事务](http://blog.didispace.com/spring-boot-learning-24-3-12/) +- [Spring Boot 2.x基础教程:使用JTA实现多数据源的事务管理](http://blog.didispace.com/spring-boot-learning-24-3-12/) - [Spring Boot 2.x基础教程:2.5版本后数据脚本初始化的变动](http://blog.didispace.com/spring-boot-learning-25-3-13/) **加速利器:各种缓存的使用** @@ -72,14 +74,15 @@ - [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基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) +- [Spring Boot 2.x基础教程:多个文件的上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) +- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](http://blog.didispace.com/spring-boot-learning-21-4-5/) ### 任务管理 @@ -97,12 +100,28 @@ - [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/) ## 版本资讯 @@ -114,20 +133,15 @@ - [Spring Boot 2.0 新特性(一):配置绑定 2.0 全解析](http://blog.didispace.com/Spring-Boot-2-0-feature-1-relaxed-binding-2/) - [Spring Boot 2.0 新特性(二):新增事件ApplicationStartedEvent](http://blog.didispace.com/Spring-Boot-2-0-feature-2-ApplicationStartedEvent/) -### 2.x版本信息 - -- [Spring Boot 2.2 正式发布,大幅性能提升 + Java 13 支持](http://blog.didispace.com/spring-boot-2-2-release/) -- [Spring Boot 2.3.0 发布](/spring-boot-2-3-0-release/) -- [Spring Boot 2.3.0 放弃 Maven 转投 Gradle](/spring-boot-gradle/) -- [Spring Boot 2.3.2 发布,解决 Too many open files 导致的应用宕机问题](http://blog.didispace.com/spring-boot-2-3-2-release/) -- [Spring Boot 2.4.0 正式发布!全新的配置处理机制,拥抱云原生!](http://blog.didispace.com/spring-boot-2-4-0-ga/) -- [Spring Boot 2.4.1 发布,修正大量2.4全新配置机制的Bug](http://blog.didispace.com/spring-boot-2-4-1-release/) -- [Spring Boot 2.5.0 发布:支持Java16、Gradle 7、Datasource初始化调整](https://blog.didispace.com/spring-boot-2-5-0-release/) -- [Spring Boot 2.5.1 发布](https://blog.didispace.com/spring-boot-2-5-1-release/) +更多关于2.x的版本信息可查看[点击查看](http://www.springcloud.com.cn/) ## 我的公众号 - + + +## 推荐我的书 + +![Spring Boot微服务实战](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png) ## 特别赞助商 diff --git a/2.x/README_zh.md b/2.x/README_zh.md index fd94ee25..70612143 100644 --- a/2.x/README_zh.md +++ b/2.x/README_zh.md @@ -4,9 +4,12 @@ **专题目标**:打造全网内容最全,比收费教程更好的Spring Boot免费教程! -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 **如何支持**: + 1. 关注我的公众号”**程序猿DD**“ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 @@ -15,20 +18,20 @@ ## 教程目录(2.x版本) -连载中...Star关注支持一下,随时获得更新信息! +本教程内容持续更新连载中!**Star关注**支持一下,随时获得更新信息! -### 基础知识 +### 快速入门 - [Spring Boot 2.x基础教程:版本关系](http://blog.didispace.com/spring-cloud-alibaba-version/) - [Spring Boot 2.x基础教程:快速入门](http://blog.didispace.com/spring-boot-learning-21-1-1/) - [Spring Boot 2.x基础教程:工程结构推荐](http://blog.didispace.com/spring-boot-learning-21-1-2/) -### 配置文件 +### 配置详解 - [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/) -- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化](http://blog.didispace.com/spring-boot-learning-24-1-4/) - [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/) +- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/) - [Spring Boot 2.x基础教程:加密配置中的敏感信息](http://blog.didispace.com/spring-boot-learning-2-1-5/) ### API开发 @@ -57,7 +60,7 @@ - [Spring Boot 2.x基础教程:MyBatis的多数据源配置](http://blog.didispace.com/spring-boot-learning-21-3-9/) - [Spring Boot 2.x基础教程:事务管理入门](http://blog.didispace.com/spring-boot-learning-21-3-10/) - [Spring Boot 2.x基础教程:使用Flyway管理数据库版本](http://blog.didispace.com/spring-boot-learning-24-3-11/) -- [Spring Boot 2.x基础教程:使用JTA实现分布式事务](http://blog.didispace.com/spring-boot-learning-24-3-12/) +- [Spring Boot 2.x基础教程:使用JTA实现多数据源的事务管理](http://blog.didispace.com/spring-boot-learning-24-3-12/) - [Spring Boot 2.x基础教程:2.5版本后数据脚本初始化的变动](http://blog.didispace.com/spring-boot-learning-25-3-13/) **加速利器:各种缓存的使用** @@ -73,15 +76,15 @@ - [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基础教程:文件上传的单元测试怎么写](https://blog.didispace.com/spring-boot-learning-21-4-5/) +- [Spring Boot 2.x基础教程:多个文件的上传](http://blog.didispace.com/spring-boot-learning-21-4-4/) +- [Spring Boot 2.x基础教程:文件上传的单元测试怎么写](http://blog.didispace.com/spring-boot-learning-21-4-5/) ### 任务管理 @@ -99,12 +102,28 @@ - [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/) ## 版本资讯 @@ -136,11 +155,11 @@ ## 我的公众号 - + ## 推荐我的书 -![](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png "在这里输入图片标题") +![Spring Boot微服务实战](https://git.oschina.net/uploads/images/2017/0416/233656_dd3bce94_437188.png) ## 特别赞助商 diff --git a/2.x/chapter1-4/pom.xml b/2.x/chapter1-4/pom.xml index 8c5539f1..5bbd4008 100644 --- a/2.x/chapter1-4/pom.xml +++ b/2.x/chapter1-4/pom.xml @@ -11,7 +11,7 @@ com.didispace chapter1-4 0.0.1-SNAPSHOT - chapter1-1 + chapter1-4 配置元数据的应用 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.x/chapter4-5/pom.xml b/2.x/chapter4-5/pom.xml new file mode 100644 index 00000000..7120c77a --- /dev/null +++ b/2.x/chapter4-5/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + com.didispace + chapter4-5 + 0.0.1-SNAPSHOT + Spring Security快速入门 + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-security + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + \ No newline at end of file diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/Application.java similarity index 91% rename from 2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java rename to 2.x/chapter4-5/src/main/java/com/didispace/chapter45/Application.java index f7a9e16e..00d2d076 100644 --- a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/Application.java +++ b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/Application.java @@ -1,4 +1,4 @@ -package com.didispace; +package com.didispace.chapter45; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/HelloController.java similarity index 95% rename from 2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java rename to 2.x/chapter4-5/src/main/java/com/didispace/chapter45/HelloController.java index f5a6770b..849a125d 100644 --- a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/HelloController.java +++ b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/HelloController.java @@ -1,4 +1,4 @@ -package com.didispace.chapter81; +package com.didispace.chapter45; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/WebSecurityConfig.java similarity index 97% rename from 2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java rename to 2.x/chapter4-5/src/main/java/com/didispace/chapter45/WebSecurityConfig.java index 1f3da340..30fffef5 100644 --- a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/WebSecurityConfig.java +++ b/2.x/chapter4-5/src/main/java/com/didispace/chapter45/WebSecurityConfig.java @@ -1,4 +1,4 @@ -package com.didispace.chapter81; +package com.didispace.chapter45; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; 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/chapter8-1/src/main/resources/templates/hello.html b/2.x/chapter4-5/src/main/resources/templates/hello.html similarity index 100% rename from 2.x/chapter8-1/src/main/resources/templates/hello.html rename to 2.x/chapter4-5/src/main/resources/templates/hello.html diff --git a/2.x/chapter8-1/src/main/resources/templates/index.html b/2.x/chapter4-5/src/main/resources/templates/index.html similarity index 100% rename from 2.x/chapter8-1/src/main/resources/templates/index.html rename to 2.x/chapter4-5/src/main/resources/templates/index.html diff --git a/2.x/chapter8-1/src/main/resources/templates/login.html b/2.x/chapter4-5/src/main/resources/templates/login.html similarity index 100% rename from 2.x/chapter8-1/src/main/resources/templates/login.html rename to 2.x/chapter4-5/src/main/resources/templates/login.html diff --git a/2.x/chapter6-4/pom.xml b/2.x/chapter6-4/pom.xml new file mode 100644 index 00000000..c1683b06 --- /dev/null +++ b/2.x/chapter6-4/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + com.didispace + chapter6-4 + 1.0.0 + jar + 使用PostgreSQL数据库 + + + org.springframework.boot + spring-boot-starter-parent + 2.5.1 + + + + + UTF-8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.postgresql + postgresql + runtime + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java new file mode 100644 index 00000000..83ebf477 --- /dev/null +++ b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/Chapter64Application.java @@ -0,0 +1,14 @@ +package com.didispace.chapter64; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication +public class Chapter64Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter64Application.class, args); + } + +} diff --git a/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java new file mode 100644 index 00000000..cc83d361 --- /dev/null +++ b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfo.java @@ -0,0 +1,26 @@ +package com.didispace.chapter64; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +@Data +@NoArgsConstructor +public class UserInfo { + + @Id + @GeneratedValue + private Long id; + + private String name; + private Integer age; + + public UserInfo(String name, Integer age) { + this.name = name; + this.age = age; + } +} \ No newline at end of file diff --git a/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfoRepository.java b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfoRepository.java new file mode 100644 index 00000000..85214e24 --- /dev/null +++ b/2.x/chapter6-4/src/main/java/com/didispace/chapter64/UserInfoRepository.java @@ -0,0 +1,22 @@ +package com.didispace.chapter64; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +/** + * Created by 程序猿DD/翟永超 on 2021/10/08. + *

+ * Blog: http://blog.didispace.com/ + * Github: https://github.com/dyc87112/ + */ +public interface UserInfoRepository extends JpaRepository { + + UserInfo findByName(String name); + + UserInfo findByNameAndAge(String name, Integer age); + + @Query("from UserInfo u where u.name=:name") + UserInfo findUser(@Param("name") String name); + +} diff --git a/2.x/chapter6-4/src/main/resources/application.properties b/2.x/chapter6-4/src/main/resources/application.properties new file mode 100644 index 00000000..3c000bf2 --- /dev/null +++ b/2.x/chapter6-4/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.datasource.url=jdbc:postgresql://localhost:5432/test +spring.datasource.username=postgres +spring.datasource.password=123456 +spring.datasource.driver-class-name=org.postgresql.Driver + +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.properties.hibernate.hbm2ddl.auto=create \ No newline at end of file diff --git a/2.x/chapter6-4/src/test/java/com/didispace/chapter64/ApplicationTests.java b/2.x/chapter6-4/src/test/java/com/didispace/chapter64/ApplicationTests.java new file mode 100644 index 00000000..1ae64fb4 --- /dev/null +++ b/2.x/chapter6-4/src/test/java/com/didispace/chapter64/ApplicationTests.java @@ -0,0 +1,51 @@ +package com.didispace.chapter64; + + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@Slf4j +@SpringBootTest +public class ApplicationTests { + + @Autowired + private UserInfoRepository userRepository; + + @Test + public void test() throws Exception { + // 创建10条记录 + userRepository.save(new UserInfo("AAA", 10)); + userRepository.save(new UserInfo("BBB", 20)); + userRepository.save(new UserInfo("CCC", 30)); + userRepository.save(new UserInfo("DDD", 40)); + userRepository.save(new UserInfo("EEE", 50)); + userRepository.save(new UserInfo("FFF", 60)); + userRepository.save(new UserInfo("GGG", 70)); + userRepository.save(new UserInfo("HHH", 80)); + userRepository.save(new UserInfo("III", 90)); + userRepository.save(new UserInfo("JJJ", 100)); + + // 测试findAll, 查询所有记录 + Assertions.assertEquals(10, userRepository.findAll().size()); + + // 测试findByName, 查询姓名为FFF的User + Assertions.assertEquals(60, userRepository.findByName("FFF").getAge().longValue()); + + // 测试findUser, 查询姓名为FFF的User + Assertions.assertEquals(60, userRepository.findUser("FFF").getAge().longValue()); + + // 测试findByNameAndAge, 查询姓名为FFF并且年龄为60的User + Assertions.assertEquals("FFF", userRepository.findByNameAndAge("FFF", 60).getName()); + + // 测试删除姓名为AAA的User + userRepository.delete(userRepository.findByName("AAA")); + + // 测试findAll, 查询所有记录, 验证上面的删除是否成功 + Assertions.assertEquals(9, userRepository.findAll().size()); + + } + +} diff --git a/2.x/chapter8-1/pom.xml b/2.x/chapter8-1/pom.xml index 81817f27..d60616ec 100644 --- a/2.x/chapter8-1/pom.xml +++ b/2.x/chapter8-1/pom.xml @@ -13,7 +13,7 @@ com.didispace chapter8-1 0.0.1-SNAPSHOT - Spring Security快速入门 + 默认日志管理与Logback配置详解 UTF-8 @@ -23,7 +23,7 @@ org.springframework.boot - spring-boot-starter + spring-boot-starter-web @@ -33,19 +33,10 @@ - org.springframework.boot - spring-boot-starter-web + org.projectlombok + lombok + provided - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-security - - diff --git a/2.x/chapter8-1/src/main/java/com/didispace/chapter81/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 index e69de29b..361847c5 100644 --- a/2.x/chapter8-1/src/main/resources/application.properties +++ b/2.x/chapter8-1/src/main/resources/application.properties @@ -0,0 +1,14 @@ +debug=true + +spring.output.ansi.enabled=detect + +logging.file.name=run.log +logging.file.path=./ + +logging.level.com.didispace=debug + +logging.logback.rollingpolicy.clean-history-on-start=false +logging.logback.rollingpolicy.file-name-pattern= +logging.logback.rollingpolicy.max-history=7 +logging.logback.rollingpolicy.max-file-size=10MB +logging.logback.rollingpolicy.total-size-cap=0B diff --git a/2.x/chapter8-2/pom.xml b/2.x/chapter8-2/pom.xml new file mode 100644 index 00000000..eeda9143 --- /dev/null +++ b/2.x/chapter8-2/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.6.1 + + + + com.didispace + chapter8-2 + 0.0.1-SNAPSHOT + 使用log4j2记录日志 + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.projectlombok + lombok + provided + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + \ No newline at end of file diff --git a/2.x/chapter8-2/src/main/java/com/didispace/chapter82/Chapter82Application.java b/2.x/chapter8-2/src/main/java/com/didispace/chapter82/Chapter82Application.java new file mode 100644 index 00000000..be62c0c2 --- /dev/null +++ b/2.x/chapter8-2/src/main/java/com/didispace/chapter82/Chapter82Application.java @@ -0,0 +1,26 @@ +package com.didispace.chapter82; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author 程序猿DD + * @version 1.0.0 + * @blog https://blog.didispace.com + */ +@Slf4j +@SpringBootApplication +public class Chapter82Application { + + public static void main(String[] args) { + SpringApplication.run(Chapter82Application.class, args); + + log.error("Hello World"); + log.warn("Hello World"); + log.info("Hello World"); + log.debug("Hello World"); + log.trace("Hello World"); + } + +} diff --git a/2.x/chapter8-2/src/main/resources/application.properties b/2.x/chapter8-2/src/main/resources/application.properties new file mode 100644 index 00000000..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.x/chapter8-3/src/main/resources/application.properties b/2.x/chapter8-3/src/main/resources/application.properties new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/2.x/chapter8-3/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/2.x/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 293aad51..f20e1714 100644 --- a/2.x/pom.xml +++ b/2.x/pom.xml @@ -54,7 +54,7 @@ chapter4-2 chapter4-3 chapter4-4 - + chapter4-5 chapter5-1 @@ -62,13 +62,14 @@ chapter5-3 chapter5-4 chapter5-5 - + - + chapter6-1 chapter6-2 chapter6-3 - + chapter6-4 + chapter7-1 @@ -81,8 +82,13 @@ chapter7-8 - - chapter8-1 + + chapter8-1 + chapter8-2 + chapter8-3 + + + diff --git a/README.md b/README.md index 84dea730..916c7fa4 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,15 @@ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 ## 教程目录 该教程自2016年连载至今,因内容较多,经历过多个版本的迭代。 -为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总。 +为方便查看学习,这里重新做了整理,根据1.x版本和2.x版本做了区分汇总,后续还会继续跟进3.x版本! 可以通过下面的链接,进入具体版本的教程目录: diff --git a/README_zh.md b/README_zh.md index 84dea730..f75927c3 100644 --- a/README_zh.md +++ b/README_zh.md @@ -8,7 +8,9 @@ 2. 点个`Star`并`Follow`我 3. 把该仓库分享给更多的朋友 -**加入社群**:[如果你正在学习Spring Boot,不妨加入我们的Spring技术交流群,一起成长!](https://blog.didispace.com/join-group-spring/index.html) +**加入社群**:如果你正在学习Spring Boot,不妨加入我们的[Spring技术交流群](https://blog.didispace.com/join-group-spring/index.html) ,一起成长 + +**Spring社区**:如果您在学习过程中碰到问题,可以访问[SpringForAll社区](http://spring4all.com),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章 ## 教程目录