yaml草稿
yaml的列表
american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
national:
- New York Mets
- Chicago Cubs
- Atlanta Braves
hr:
- Mark McGwire
# Following node labeled SS
- &SS Sammy Sosa
rbi:
- *SS # Subsequent occurrence
- Ken Griffey
那么yml考虑到了这个特性,也允许你是用|或是_来标注接下来的内容将涉及跨行
server . port=808 1
s tudent . studentName=l fguan
student . student- id=23
student . studentAge=8 9
student . birth=2018/12/ 12
student .maps . test= 1
student .maps . test2=2
student. lists: 1,2,3,4
wwwww..
#student. lists [0] =dog
student . teacher . teache rName=$ { student . studentName } tes t
student. teacher . teacherId=$ { random. int (100) }
school . schoolName=- 中
school . address=合肥市
school . createTime=2019/ 12/ 12
htps://log.csdn.netbaoshen
my:
#map
name: ignore
#数组
jobs:
- it
- teacher
#数组加map
ip:
- host: 127.0.0.1
port: 22
- host: 10.10.0.1
port: 21
key:
child-key: value
child-key2: value2
key [key,vaue]
key: {child-key: value, child-key2: value2}
可以使用问号加一个空格代表一个复杂的key,配合一个冒号加一个空格代表一个value:
?
- complexkey1
- complexkey2
:
- complexvalue1
- complexvalue2
companies:
-
id: 1
name: company1
price: 200W
-
id: 2
name: company2
price: 500W
companies: [{id: 1,name: company1,price: 200W},{id: 2,name: company2,price: 500W}]
可以进行长短结合
3,!! YAML中使用!!做类型强行转换:
string:
- !!str 54321
- !!str true
--- !!set
- Mark McGwire: 65
- Sammy Sosa: 63
- Sammy Sosa: 63
- Ken Griffy: 58
锚点 结构乱 有时可以考虑直接用key的名字
<!-- 导入文件处理器,配置文件进行绑定的时候,就会有提示-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
my.servers[0]=dev.bar.com
my.servers[1]=foo.bar.com
注:spring环境中,YamlPropertySourceLoader类能够将YAML作为PropertySource导出到Sprig Environment。因此可以使用常用的@Value注解配合占位符语法访问YAML属性。
springboot
当三种文件同时存在时,其实三个文件中的配置信息都会生效
优先级是:properties>yaml>yml
这里的逻辑顺序是先加载yml再加载yaml再加properties,后加载的自然会把先加载的数据给覆盖掉.
配置文件放在src/main/resources目录或者类路径/config下