0%

spring注解Value设置默认值

文章字数:33,阅读全文大约需要1分钟

  • 字符串
    1
    2
    3
    4
    5
    @Value("${some.key:my default value}")
    private String stringWithDefaultValue;
    //空值
    @Value("${some.key:}")
    private String stringWithBlankDefaultValue;
  • 基本数据类型
    1
    2
    3
    4
    5
    @Value("${some.key:true}")
    private boolean booleanWithDefaultValue;

    @Value("${some.key:42}")
    private int intWithDefaultValue;
  • 数组默认值
    1
    2
    3
    4
    5
    @Value("${some.key:one,two,three}")
    private String[] stringArrayWithDefaults;

    @Value("${some.key:1,2,3}")
    private int[] intArrayWithDefaults;