freemarker使用map替換字符串中的值

package demo01;java

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;url

import freemarker.template.Template;
import freemarker.template.TemplateException;it

public class test01 {io

public static void main(String[] args) {
try {
Template tmp = new Template(null, new StringReader("name:${user};URL:${url};uname:${name}"), null);
Map<String,String> map = new HashMap<String,String>();
map.put("user", "crd");
map.put("url", "www.baidu.com");
map.put("name", "baidu");
tmp.process(map, new OutputStreamWriter(System.out));
} catch (IOException e) {
e.printStackTrace();
}catch (TemplateException e) {
e.printStackTrace();
}
}class

}test

後臺打印:import

name:crd;URL:www.baidu.com;uname:baidu後臺

相關文章
相關標籤/搜索