zno2

${property-name} 通过:设置默认值,格式到底是什么样的

org.springframework.beans.factory.config.PlaceholderConfigurerSupport

 

The values to replace are specified as 'placeholders' of the form ${property-name} which follows the Ant / Log4J / JSP EL style.

 

有个疑问,${aa:1} 如何解析其中的aa,那么要分析他的格式,前缀必须是"${" ,后缀必须是"}",默认值必须以":"分割,且是第一个冒号后面的都是默认值

	@Value("${a:1:2}")
	private String a;

a的默认值是"1:2" 

 

 

 

 

 

 

需求是如何获取prop?

    public static String prop(String valueExpression) {
        if (valueExpression == null) {
            return null;
        }
        valueExpression = valueExpression.trim();

        int index1 = valueExpression.indexOf("${");
        int index2 = valueExpression.lastIndexOf("}");
        if (index1 == -1 || index2 == -1 || index1 >= index2) {
            return null;
        }
        return valueExpression.substring(index1 + 2, index2).split(":")[0];
    }

 

posted on 2023-06-02 08:09  zno2  阅读(81)  评论(0编辑  收藏  举报

导航