1 准备
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
2 实践
这个占位符可以包括unicode字符,也可以包括特殊字符,空格等等
public static void fillPlaceholder() {
String template = "Welcome ${中午インターフェ:!:!+-*/ }! Your last login was ${lastlogin}";
Map<String, String> data = new HashMap<String, String>();
data.put("中午インターフェ:!:!+-*/ ", "You");
data.put("lastlogin", new Date().toString());
String output = StrSubstitutor.replace(template, data);
System.out.println(output);
}
输出:
Welcome You! Your last login was Thu Mar 01 16:35:25 CST 2018