一、springBoot-03-配置文件、数据校验JSR303
1、使用@value注入值
## 2、使用配置文件注入值
1.了解配置文件
- 在SpringBoot中,配置文件可以有两种格式,分别是:application.properties和application.yaml。
- 两者最明显的区别是:在yaml中可以写对象,而在properties中只能以键值对的形式。
- 通过注解@ConfigurationProperties来获取配置文件中的值,使用前导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
- 注意:
2.如何赋值和取值
a)、@ConfigurationProperties注解
b)、@PropertySource指定配置文件
3.松散绑定
4.配置文件的位置
5.多环境配置如何激活其中一个配置文件
3、数据校验JSR303
- 需要导入的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
相关资源: 学习狂神说 学习地址(以上仅为笔记)