References
VTL has three types of reference: variables, attributes, and methods. As a designer, the Java engineer must be consistent with the name (identifier) referenced by the VTL reference to use them in the template. The reference is handled as a String object.
(1) variable
Variable format: $ VTL identifier
The VTL identifier consists of letters, numbers, transverse lines (-) or underscores (_). Variables or Values (as described above), or Java code (same name variable) from the SET instructions in the template. Velocity only processes the defined variable reference, and Velocity returns to the unfined variable reference. For example, the following example:
#set ($ foo = "gibbous")
$ moon = $ foo
The output is: $ moon = Gibbous
(2) attribute
Property Format: $ VTL Identifier. VTL Identifier
Below is an example of attribute reference:
$ Customer.Address
$ purchase.total
Take the first example, there are two interests:
l Return to the value of the HashTable object Customer key value is Address
l $ Customer.GetDress () Method Reference Abbreviation (Getter Method for Javabean Properties)
As for which case, Velocity will make decisions and return the appropriate value.
(3) method
Method's format: $ VTL identifier (parameter list)
Here is an example of method reference:
$ Customer.Getaddress ()
$ purchase.gettotal ()
$ Page.Settitle ("My Home Page")
$ Person.SetaTRibutes (["Strange", "Weird", "Excited"])
Two examples of the previous examples can abbreviate the property reference (such as an example of attribute reference). Properties references and method references are the main differences for methods to specify a list of parameters.
(4) Formal reference symbol: {}
The official reference symbols are distinguished in the use of variables. Look at the example below:
#set ($ vice = "klepto")
Jack is a $ ViceManiac.
The output is: Jack IS A $ ViceManiac. ($ ViceManiac is not defined, the output is output)
#set ($ vice = "klepto")
Jack is a $ {vice} maniac.
The output result is: Jack Is A Kleptomaniac. (Separate $ VICE and other text) using official reference symbols)
(5) Quit reference symbol:!
Look at the example below:
At the beginning, $ email doesn't have a value, so the value of $ Email will be displayed in the text box, but more hope is blank. Here is an example of using a quit reference symbol:
Velocity will replace $ EMAIL with an email when $ email is no value.
(6) Special character escape
For special characters such as $, # to be displayed normally, you can use / perform escape, // escape. Below is an example:
#set ($ email = "foo")
The output result is:
foo
/ foo