﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Natlive's blog-随笔分类-Freemarker</title><link>http://www.blogjava.net/natlive/category/24881.html</link><description>A long way and dream.</description><language>zh-cn</language><lastBuildDate>Mon, 13 Aug 2007 18:36:26 GMT</lastBuildDate><pubDate>Mon, 13 Aug 2007 18:36:26 GMT</pubDate><ttl>60</ttl><item><title>自翻译·Freemarker 文档（一）</title><link>http://www.blogjava.net/natlive/archive/2007/08/13/136286.html</link><dc:creator>狂龙</dc:creator><author>狂龙</author><pubDate>Mon, 13 Aug 2007 01:51:00 GMT</pubDate><guid>http://www.blogjava.net/natlive/archive/2007/08/13/136286.html</guid><wfw:comment>http://www.blogjava.net/natlive/comments/136286.html</wfw:comment><comments>http://www.blogjava.net/natlive/archive/2007/08/13/136286.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/natlive/comments/commentRss/136286.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/natlive/services/trackbacks/136286.html</trackback:ping><description><![CDATA[<p style="FONT-FAMILY: Courier">自己的英语水平只有一级半，为了努力学好英语，现在一天一个翻译，先从Freemarker文档开始，有不对的地方多谢指正抛砖。<br><br>Create a configuration instance<br>建立一个配置实例</p>
<p style="FONT-FAMILY: Courier">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.<br>首先你必须建立一个freemarker.template.Configuration类的实例并调整它的设置. 一个Configuration类实例是保存Freemarker应用程序设置的中心首要. 同样, 它决定着预编译模版的建立和缓冲.</p>
<p>Probably you will do it only once at the beginning of the application(possibly servlet) life-cycle:<br>也许你只需要在程序开始时,仅仅只需调用一次下面的代码,并且在程序的整个生命周期都可用:<br><br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">Configuration&nbsp;cfg&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Configuration();<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Specify&nbsp;the&nbsp;data&nbsp;source&nbsp;where&nbsp;the&nbsp;template&nbsp;files&nbsp;come&nbsp;from.<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;指定模板的数据源<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Here&nbsp;I&nbsp;set&nbsp;a&nbsp;file&nbsp;directory&nbsp;for&nbsp;it:<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;在这里我设置为一个目录</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">cfg.setDirectoryForTemplateLoading(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Fil(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">/where/you/store/templates</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Specify&nbsp;how&nbsp;templates&nbsp;will&nbsp;see&nbsp;the&nbsp;data&nbsp;model.&nbsp;This&nbsp;is&nbsp;an&nbsp;advanced&nbsp;topic<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;指定模板怎么读取数据模型(data&nbsp;model).&nbsp;这是一个需要专门讨论的话题<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;but&nbsp;just&nbsp;use&nbsp;this:<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;不过现在你可以这样做</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">cfg.setObjectWrapper(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;DefaultObjectWrapper());&nbsp;&nbsp;<br></span></div>
<p><span style="FONT-FAMILY: Courier">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.<br>现在开始,你就可以使用这个Configuration实例了. 如果一个系统有多个模块使用Freemarker的话, 毫无意外的, 它们最后使用它们各自私有的Configuration实例.</span> </p>
<img src ="http://www.blogjava.net/natlive/aggbug/136286.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/natlive/" target="_blank">狂龙</a> 2007-08-13 09:51 <a href="http://www.blogjava.net/natlive/archive/2007/08/13/136286.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>