1、StrSubstitutor
StrSubstitutor是一个很特殊的类,在String中使用${key}的方法在形成了一个可配置的模板,new一个HashMap使用HashMap替换String模板
示例
@Test public void testStrSubstitutor(){ Map<String,String> valuesMap = new HashMap<String,String>(); valuesMap.put("animal", "quick brown fox"); valuesMap.put("target", "lazy dog"); String templateString = "The ${animal} jumped over the ${target}."; System.out.println(templateString); StrSubstitutor sub = new StrSubstitutor(valuesMap); String resolvedString = sub.replace(templateString); System.out.println(resolvedString); }