一、语法格式
#字面量
ka: v
#对象
kb: {k1: v1, k2: v2, k3: v3}
kc:
k1: v1
k2: v2
k3: v3
#数组
kd: [v1,v2,v3]
k:
- v1
- v2
- v3
二、Yml为实体类的属性赋值
1、例子
实体类
@ConfigurationProperties(prefix = "person")
@Component
@ToString
@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<Dog>> allPets;
}
对应yml中的属性值
person:
userName: zhangsan
boss: true
birth: 2019/12/9
age: 18
pet:
name: 小狗a
weight: 20.2
# interests: [篮球,足球]
interests:
- 篮球
- 足球
animal: [cat, dog]
# score: {engligh: 80, math:90}
score:
english: 80
math: 90
salarys:
- 9999
- 9998
allPets:
sick:
- {name: 阿狗, weight: 99.99}
- name: 阿猫
weight: 88.88
health:
- { name: 阿蓝, weight: 99.99 }
- { name: 阿橙, weight: 99.99 }