2种读取yml文件的方式
@RequestMapping("/test4")
public String getInfo4(){
YamlPropertiesFactoryBean y=new YamlPropertiesFactoryBean();
y.setResources(new ClassPathResource("01.yaml"));
String result=String.valueOf(y.getObject().get("user.username"));
return result;
}
@RequestMapping("/test5")
public String getInfo5(){
YamlMapFactoryBean y=new YamlMapFactoryBean();
y.setResources(new ClassPathResource("01.yaml"));
Map<String,Object> map=y.getObject();
Map<String,Map> resultMap=(Map)map.get("user");
String result=String.valueOf(resultMap.get("password"));
return result;
}
其中resources下的01.yaml内容如下:
user:
username: paul
password: linux
|