Velocity语法参考
1.1.Velocity語法參考
1.1.1.表達式
2? 訪問JavaBeans
$someBean或${someBean}
2? 讀Properties
$bean.name或${bean.name}??? ## 訪問bean.getName()方法或是$bean.get(“name”)方法
2? 寫Properties
#set ($bean.name = “value”)
或#set (${bean.name} = “value”)??? ## 訪問bean.setName(“value”)方法
2? 調用方法
$uri.setTarget(“target.vm”)
1.1.2.注釋
2? 行注釋
## line comments
2? 塊注釋
#* block
??? comments
?*#
2? 文檔注釋
#** document
????? comments
?*#
1.1.3.循環
2? 循環語句:
#foreach ($item in $collection)
??? ($velocityCount) item is $item
#end
2? 其中velocityCount是一特殊循環變量,用來指出循環的次數(1-based)
1.1.4.條件判斷
2? 條件判斷
#if ($order.total == 0)
??? No charge
#else
??? $order.total
#end
1.1.5.賦值
2? 賦值
#set ($customer = $order.customer)
2? 四則運算
#set ($sum = $num1 + $num2)
#set ($sub = $num1 - $num2)
#set ($mul = $num1 * $num2)
#set ($div = $num1 / $num2)
#set ($mod = $num1 % $num2)
1.1.6.調試
2? 暫停執行
#if ($debug) #stop #end
2? 調試表達式
$user? ## 顯示user.toString()
$user.class? ## 顯示user.getClass()
$user.name ## 顯示user.getName().toString()
$user.name.class? ## 顯示user.getName().getClass()
1.1.7.宏
2? 定義宏
#macro ( errorMessage $field )
??? #if ( !$field.valid )
??????? <div class="formError">* $field.message</div>
??? #end
#end
2? 使用宏
?<td>#errorMessage ( $group.lastName )</td>
1.1.8.判斷空
2? 判斷:$bean不為null或Boolean.TRUE
#if ($bean) … #end
2? 判斷字符串空:””或null
#if ($stringUtil.isEmpty($str)) … #end
2? 判斷字符串非空:非””和null
#if ($stringUtil.isNotEmpty($str)) … #end
轉載于:https://www.cnblogs.com/shipengzhi/articles/2050152.html
總結
以上是生活随笔為你收集整理的Velocity语法参考的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python-Learn
- 下一篇: 背景色透明,里面内容(图片、文字)不透明