yaml草稿-给自己看的

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下
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值