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),描述你的问题,我们会尽快给你答复。当然,如果你想分享你的学习经验,也可以在这里发表你的文章
## 教程目录