基本语法
• key: value;kv之间有空格
• 大小写敏感
• 使用缩进表示层级关系
• 缩进不允许使用tab,只允许空格
• 缩进的空格数不重要,只要相同层级的元素左对齐即可
• '#‘表示注释
• 字符串无需加引号,如果要加,’'与""表示字符串内容 会被 转义/不转义
数据类型
• 字面量:单个的、不可再分的值。date、boolean、string、number、null
k: v
• 对象:键值对的集合。map、hash、set、object
行内写法: k: [v1,v2,v3]
#或者
k:
- v1
- v2
- v3
• 数组:一组按次序排列的值。array、list、queue
行内写法: k: [v1,v2,v3]
#或者
k:
- v1
- v2
- v3
测试
yaml
person:
userName: 张三
boos: true
birth: 2019/12/9
age: 23
# interests: [篮球,足球]
interests:
- 足球
- 篮球
animal: [猫,狗]
score: {english: 90,math: 80}
sakarys:
- 999
- 888
pet:
id: 1
petName: 大黄
allPets:
sick:
- {id: 2,petName: 小花}
- id: 5
petName: 大花
heakth:
- {id: 3,petName: 小绿}
java
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Component
@ConfigurationProperties(prefix = "person")
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;
}
配置提示
自定义的类和配置文件绑定一般没有提示。
<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>