文章目錄
- 1. 文件類型
- 1.1 properties
- 1.2 yaml
- 1.2.1 簡介
- 1.2.2 基本語法
- 1.2.3 數據類型
- 1.2.4 示例
- 2. 配置提示
1. 文件類型
1.1 properties
同以前的properties的用法
1.2 yaml
1.2.1 簡介
YAML 是 “YAML Ain’t Markup Language”(YAML 不是一種標記語言)的遞歸縮寫。在開發的這種語言時,YAML 的意思其實是:“Yet Another Markup Language”(仍是一種標記語言)。
非常適合用來做以數據為中心的配置文件
1.2.2 基本語法
- key: value;kv之間有空格
- 大小寫敏感
- 使用縮進表示層級關系
- 縮進不允許使用tab,只允許空格
- 縮進的空格數不重要,只要相同層級的元素左對齊即可
- '#'表示注釋
- 字符串無需加引號,如果要加,''與""表示字符串內容 會被 轉義/不轉義
1.2.3 數據類型
- 字面量:單個的、不可再分的值。date、boolean、string、number、null
k: v
- 對象:鍵值對的集合。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
1.2.4 示例
@Data
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;
}@Data
public class Pet {private String name;private Double weight;
}
# yaml表示以上對象
person:userName: zhangsanboss: falsebirth: 2019/12/12 20:12:33age: 18pet: name: tomcatweight: 23.4interests: [籃球,游泳]animal: - jerry- marioscore:english: first: 30second: 40third: 50math: [131,140,148]chinese: {first: 128,second: 136}salarys: [3999,4999.98,5999.99]allPets:sick:- {name: tom}- {name: jerry,weight: 47}health: [{name: mario,weight: 47}]
2. 配置提示
自定義的類和配置文件綁定一般沒有提示。
<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>