首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Velocity用户手册学习札记

2012-10-28 
Velocity用户手册学习笔记Velocity的学习笔记原文地址http://velocity.apache.org/engine/releases/veloci

Velocity用户手册学习笔记
Velocity的学习笔记

原文地址
http://velocity.apache.org/engine/releases/velocity-1.6.4/user-guide.html

简要
References begin with $ and are used to get something.
Directives begin with # and are used to do something.

注释 单行 ## 多行 #* *# doc #** *#

引用
变量
属性
注意$customer.Address可以表示customer的getAddress方法,也可以表示customer map中的Address对应的value.
方法
As of Velocity 1.6, all array references are now "magically" treated as if they are fixed-length lists. This means that you can call java.util.List methods on array references.
可变参数当作数组。

属性查找顺序
小写的属性$customer.address
1.getaddress()
2.getAddress()
3.get("address")
4.isAddress()
大写的属性$customer.Address
1.getAddress()
2.getaddress()
3.get("Address")
4.isAddress()

Rendering
引擎把每一个引用都转变为String,可以调用toString方法转变。

Formal Reference Notation
Jack is a ${vice}maniac.
Now Velocity knows that $vice, not $vicemaniac, is the reference. Formal notation is often useful when references are directly adjacent to text in a template.

Quiet Reference Notation

当$email没有定义的时候输出$email.

当$email没有定义的时候输出"".

Strict References Setting
对未定义变量,或null变量调用方法抛异常。
但是if语句可以使用未定义变量。

Directives

#set



For the ArrayList example the elements defined with the [..] operator are accessible using the methods defined in the ArrayList class. So, for example, you could access the first element above using $monkey.Say.get(0).

Similarly, for the Map example, the elements defined within the { } operator are accessible using the methods defined in the Map class. So, for example, you could access the first element above using $monkey.Map.get("banana") to return a String 'good', or even $monkey.Map.banana to return the same value.

这个比较容易迷惑人。
If the RHS is a property or method reference that evaluates to null, it will not be assigned to the LHS.


Can I register Velocimacros via #parse() ?
Yes! This became possible in Velocity 1.6.

This is important to remember if you try to #parse() a template containing inline #macro() directives. Because the #parse() happens at runtime, and the parser decides if a VM-looking element in the template is a VM at parsetime, #parse()-ing a set of VM declarations won't work as expected. To get around this, simply use the velocimacro.library facility to have Velocity load your VMs at startup.
对于宏定义的查找是在parsetime,所以runtime的parse中如果有宏会有问题。

What is Velocimacro Autoreloading?
宏自动加载,用于开发环境。

字符串连接
放在一起就好。

热点排行