配置文件添加了:
name=zrl
bir=2021/2/16
如果想在对象中取到这个值,需要使用
@Value("${name}")
private String name
@Value("${bir}")
private Date bir
yml数据结构格式:
-
数组:直接用逗号分隔,例如
aa,bb,cc
,注入时标明数组格式 -
列表:直接用逗号分隔,例如
aa,bb,cc
,注入时标明列表格式 -
Map:@Value取值格式是
#{${mapname}}
properties格式是mapname={key:value,key:value...}
,yml格式如下mapname.aa=111
mapname.bb=222
mapname.cc=333
-
对象:以user类,properties格式为例,
user.name=xx
,user.age=xx
,然后在实体类添加两个注解@Component
@ConfigurationProperties(prefix = "user")