Velocity语法简介

变量定义

#set( $a = "Velocity" )

各种注释

## This is a single line comment.

#*
 Thus begins a multi-line comment. Online visitors won't
 see this text because the Velocity Templating Engine will
 ignore it.
*#

#**
This is a VTL comment block and
may be used to store such information
as the document author and versioning
information:
@author
@version 5
*#

属性

$customer.Address

如果customer是一个Map则等于customer.get("Address") 或者相当于customer.getAddress();

当作方法来调用

$person.setAttributes( ["Strange", "Weird", "Excited"] )

属性查找规则

$customer.address, the sequence is
getaddress()
getAddress()
get("address")
isAddress()

索引

$foo[0]       ## $foo takes in an Integer look up
$foo[$i]      ## Using another reference as the index
$foo["bar"]   ## Passing a string where $foo may be a Map

相当于foo.get(Integer)

正式表示

Jack is a $vice maniac.
Jack is a ${vice}maniac.

空输出

$!email

严格模式

setting the velocity configuration property 'runtime.references.strict' to true

那么会抛出异常。

简写

$data.getRequest().getServerName()
## is the same as
$data.Request.ServerName
## is the same as
${data.Request.ServerName}

if语句

#if( $XHTML )
  #set( $br = "<br />" )
#else
  #set( $br = "<br>" )
#end

for语句

#foreach( $mud in $mudsOnSpecial )
   #if ( $customer.hasPurchased($mud) )
      <tr>
        <td>
          $flogger.getPromo( $mud )
        </td>
      </tr>
   #end
#end



#foreach( $foo in [1..5] )
$foo
#end

逃跑

#[[
#foreach ($woogie in $boogie)
  nothing will happen to $woogie
#end
]]#


\$email

包含

#include( "one.gif","two.txt","three.htm" )

 #macro( callme $a )
         $a $a $a
     #end
     #callme( $foo.bar() )

转载于:https://my.oschina.net/chunquedong/blog/190116

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值