Saturday, December 29, 2012

Velocity笔记

## or    #* ... *#
<input type="text" name="email" value="$!email"/>
\$email escape
$data.getRequest().getServerName()  ## is the same as  $data.Request.ServerName
Directives always begin with a #
#set( $primate = "monkey" )
#set( $monkey.Say = ["Not", $my, "fault"] ) ## ArrayList
#set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"}) ## Map
you could access the first element above using $monkey.Say.get(0).   $monkey.Map.get("bannana") to return a String 'good'
#literal()      #end
<table>
#foreach( $customer in $customerList )
   <tr><td>$velocityCount</td><td>$customer.Name</td></tr>
#end
</table>
#foreach( $foo in [1..5] )
$foo
#end

As a programmer, the classes you should use to interact with the Velocity internals are the org.apache.velocity.app.Velocity
class if using the singleton model, or org.apache.velocity.app.VelocityEngine if using the non-singleton model ('separate instance').





check $ and #,

No comments:

Post a Comment