yaml(yml)文件数据格式(List、Map、Object、基本数据类型)
准备类:
@Data
@Component
public class Dog {
private String name;
private Integer age;
}
@Data
@Configuration
@ConfigurationProperties(prefix = "person")
public class Person {
private String name;
private Integer age;
private boolean gender;
private LocalDate birthday;
private List<Dog> lists;
private Map<String,Object> maps;
private Dog dog;
private List<String> stringList;
private Map<String,Dog> dogMap;
}
格式示例如下:
#yaml格式本身是键值对表示。
#以空格为缩进。键: 值的形式存在。键后跟英文:和空格,与值。
# #则表示注释
#person:
# name: cs #字符串可以不打引号,也可打单引号或双引号
# age: 27
# gender: true
# birthday: 2020/12/21
# dog: #包含对象时,则值应该与类中的字段名一致
# name: wangcai #类似于person.dog.name
# age: 10
#List有三种写法。
#第一种:[{},{},...]
# lists: [{name: 'test1', age: 1},{name: 'test2', age: 2}]
#第二种:-,换行后键值
# -
# name: test1
# age: 1
# -
# name: test2
# age: 2
#第三种:- {}
# - {name: test1,age: 1}
# - {name: test2,age: 2}
# stringList: [手打,多少度]
# - sad
# - 222
# Map两种写法。
# 第一种:{key1:{},key2:{}...}
#基本对象就是{key1: value1,....}
# maps: {k1: v1,k2: v2}
# dogMap: {str1: {name: d1, age: 1},str2: {name: d2, age: 2}}
#第二种:按照对象缩进
# str1:
# name: d1
# age: 1
# str2:
# name: d2
# age: 2