zoukankan      html  css  js  c++  java
  • spring中PropertyPlaceholderHelper替换占位符的值

    1.Properties中的值替换¥{}或者#{}占位符

        String text = "foo=${foo},bar=${bar}";
            Properties props = new Properties();
            props.setProperty("foo", "foo_value");
            props.setProperty("bar", "bar_value");
            PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}", null, false);
            System.out.println( helper.replacePlaceholders(text, props));

    2.hashmap或者对象替换¥{}或者#{}占位符

    final Map<String,String> params = new HashMap<>();
            params.put("foo", "bar");
            params.put("bar", "bar");
            PropertyPlaceholderHelper helper1 = new PropertyPlaceholderHelper("${", "}", null, false);
            String s = helper1.replacePlaceholders(text, new PlaceholderResolver() {
                @Override
                public String resolvePlaceholder(String placeholderName) {
                    // TODO Auto-generated method stub
                    return params.get(placeholderName);
                }
            });
            System.out.println(s);
  • 相关阅读:
    maven项目诡异的问题
    13) Developing Java Plugins
    15) maven dependency scope
    Bootstrap学习记录
    电力
    MongoDB学习记录
    Java基础知识
    旅游
    人生感悟
    【转】25岁到55岁:如何规划人生最重要的三个十年
  • 原文地址:https://www.cnblogs.com/xunianchong/p/6650677.html
Copyright © 2011-2022 走看看