单引号和双引号的小区别

VTL语句以#开头,并包含指令(set)。变量以$开头,用引号引起。引号可以是单引号,也可以是双引号。 前者引用具体的String值;后者可以包含Velocity 引用,例如”hello, $name”, $name会用其当前的值替换。上面的例子是将值Velocity 赋值给变量a。


当使用#set 指令时,括在双引号中的字面字符串将解析和重新解释,如下所示:

#set( $directoryRoot = "www" )

#set( $templateName = "index.vm" )

#set( $template = "$directoryRoot/$templateName" )

$template

 输出将会是:

www/index.vm

然而,当字面字符串括在单引号中时,他将不被解析:

#set( $foo = "bar" )

$foo

#set( $blargh = '$foo' )

$blargh

 输出是:

Bar

$foo

你可能感兴趣的:(velocity)