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