velocity
velocity
v velocity简介
v velocity的使用方法
v 参考文献
velocity简介
Velocity是ASF下的一个优秀模板引擎
velocity的使用
v 取变量
$ 如$customer 二级的$customer.Name
多级类推
v 循环
#foreach( $mud in $mudsOnSpecial )
#end
$mud临时声明的变量 $mudsOnSpecial 集合
Velocity使用
v 对象的方法调用
$customer.hasPurchased($mud)
v 页面设置变量
#set( $a = "Velocity" )
v 注释
## 单行注释
#* *#多行注释
Velocity的使用
v 变量名称
alphabetic (a .. z, A .. Z)
numeric (0 .. 9)
hyphen ("-")
underscore ("_")
例如
$foo $mudSlinger
$mud-slinger $mud_slinger
$mudSlinger1
Velocity的使用
$customer.address
这个取属性 如果点后是小写的,他查找的是这么干
getaddress()
getAddress()
get("address")
isAddress()
Velocity的使用
属性查找
$customer.Address
getAddress()
getaddress()
get("Address")
isAddress()
Velocity的使用
索引方法
$foo[0] ## $foo takes in an Integer look up
$foo[$i] ## Using another reference as the index
$foo["bar"] ## Passing a string where $foo may be a Map
点号取值
$foo.bar[1].junk
$foo.callMethod()[1]
$foo["apple"][4]
Velocity的使用
索引赋值
#set($foo[0] = 1)
#set($foo.bar[1] = 3)
#set($map["apple"] = "orange")
{}的用法
${mudSlinger}
${customer.Address}
${purchase.getTotal()}
$!{email} 如果为空不显示
Velocity的使用
v $bar.bogus ## $bar does not provide property bogus, Exception
v $bar.foo.bogus ## $bar.foo does not provide property bogus, Exception
v $bar.retnull.bogus ## cannot call a property on null, Exception
Velocity的使用
If / ElseIf / Else 用法
#if( $foo < 10 )
<strong>Go North</strong>
#elseif( $foo == 10 ) <strong>Go East</strong>
#elseif( $bar == 6 ) <strong>Go South</strong>
#else <strong>Go West</strong>
#end
Velocity的使用
逻辑符
&& || !
包含
#include( "one.txt" )
#include( "one.gif","two.txt","three.htm" )
#include( “greetings.txt", $seasonalstock )
#parse( "me.vm" )
parse 只能放一个参数
#break 跳出
Velocity使用
v 宏定义
#macro( d ) <tr><td></td></tr> #end
v 宏调用
#d()
Velocity的使用
参考文献
http://velocity.apache.org/engine/releases/velocity-1.7/user-guide.html
Velocity