@Value 注入 List Map

YAML 语法 

  • “ ”  双引号:不会转义字符串里面的特殊字符  特殊字符会作为本身想表示的意思

             name: hello \n world:输出;hello 换行 world

  • ‘ ’   单引号:会转义特殊字符  特殊字符最终只是一个普通的字符串数据

             name: hello \n world:输出;hello \n world

application.yml:

test:
  str: https://google.com
  list: qq,ww,ee
  map: "{key1: 'value1', key2: 'value2'}"

属性获取: 

    @Value("${test.str}")
    private  String str;

    //@Value("${test.list}") 该方式测试也OK
    @Value("#{'${test.list}'.split(',')}")
    private List<String> list;
    
    @Value("#{${test.map}}")
    private Map<String,String> map;
 

猜你喜欢

转载自blog.csdn.net/xiangwang2016/article/details/106752352