日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[转]Velocity脚本摘要

發布時間:2023/12/15 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [转]Velocity脚本摘要 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
官網:http://velocity.apache.org/

1、聲明:#set ($var=XXX)
左邊可以是以下的內容
Variable reference
String literal
Property reference
Method reference
Number literal #set ($i=1)
ArrayList #set ($arr=["yt1","t2"])
技持算術運算符

2、注釋:
單行## XXX
多行#* xxx
xxxx
xxxxxxxxxxxx*#

References 引用的類型
3、變量 Variables
以 "$" 開頭,第一個字符必須為字母。character followed by a VTL Identifier. (a .. z
or A .. Z).
變量可以包含的字符有以下內容:
alphabetic (a .. z, A .. Z)
numeric (0 .. 9)
hyphen ("-")
underscore ("_")

4、Properties
$Identifier.Identifier
$user.name
hashtable user中的的name值.類似:user.get("name")

5、Methods
object user.getName() = $user.getName()

6、Formal Reference Notation
用{}把變量名跟字符串分開


#set ($user="csy"}
${user}name
返回csyname

$username
$!username
$與$!的區別
當找不到username的時候,$username返回字符串"$username",而$!username返回空字符串""

7、雙引號 與 引號
#set ($var="helo")
test"$var" 返回testhello
test'$var' 返回test'$var'
可以通過設置 stringliterals.interpolate=false改變默認處理方式

8、條件語句
#if( $foo )
<strong>Velocity!</strong>
#end
#if($foo)
#elseif()
#else
#end
當$foo為null或為Boolean對象的false值執行.

9、邏輯運算符:== && || !

10、循環語句#foreach($var in $arrays ) // 集合包含下面三種Vector, a Hashtable or an Array
#end
#foreach( $product in $allProducts )
<li>$product</li>
#end

#foreach( $key in $allProducts.keySet() )
<li>Key: $key -> Value: $allProducts.get($key)</li>
#end

#foreach( $customer in $customerList )
<tr><td>$velocityCount</td><td>$customer.Name</td></tr>
#end
11、velocityCount變量在配置文件中定義
# Default name of the loop counter
# variable reference.
directive.foreach.counter.name = velocityCount
# Default starting value of the loop
# counter variable reference.
directive.foreach.counter.initial.value = 1

12、包含文件
#include( "one.gif","two.txt","three.htm" )

13、Parse導入腳本
#parse("me.vm" )

14、#stop 停止執行并返回

15、定義宏Velocimacros ,相當于函數 支持包含功能
#macro( d )
<tr><td></td></tr>
#end
調用
#d()

16、帶參數的宏
#macro( tablerows $color $somelist )
#foreach( $something in $somelist )
<tr><td bgcolor=$color>$something</td></tr>
#end
#end

17、Range Operator
#foreach( $foo in [1..5] )

總結

以上是生活随笔為你收集整理的[转]Velocity脚本摘要的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。