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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 综合教程 >内容正文

综合教程

velocity语法

發(fā)布時(shí)間:2023/11/24 综合教程 37 生活家
生活随笔 收集整理的這篇文章主要介紹了 velocity语法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.聲明變量 #set($var = XXX) 右邊可以是以下的內(nèi)容 Variable reference String literal Property reference Method reference Number literal #set ($i=1) ArrayList #set ($arr=["yt1","t2"]) 技持算術(shù)運(yùn)算符

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

3、變量 Variables 以 "$" 開頭,第一個(gè)字符必須為字母。character followed by a VTL Identifier. (a .. z or A .. Z). 變量可以包含的字符有以下內(nèi)容: 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 $與$!的區(qū)別 當(dāng)找不到username的時(shí)候,$username返回字符串"$username",而$!username返回空字符串""

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

8、條件語(yǔ)句 #if( $foo ) <strong>Velocity!</strong> #end #if($foo) #elseif() #else #end 當(dāng)$foo為null或?yàn)锽oolean對(duì)象的false值執(zhí)行.

9、邏輯運(yùn)算符:== && || !

10、循環(huán)語(yǔ)句#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、定義宏Velocimacros ,相當(dāng)于函數(shù) 支持包含功能 #macro( d ) <tr><td></td></tr> #end 調(diào)用 #d()

13、帶參數(shù)的宏 #macro( tablerows $color $somelist ) #foreach( $something in $somelist ) <tr><td bgcolor=$color>$something</td></tr> #end #end 調(diào)用 # tablerows (“red” “…”)

項(xiàng)目開發(fā)中需要注意到的要點(diǎn): 1. vm中顯示變量,一律加!和{},如:$!{userName}、$!{userVO.name}、$!{userVO.getName()}、$!{userMap.get(“Bob”)} 2. 合并字符串 如果變量是字符串或數(shù)值型,如 #set($user = “Tester”),則應(yīng)為 “welecom$!{user}”,而不是 “welcome” + $user 3. #if($var)條件判斷,當(dāng)且僅當(dāng):$var存在(如果$var是Boolean/boolean型,還必須$var的值為Boolean.true/true)時(shí),條件才成立 4. #foreach()循環(huán)的時(shí)候,有個(gè)系統(tǒng)變量$velocityCount可直接使用,不必自己設(shè)定額外的計(jì)數(shù)器 5. 比較字符串相等,#if($var == “test”)?? #if(“test”.equals($var))均可, 6. vm中生成URL #set($userName = “Bob”) “$offerModule.setTarget('modifySingleOffer.vm').addQueryData(‘userName’, $userName).fork()” “$offerModule.setTarget('modifySingleOffer.vm').addQueryData(‘userName’, ‘Bob’).fork()” 目標(biāo)大致如:http://127.0.0.1/offer/modifySingleOffer.htm?userName=Bob?7. vm中調(diào)用control $control.setTemplate("home:pageNavigator.vm").setParameter("position", "top").setParameter("pageList", $pageList) 8.其它可能會(huì)被使用到的,如定義自己的宏(定義和修改宏,需要重新啟動(dòng)應(yīng)用服務(wù)器才生效)

總結(jié)

以上是生活随笔為你收集整理的velocity语法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。