自翻譯·Freemarker 文檔(一)
自己的英語水平只有一級半,為了努力學好英語,現在一天一個翻譯,先從Freemarker文檔開始,有不對的地方多謝指正拋磚。
Create a configuration instance
建立一個配置實例
First you have to create a freemarker.template.Configuration instance and adjust its settings. A Configuration instance is a central place to store the appliction level setting of FreeMarker. Also, it deals with the creation and caching of pre-parsed templates.
首先你必須建立一個freemarker.template.Configuration類的實例并調整它的設置. 一個Configuration類實例是保存Freemarker應用程序設置的中心首要. 同樣, 它決定著預編譯模版的建立和緩沖.
Probably you will do it only once at the beginning of the application(possibly servlet) life-cycle:
也許你只需要在程序開始時,僅僅只需調用一次下面的代碼,并且在程序的整個生命周期都可用:
// Specify the data source where the template files come from.
// 指定模板的數據源
// Here I set a file directory for it:
// 在這里我設置為一個目錄
cfg.setDirectoryForTemplateLoading(new Fil("/where/you/store/templates"));
// Specify how templates will see the data model. This is an advanced topic
// 指定模板怎么讀取數據模型(data model). 這是一個需要專門討論的話題
// but just use this:
// 不過現在你可以這樣做
cfg.setObjectWrapper(new DefaultObjectWrapper());
From now you should use this single configuration instance. Note however that if a system has multiple independent components that use FreeMarker, then of course they will use their own private Configuration instance.
現在開始,你就可以使用這個Configuration實例了. 如果一個系統有多個模塊使用Freemarker的話, 毫無意外的, 它們最后使用它們各自私有的Configuration實例.
posted on 2007-08-13 09:51 狂龍 閱讀(1003) 評論(1) 編輯 收藏 所屬分類: Freemarker