velocity 笔记

5 篇文章 0 订阅
1 篇文章 0 订阅

Single quotes will ensure that the quoted value will be assigned to the reference as is. Double quotes allow you to use velocity references and directives to interpolate, such as "Hello $name", where the $name will be replaced by the current value before that string literal is assigned to the left hand side of the =


#set( $a = "Velocity" )

单引号不解析 双引号解析

## This is a single line comment.

The Property $customer.Address has the exact same effect as using the Method $customer.getAddress()

<input type="text" name="email" value="$!email"/> !表示可为空 否则输出  $email

Now when the form is initially loaded and $email still has no value, an empty string will be output instead of "$email".

References to instance variables in a template are not resolved. Only references to the attribute equivalents of JavaBean getter/setter methods are resolved (i.e. $foo.Name does resolve to the class Foo's getName() instance method, but not to a public Name instance variable of Foo).

#[[don't parse me!]]#

<table>
#foreach( $customer in $customerList )
    <tr><td>$foreach.count </td><td>$customer.Name</td></tr>
#end
</table>

#foreach( $customer in $customerList )
    $customer.Name#if( $foreach.hasNext ),#end
#end

 $foreach.index    0开头
$foreach.first and $foreach.last

$foreach.parent or $foreach.topmost

#break

#include ----  The contents of the file are not rendered through the template engine.

The #parse script element allows the template designer to import a local file that contains VTL. Velocity will parse the VTL and render the template specified.

(e.g. #break($macro)). This will stop rendering of all scopes up to the specified one

#break($foreach.parent

The #stop directive stops any further rendering and execution of the template.
短路方式,render马上结束

The example below will display abc.

#set($source1 = "abc")
#set($select = "1")
#set($dynamicsource = "$source$select")
## $dynamicsource is now the string '$source1'
#evaluate($dynamicsource)


#define( $block )Hello $who#end
#set( $who = 'World!' )
$block
display Hello World!


Note that the range operator only produces the array when used in conjunction with #set and #foreach directives

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值