Apache commons StringSubstitutor 替换占位符

   Apache commons  StringSubstitutor  替换占位符

 

 



    org.apache.commons
    commons-lang3
    3.7

 

 Map valuesMap = HashMap();
 valuesMap.put("animal", "quick brown fox");
 valuesMap.put("target", "lazy dog");
 String templateString = "The ${animal} jumped over the ${target}.";
 StrSubstitutor sub = new StrSubstitutor(valuesMap);
 String resolvedString = sub.replace(templateString);
 

yielding:

      The quick brown fox jumped over the lazy dog.

 

你可能感兴趣的:(遇到的问题)