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);
  • 相关阅读:
    HTML5学习记录
    CSS学习记录
    HTML扩展(thead,tbody,tfoot标签的使用)
    测删除功能
    jmeter-连接数据库
    jmeter-正则表达式提取器
    jmeter常用函数
    java基础(二)
    git基本使用
    波特的钻石模型
  • 原文地址:https://www.cnblogs.com/xunianchong/p/6650677.html
Copyright © 2011-2022 走看看