Velocity是一種Java模版引擎技術(shù),該項目由Apache提出,功能強大。官方地址http://velocity.apache.org/
用了一段時間,有點心得,總結(jié)如下:
1.在vm中如果某值沒有設(shè)置,或者為空,可以在$后加!,例如$!{userName}還建議用{}把對象括起來,這樣比較標準一點、
2。循環(huán)中渲染vm
for循環(huán)
#if($!baskItemList&&$!baskItemList.size()>0)
#foreach($baskItem in $!baskItemList)
<li>$!baskItem.title </li>
#end
#end
HashMap循環(huán)
#if($!shopMap)
#foreach($shop in $shopMap.keySet() )
<li> Aa ${shopMap.get("$!{shop}").name} </li>
#end
#end
3 頁面賦值
#set($commentCount=1)
下面引用$!{commentCount}就可以了
4.Velocity計數(shù)器
#if($!baskItemList && $!baskItemList.size()>0)
#foreach($baskItem in $!baskItemList)
<li>$velocityCount</li>
#end
#end
注意velocityCount是從1開始的
posted on 2010-05-28 17:08
青菜貓(孫宇) 閱讀(462)
評論(0) 編輯 收藏 所屬分類:
java