14. VTL 格式化问题

虽然在本指南中的VTL经常显示在新行中或者有空格,但是下面的VTL

  1. #set( $imperial = ["Munetaka","Koreyasu","Hisakira","Morikune"] )
  2. #foreach( $shogun in $imperial )
  3. $shogun
  4. #end

和下面的写法同样有效。

  1. Send me #set($foo = ["$10 and ","a cake"])#foreach($a in $foo)$a #end please.

Velocity的行为并不受空格的影响,前述的指令也可以写成:

  1. Send me
  2. #set( $foo = ["$10 and ","a cake"] )
  3. #foreach( $a in $foo )
  4. $a
  5. #end
  6. please.

或者

  1. Send me
  2. #set($foo = ["$10 and ","a cake"])
  3. #foreach ($a in $foo )$a
  4. #end please.

上面每种写法结果都一样。