test.java
...
public void test() throws Exception {
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(new File("" + "./src"));
cfg.setObjectWrapper(new DefaultObjectWrapper());
Map<String, Object> root = new HashMap<String, Object>();
root.put("user", "Koma");
Map<String, String> latest = new HashMap<String, String>();
root.put("latestProduct", latest);
latest.put("url", "1.htm");
latest.put("name", "product name");
Template temp = cfg.getTemplate("test.ftl");
Writer out = new OutputStreamWriter(System.out);
temp.process(root, out);
out.flush();
}
test.ftl
hello ${user}.
${latestProduct.url}
${latestProduct.name}
出力結果:
hello Koma.
1.htm
product name
0 件のコメント:
コメントを投稿