- 5
- 0
- 约6.54千字
- 约 3页
- 2017-06-11 发布于北京
- 举报
Velocity 学习笔记:
Velocity 符号规则: $得到 #设置
注释:
单行注释: ## This is a single line comment. 多行注释: #* This is a single line comment *#
关系运算符: == , , 逻辑运算:: ,|| ,!
数据类型: 货币:$2.5 , 数字 123 , 布尔 true/false 字符串: “Velocity”
数学运算符: #set ( $foo = $bar + 3 ) #set ( $foo = $bar - 4 ) #set ( $foo = $bar * 6 )
#set ( $foo = $bar / 2 ) #set ( $foo = $bar % 5 )
关于数字区间的使用:
#foreach ( $foo in [1..5] ) $foo #end
#foreach ( $bar in [2..-2] ) $bar #end
#set ( $arr = [0..1] ) #foreach ( $i in $arr ) $i #end
注意:[m..n]只在#set和#foreach中有效。
创建变量:
变量的表现形式: $a
创建一个变量:#set($a=wangsiyu)
注:只可以给变量赋值 字符串
为变量赋值字符串: #set( $foo = “gibbous” )
为变量赋值布尔型: #set( $result = false )
变量与变量赋值:$moon = $foo
变量在HTML中的使用:
body
#set ( $foo = “Velocity” )
Hello $foo World!
/body
输出结果: Hello Velocity World!
逃逸符(\\) 的使用:××××××××××××××××××有问题
$email 结果: foo
\\$email 结果: $email
\\\\$email 结果: \\foo
\\\\\\$email 结果: \\\\$email
如果变量没有被定义 并且 使用逃逸符 则 原样输出
条件语句(#if #end):
#if ( $foo )
strongVelocity!/strong
#end
条件语句扩展:
#if( $foo 10 )
strong Go North /strong
#elseif( $foo == 6 )
strong Go South /strong
#else
strong Go West /strong
#end
循环(#foreach #end):
#foreach ( $product in $allProducts )
li $product /li
#end
注:$allProducts 的类型: Vector、Hashtable或者Array
foreach控制循环次数:
#foreach ( $customer in $customerList )
trtd$velocityCount/tdtd$customer.Name/td/tr
#end
例:
table
#foreach( $mud in $nudsOnSpecial )
#if ( $customer.hasPurchased($mud ) )
trtd$flogger.getPromo( $mud )/td/tr
#end
#end
/table
Velocity三种类型: 变量, 属性 , 方法
变量:
数据类型 变量; 数据类型 变量1, 变量2, ..., 变量n; 数据类型 变量 = 数据值;int x; int x = 9; boolean terminate = false;
属性:
$customer.Address
$purchase.Total
$customer.Address
方法:
$customer.getAddress()
$purchase.getTotal()
$page.setTitle( “My Home Page” )
$person.setAttributes( [“Strange”, “Weird”, “Excited”] )
正式格式表示:
变量:${mudSlinger}
属性:${customer.Address}
方法:${purchase.getTotal()}
正是格式与非正是格式的区别:
Jack is a $vicemaniac.
本来变量是$vice现在却变成了$vicemaniac,这样Veloctiy就不知道
原创力文档

文档评论(0)