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 Mapparams = 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);