自己的英語(yǔ)水平只有一級(jí)半,為了努力學(xué)好英語(yǔ),現(xiàn)在一天一個(gè)翻譯,先從Freemarker文檔開始,有不對(duì)的地方多謝指正拋磚。
Create a configuration instance
建立一個(gè)配置實(shí)例
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.
首先你必須建立一個(gè)freemarker.template.Configuration類的實(shí)例并調(diào)整它的設(shè)置. 一個(gè)Configuration類實(shí)例是保存Freemarker應(yīng)用程序設(shè)置的中心首要. 同樣, 它決定著預(yù)編譯模版的建立和緩沖.
Probably you will do it only once at the beginning of the application(possibly servlet) life-cycle:
也許你只需要在程序開始時(shí),僅僅只需調(diào)用一次下面的代碼,并且在程序的整個(gè)生命周期都可用:
Configuration cfg = new Configuration();
// Specify the data source where the template files come from.
// 指定模板的數(shù)據(jù)源
// Here I set a file directory for it:
// 在這里我設(shè)置為一個(gè)目錄
cfg.setDirectoryForTemplateLoading(new Fil("/where/you/store/templates"));
// Specify how templates will see the data model. This is an advanced topic
// 指定模板怎么讀取數(shù)據(jù)模型(data model). 這是一個(gè)需要專門討論的話題
// but just use this:
// 不過(guò)現(xiàn)在你可以這樣做
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.
現(xiàn)在開始,你就可以使用這個(gè)Configuration實(shí)例了. 如果一個(gè)系統(tǒng)有多個(gè)模塊使用Freemarker的話, 毫無(wú)意外的, 它們最后使用它們各自私有的Configuration實(shí)例.