velocity 在netiler經常使用指令及應用javascript
<div>css Hello Worldhtml </div>前端 |
賦值#set($word="hello") java 取值 $word 推薦寫成${word}web 取值的另外一種寫法 $!word spring $word和 $!word區別是當變量word爲null時,$word會在前端顯示字符串"$word",而$!word不顯示任何東西框架 |
#foreach($stu in $stulist)ide $i,$stu.name,$stu.sex,$stu.agespa #end $stulist爲後臺傳來的Student對象集合 #foreach() 結合 #if() #break()用法示例 #foreach($item in $list) $item #if($item=="1") #break() #end #end |
#include('path') 加載其餘.vm文件,文件加載支持相對路徑的模式。 |
#px() |
#script('student') 引入/web/resource/script/student.js #javascript() <script> alert('abc'); 等同於 alert('abc'); #end </script> #style('student') 將加載web/resource/theme/style.css文件,若是文件不存在,頁面將不載入。 #p_w_picpath('student') 將加載web/resource/p_w_picpath/p_w_picpath.jpg文件,等同於HTML<img/>標籤。 |
#path('') 的值爲project.xml的namespace的值並以/開頭,/結尾 輸出/demo/ #path('index.nsp') 值爲/demo/index.nsp |
#title('hello velocity') 頁面源代碼 |
#date('2013-04-01') 輸出2013-04-01 格式化 #date('2013-04-01','yyyy年M月d日') 輸出2013年4月1日 |
#bean('com.leadal.demo.service.DemoService',$bean) ,將加載Spring中的com.leadal.demo.service.DemoService對象,並賦值變量$bean。提供下面程序訪問。 |
#btn(‘student’) 使用#btn()時框架默認引入px支持 添加/web/resource/btn/student.btn中全部按鈕 #btn(‘student’,[‘add’,’edit’,’delete’]) 添加/web/resource/btn/student.btn中add,edit,delete三個按鈕 |