From dd65ce69631e09057433075a076f203895f8dd22 Mon Sep 17 00:00:00 2001 From: barney <15270405776@163.com> Date: Fri, 3 Mar 2023 23:18:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E5=A4=9A=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springaop/service/UserServiceTest.java | 8 +++- annotations/pom.xml | 7 +++ .../controller/PersonController.java | 17 +++++++ .../cc/bnblogs/annotations/entity/Person.java | 48 +++++++++++++++++++ .../src/main/resources/application.properties | 10 +++- .../main/resources/static/person.properties | 4 ++ 6 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 annotations/src/main/java/cc/bnblogs/annotations/controller/PersonController.java create mode 100644 annotations/src/main/java/cc/bnblogs/annotations/entity/Person.java create mode 100644 annotations/src/main/resources/static/person.properties diff --git a/SpringAOP/src/test/java/cc/bnblogs/springaop/service/UserServiceTest.java b/SpringAOP/src/test/java/cc/bnblogs/springaop/service/UserServiceTest.java index d3b89fe..4b8c032 100644 --- a/SpringAOP/src/test/java/cc/bnblogs/springaop/service/UserServiceTest.java +++ b/SpringAOP/src/test/java/cc/bnblogs/springaop/service/UserServiceTest.java @@ -3,12 +3,18 @@ package cc.bnblogs.springaop.service; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import static org.junit.jupiter.api.Assertions.*; @SpringBootTest class UserServiceTest { - @Autowired + private UserService userService; + @Autowired + public UserServiceTest(UserService userService) { + this.userService = userService; + } @Test void funA() { diff --git a/annotations/pom.xml b/annotations/pom.xml index d846c7c..08cba9b 100644 --- a/annotations/pom.xml +++ b/annotations/pom.xml @@ -21,11 +21,18 @@ org.springframework.boot spring-boot-starter-web + org.springframework.boot spring-boot-starter-freemarker + + org.springframework.boot + spring-boot-configuration-processor + true + + org.springframework.boot spring-boot-devtools diff --git a/annotations/src/main/java/cc/bnblogs/annotations/controller/PersonController.java b/annotations/src/main/java/cc/bnblogs/annotations/controller/PersonController.java new file mode 100644 index 0000000..115791e --- /dev/null +++ b/annotations/src/main/java/cc/bnblogs/annotations/controller/PersonController.java @@ -0,0 +1,17 @@ +package cc.bnblogs.annotations.controller; + +import cc.bnblogs.annotations.entity.Person; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class PersonController { + @Autowired + private Person person; + + @GetMapping("/person/") + public Person getPerson() { + return person; + } +} diff --git a/annotations/src/main/java/cc/bnblogs/annotations/entity/Person.java b/annotations/src/main/java/cc/bnblogs/annotations/entity/Person.java new file mode 100644 index 0000000..eca03f1 --- /dev/null +++ b/annotations/src/main/java/cc/bnblogs/annotations/entity/Person.java @@ -0,0 +1,48 @@ +package cc.bnblogs.annotations.entity; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Component; + +@Component +@PropertySource(value = {"classpath:static/person.properties"}) +@ConfigurationProperties(prefix = "person") +public class Person { + private String name; + private String password; + private String sex; + private Integer age; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } +} diff --git a/annotations/src/main/resources/application.properties b/annotations/src/main/resources/application.properties index d58c86f..3b31a60 100644 --- a/annotations/src/main/resources/application.properties +++ b/annotations/src/main/resources/application.properties @@ -6,7 +6,15 @@ spring.mvc.view.suffix=.html spring.freemarker.suffix=.html spring.freemarker.template-loader-path=classpath:/static/ -# ??????? +# \u7F16\u7801\u8BBE\u7F6E\u4E3AUTF-8 +server.servlet.encoding.force=true +server.servlet.encoding.charset=UTF-8 + my.page=1 local.username=admin local.password=admin123 + +#person.name=admin +#person.password=123123 +#person.sex=\u7537 +#person.age=18 diff --git a/annotations/src/main/resources/static/person.properties b/annotations/src/main/resources/static/person.properties new file mode 100644 index 0000000..5c9c4fa --- /dev/null +++ b/annotations/src/main/resources/static/person.properties @@ -0,0 +1,4 @@ +person.name=admin +person.password=123123 +person.sex=\u5973 +person.age=18 \ No newline at end of file