0
我尝试使用替代像org.apache.commons.lang3.text.StrSubstitutor这
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("price", "40");
valuesMap.put("product", "Shirt");
String templateString = "I paid total ${{price}} for the product {{product}}.";
StrSubstitutor sub = new StrSubstitutor(valuesMap, "{{", "}}");
String resolvedString = sub.replace(templateString);
System.out.println(resolvedString);
琴弦然后我得到以下输出
我付产品衬衫的总价{{价格}}。
,而不是
我付的总$ 40的产品衬衫。
我相信$符号必须与在StrSubstitutor中处理正则表达式的方式冲突。
我错过了什么?如果没有,那么我怎样才能得到预期的解决方案?