package demo01;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class test01 {
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();
}
}
}
后台打印:
name:crd;URL:www.baidu.com;uname:baidu