﻿<?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-kxbin-文章分类-FreeMarker</title><link>http://www.blogjava.net/kxbin/category/50378.html</link><description>创出一片天地</description><language>zh-cn</language><lastBuildDate>Fri, 16 Dec 2011 05:10:48 GMT</lastBuildDate><pubDate>Fri, 16 Dec 2011 05:10:48 GMT</pubDate><ttl>60</ttl><item><title>FreeMarker的数据模型</title><link>http://www.blogjava.net/kxbin/articles/366503.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Fri, 16 Dec 2011 03:04:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/366503.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/366503.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/366503.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/366503.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/366503.html</trackback:ping><description><![CDATA[<div><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">基础</li></ul><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">在快速入门中介绍了在模板中使用的三种基本对象类型：scalars、hashes 和sequences，其实还可以有其它更多的能力：</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><strong>scalars</strong>：存储单值</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><strong>hashes</strong>：充当其它对象的容器，每个都关联一个唯一的查询名字</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><strong>sequences</strong>：充当其它对象的容器，按次序访问</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">方法：通过传递的参数进行计算，以新对象返回结果</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">用户自定义FTL标记：宏和变换器</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">通常每个变量只具有上述的一种能力，但一个变量可以具有多个上述能力，如下面的例子：</p><pre style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: #2f6fab; border-right-color: #2f6fab; border-bottom-color: #2f6fab; border-left-color: #2f6fab; background-color: #ffffff; line-height: 1.1em; font-size: 14px; ">(root)  |  +- mouse = "Yerri"      |      +- age = 12      |      +- color = "brown"&gt; </pre><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">mouse既是scalars又是hashes，将上面的数据模型合并到下面的模板：</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">${mouse} &lt;#-- use mouse as scalar --&gt; ${mouse.age}&lt;#-- use mouse as hash --&gt; ${mouse.color} &lt;#-- use mouse as hash --&gt;</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">输出结果是：</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">Yerri</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">12</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">brown</p><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">Scalar变量</li></ul><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">Scalar变量存储单值，可以是：</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">字符串：简单文本，在模板中使用引号（单引号或双引号）括起</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">数字：在模板中直接使用数字值</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">日期：存储日期/时间相关的数据，可以是日期、时间或日期-时间（Timestamp）；通常情况，日期值由程序员加到数据模型中，设计者只需要显示它们</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">布尔值：true或false，通常在&lt;#if &#8230;&gt;标记中使用</p><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">hashes 、sequences和集合</li></ul><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">有些变量不包含任何可显示的内容，而是作为容器包含其它变量，者有两种类型：</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">hashes：具有一个唯一的查询名字和它包含的每个变量相关联</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">sequences：使用数字和它包含的每个变量相关联，索引值从0开始</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">集合变量通常类似sequences，除非无法访问它的大小和不能使用索引来获得它的子变量；集合可以看作只能由&lt;#list &#8230;&gt;指令使用的受限sequences</p><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">方法</li></ul><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">方法变量通常是基于给出的参数计算值。</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">下面的例子假设程序员已经将方法变量avg放到数据模型中，用来计算数字平均值：</p><pre style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: #2f6fab; border-right-color: #2f6fab; border-bottom-color: #2f6fab; border-left-color: #2f6fab; background-color: #ffffff; line-height: 1.1em; font-size: 14px; ">The average of 3 and 5 is: ${avg(3, 5)}  The average of 6 and 10 and 20 is: ${avg(6, 10, 20)}  The average of the price of python and elephant is:         ${avg(animals.python.price, animals.elephant.price)} </pre><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">宏和变换器</li></ul><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">宏和变换器变量是用户自定义指令（自定义FTL标记），会在后面讲述这些高级特性</p><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">节点</li></ul><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">节点变量表示为树型结构中的一个节点，通常在XML处理中使用</p></div><img src ="http://www.blogjava.net/kxbin/aggbug/366503.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2011-12-16 11:04 <a href="http://www.blogjava.net/kxbin/articles/366503.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FreeMarker基本语法</title><link>http://www.blogjava.net/kxbin/articles/366502.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Fri, 16 Dec 2011 03:02:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/366502.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/366502.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/366502.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/366502.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/366502.html</trackback:ping><description><![CDATA[<div></div><div><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;# ... &gt; 中存放所有freemaker的内容，之外的内容全部原样输出。</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;@ ... /&gt; 是函数调用</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">两个定界符内的内容中，第一个符号表示指令或者函数名，其后的跟随参数。freemaker提供的控制包括如下：</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;#if condition&gt;&lt;#elseif condition&gt;&lt;#else&gt; 条件判断</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;#list hash_or_seq as var&gt; 遍历hash表或者collection（freemaker称作sequence）的成员</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;#macro name param1 param2 ... &gt;&lt;#nested param&gt; 宏，无返回参数</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;#function name param1 param2&gt;&lt;#return val&gt;函数，有返回参数</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">var?member_function(...) 用函数对var进行转换，freemaker称为build-ins。实际内部实现类似member_function(var, ...)</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">stringA[M .. N] 取子字符串，类似substring(stringA, M, N)</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">{key:value, key2:value2 ...} 直接定义一个hash表</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">[item0, item1, item2 ...] 直接定义一个序列</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">hash0[key0] 存取hash表中key对应的元素</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">seq0[5] 存取序列指定下标的元素</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;@function1 param0 param1 ... /&gt; 调用函数function1</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;@macro0 param0 param1&nbsp;; nest_param0 nest_param1 ...&gt; nest_body &lt;/@macro&gt; 调用宏，并处理宏的嵌套</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;#assign var = value &gt; 定义变量并初始化</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;#local var = value&gt; 在 macro 或者 function 中定义局部变量并初始化</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;#global var = value &gt; 定义全局变量并初始化</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">${var} 输出并替换为表达式的值</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;#visit xmlnode&gt; 调用macro匹配xmlnode本身及其子节点</li></ul><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">&lt;#recurse xmlnode&gt; 调用macro匹配xmlnode的子节点</li></ul></div><img src ="http://www.blogjava.net/kxbin/aggbug/366502.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2011-12-16 11:02 <a href="http://www.blogjava.net/kxbin/articles/366502.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FreeMarker介绍</title><link>http://www.blogjava.net/kxbin/articles/366500.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Fri, 16 Dec 2011 03:00:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/366500.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/366500.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/366500.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/366500.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/366500.html</trackback:ping><description><![CDATA[<div><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">FreeMarker是一个<a href="http://www.zzbaike.com/wiki/%E6%A8%A1%E7%89%88" title="模版" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">模版</a>引擎，一个基于文本的模板输出工具（生成任意的<a href="http://www.zzbaike.com/wiki/HTML" title="HTML" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">HTML</a>表单代码）。它是一个<a href="http://www.zzbaike.com/wiki/Java" title="Java" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Java</a>包，面向Java程序员的类库。它本身并不是针对最终用户的应用，而是允许程序员将其嵌入到他们的产品中。</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">FreeMarker被设计用来生成HTML Web页面，特别是基于<a href="http://www.zzbaike.com/wiki/MVC" title="MVC" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">MVC</a>模式的应用程序。使用 MVC 模式作为动态的<a href="http://www.zzbaike.com/wiki/WEB" title="WEB" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">WEB</a>页面的想法，是为了分隔页面设计者 (HTML 设计者) 和程序员。.每个人做自己擅长的那一部分。设计者可以不通过程序员的改变或修改代码来改变网页的样子，因为应用逻辑(Java程序)和页面设计（FreeMarker 模版）是分开的。模板不会被复杂繁琐的程序框架所破坏。即使当一个项目的程序员和HIMTL页面的制作者是同一个人时，这种分隔也是很有用，因为这样有助于保持应用的清晰并易于维护。</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">尽管FreeMarker有一些编程的能力，但它并不是一个象<a href="http://www.zzbaike.com/wiki/PHP" title="PHP" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">PHP</a>那样的成熟的编程语言。与Java不同的是，Java程序准备用来显示的数据，而Freemarker仅是生成文本页，这个文本页显示用于模板的预备数据。</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><a href="http://www.zzbaike.com/wiki/Image:Freemaker1.png" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><img alt="Freemaker1.png" src="http://www.zzbaike.com/wiki/images/a/a2/Freemaker1.png" width="416" height="191" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; vertical-align: middle; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /></a></p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">FreeMarker 不是一个<a href="http://www.zzbaike.com/wiki/Web" title="Web" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Web</a>&nbsp;应用框架，而更适合充当 Web 应用框架里的一个组件的角色，但 FreeMarker 引擎本身对 HTTP 或 servlets 并不关心，它仅仅是生成文本。在非 Web 应用环境中它同样能够展示完美的用途。然而值得注意的是：我们为使用 FreeMarker 提供了方便的解决方案，作为 Model2 框架（如 Struts ）的视图组件，你也可以在模版中使用<a href="http://www.zzbaike.com/wiki/JSP" title="JSP" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">JSP</a>标签。</p><h2><span id=".E6.BA.90.E7.A0.81.E6.A6.82.E8.A6.81">源码概要</span></h2><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">授权协议：&nbsp;<a href="http://www.zzbaike.com/wiki/BSD" title="BSD" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">BSD</a></p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">开发语言：&nbsp;<a href="http://www.zzbaike.com/wiki/Java" title="Java" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Java</a></p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">操作系统： 跨平台</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 20px; font-family: sans-serif; font-size: 14px; background-color: #ffffff; ">软件用途:模板引擎</p><h2><span id="FreeMarker.E7.89.B9.E7.82.B9">FreeMarker特点</span></h2><ul style="line-height: 20px; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(http://www.zzbaike.com/wiki/skins/monobook/bullet.gif); font-family: sans-serif; font-size: 14px; background-color: #ffffff; "><li style="margin-bottom: 0.1em; ">能够生成各种文本：<a href="http://www.zzbaike.com/wiki/HTML" title="HTML" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">HTML</a>、XML、RTF、Java源代码等等</li><li style="margin-bottom: 0.1em; ">易于嵌入到你的产品中：轻量级；不需要Servlet环境</li><li style="margin-bottom: 0.1em; ">插件式模板载入器：可以从任何源载入模板，如本地文件、数据库等等</li><li style="margin-bottom: 0.1em; ">你可以按你所需生成文本：保存到本地文件；作为Email发送；从<a href="http://www.zzbaike.com/wiki/Web" title="Web" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Web</a>应用程序发送它返回给Web<a href="http://www.zzbaike.com/wiki/%E6%B5%8F%E8%A7%88%E5%99%A8" title="浏览器" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">浏览器</a></li><li style="margin-bottom: 0.1em; ">强大的模板语言</li><li style="margin-bottom: 0.1em; ">通用数据模型</li><li style="margin-bottom: 0.1em; ">智能的国际化和本地化</li><li style="margin-bottom: 0.1em; ">强大的<a href="http://www.zzbaike.com/wiki/XML" title="XML" style="text-decoration: none; color: #002bb8; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">XML</a>处理能力</li></ul></div><img src ="http://www.blogjava.net/kxbin/aggbug/366500.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2011-12-16 11:00 <a href="http://www.blogjava.net/kxbin/articles/366500.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>