(1) freemarker入门实例
生活随笔
收集整理的這篇文章主要介紹了
(1) freemarker入门实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉載地址: ?http://swiftlet.net/archives/905
首先在項目中建立存放模板的文件夾templates,然后放入模板文件person.ftl,內容如下:
Hello, my name is ${name}. I come from ${address}. Nice to meet you!
public class Test {public static void main(String[] args) throws IOException, TemplateException{Version version = new Version(2, 3, 1);Configuration cfg = new Configuration(version);cfg.setDirectoryForTemplateLoading(new File("templates"));cfg.setObjectWrapper(new DefaultObjectWrapper(version));Template temp = cfg.getTemplate("person.ftl");Map root = new HashMap();root.put("name", "張三");root.put("address", "中國-北京");Writer out = new OutputStreamWriter(System.out);temp.process(root, out);out.flush();} } 輸出結果為:
Hello, my name is 張三. I come from 中國-北京. Nice to meet you!
總結
以上是生活随笔為你收集整理的(1) freemarker入门实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 枚举用法
- 下一篇: (2) freemarker入门案例2