velocity中的表达式

mac2022-06-30  65

1:注释

   单行:##

   多行:#* *#

2:设置(给新的变量$a赋值)

    #set($a='velocity')

3.单引号和双引号

    #set ($var="helo")     test"$var" 返回testhello     test'$var' 返回test'$var'

4、条件语句 #if( $foo ) <strong>Velocity!</strong> #end #if($foo) #elseif() #else #end 当$foo为null或为Boolean对象的false值执行.

5.逻辑运算符:==       &&          ||      !

6.循环语句#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

7.$"用来标识一个对象(或理解为变量);如 如:$i、$msg、$TagUtil.options(...)等。

8、"{}"用来明确标识Velocity变量; 比如在页面中,页面中有一个$someonename,此时,Velocity将把someonename作为变量名,若我们程序是想在someone这 个变量的后面紧接着显示name字符,则上面的标签应该改成${someone}name。

9."!"用来强制把不存在的变量显示为空白。 如当页面中包含$msg,如果msg对象有值,将显示msg的值,如果不存在msg对象同,则在页面中将显示$msg字符。这是我们不希望的,为了把不存 在的变量或变量值为null的对象显示为空白,则只需要在变量名前加一个“!”号即可。 如:$!msg

10.时间类型器数据转化

后台绑定:beat.getModel().add("date", new DateTool());

前台展示:$date.format('yyyy-MM-dd HH:mm:ss',$!{element.regTime})

转载于:https://www.cnblogs.com/xiaoQ0725/p/8360919.html

相关资源:数据结构—成绩单生成器
最新回复(0)