學習視頻:https://www.bilibili.com/video/BV19K4y1L7MT?p=20
語法:同以前的properties用法
字面量:單個的、不可再分的值。date、boolean、string、number、null
k: v
一步一步學SpringBoot2、對象:鍵值對的集合。map、hash、set、object
行內寫法: k: {k1: v1,k2: v2,k3: v3}
#或
k: k1: v1k2: v2k3: v3
數組:一組按次序排列的值。array、list、queue
行內寫法: k: [v1,v2,v3]
#或者
k:- v1- v2
- v3
javabean—Person.class
@ConfigurationProperties(prefix = "person")
@Component
@Getter
@Setter
@ToString(includeFieldNames = false, exclude = {"boss", "animal", "score", "salary","allPets"})
@NoArgsConstructor
@AllArgsConstructor
public class Person {private String userName;private Boolean boss;private Date birth;private Integer age;private Pet pet;private String[] interests;private List<String> animal;private Map<String, Object> score;private Set<Double> salarys;private Map<String, List<Pet>> allPets;
}
javabean—Pet.class
@Component
@ConfigurationProperties(prefix = "pet")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Pet {private String name;private Double weight;
}
SpringBoot入門。配置文件—application.yml
person:username: desertsboss: falsebirth: 2000/01/01 11:11:11age: 18pet:name: tomcatweigth: 33.3interes: [跑步, 羽毛球]animal:- dog- cat- pigscore:English: [80, 90, 100]Math:first: 45second: 55thrid: 65salarys: [8888, 9999, 10000]allPets:health:- {name: tom, weight: 30}- {name: jerry}sick:- {name: trump, weight: 100}
自定義的類和配置文件綁定一般沒有提示,添加依賴
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency>
打包時不帶上配置處理器
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId></exclude></excludes></configuration></plugin></plugins></build>
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态