Java?????????freemarker????
???????????? ???????[ 2016/4/26 13:56:18 ] ??????????????????? ???????
???????java project??????freemarker.jar?? ???????????汾??freemarker-2.3.20 ?汾
????java?????????£?
????test.ftl???
name : ${name}
age : ${age}
test??
package com.freemarker;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class Test {
public static void main(String[] args) throws IOException?? TemplateException {
//1.???????????Cofiguration
Configuration cfg = new Configuration();
//2.????????????
//??1??src???μ?????template??src?£?
//cfg.setDirectoryForTemplateLoading(new File("src/template"));
//??2??????·????template??src?£?
//cfg.setDirectoryForTemplateLoading(new File(
// "D:/cpic-env/workspace/javaFreemarker/src/template"));
//cfg.setDirectoryForTemplateLoading(new File("src/template"));
//??3?????????μ?????template/main??????£?--???
cfg.setDirectoryForTemplateLoading(new File("template/main"));
//cfg.setObjectWrapper(new DefaultObjectWrapper());
//?????壨template??
Template template = cfg.getTemplate("test.ftl");
//????????????Map??
Map<String?? String> root = new HashMap<String?? String>();
root.put("name"?? "cxl");
root.put("age"?? "25");
//????????????????????????????????
Writer out = new OutputStreamWriter(System.out);
//StringWriter out = new StringWriter();
//System.out.println(out.toString());
//?????????????????+???=?????
template.process(root?? out);
out.flush();
}
}
???????н????
????name : cxl
????age : 25
??????

???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11