赞
踩
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
import org.apache.commons.lang.text.StrSubstitutor;
import java.util.HashMap;
import java.util.Map;
public class test {
public static void main(String[] args) {
Map<String, Object> map = new HashMap<>();
map.put("name", "旺旺");
map.put("gender", "未知");
String s = "双重否定的${name}, 性别是${gender}";
System.out.println(replaceAll(map, s));
}
// 替换所有占位符
public static String replaceAll(Map<String, Object> map, String replaceValue){
StrSubstitutor strSubstitutor = new StrSubstitutor(map);
return strSubstitutor.replace(replaceValue);
}
}
运行结果
双重否定的旺旺, 性别是未知
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。