One, variable
1. Variable definition
#Set($name = "velocity")
2. Use of variables
Use $name or ${name} in the template file to work with the defined variables. It is recommended to use the format ${name}, because in the template it is possible to define two variables similar to $name and $names, and if you do not use braces, the engine will not be able to correctly identify the variable $names.
For a variable of a complex object type, such as $person, you can use ${person.name} to access the person's Name property. It is worth noting that the ${person.name} here does not directly access the person's Name property, but instead accesses the person's GetName () method, so ${person.name} and ${person.getname ()} are the same.
3. Assigning values to variables
In the first small point, a variable is defined, and the variable is assigned a value. For Velocity, a variable is a weak data type, and it can be assigned a number or array after assigning a String to the variable. You can assign the following six data types to a Velocity variable: A variable reference, a literal string, a property reference, a method reference, a literal number, an array list.
#Set ($foo = $bar) #Set ($foo ="Hello") #set($foo. Name = $bar. Name) # Set($foo. Name = $bar. GetName ($arg)) #set123) #set($ foo = ["foo", $bar])
Second, the circulation
#foreach in are $element $velocityCount #end
The loop of the object
#foreach($Meisaiinch$KbnMeisaiList)#if($! {meisai.kbnid}==$! {Kbn.kbnid}) <input type="checkbox"Name="$! {Meisai.kbnid}"Id="$! {MEISAI.KBNCD}"Value="$! {Meisai.kbncdname}" #if(!${null.isnull ($kbnSelectList)} && ${kbnselectlist.size ()}!=0) #foreach($tempinch$kbnSelectList)#if($! {Temp.kbnid} = = $! {Kbn.kbnid} && $! {TEMP.KBNCD} = = $! {MEISAI.KBNCD}) checked= "checked" #end#end #end/>$!{meisai.kbncdname} #end #end
Third, conditional statements
The syntax for a conditional statement is as follows
#if (condition) ... #elseif (condition) ... #else ... #end
Iv. Relational operators
The Velocity engine provides the and, or, and not operators, respectively, for the &&, | | | And! For example:
#if ($foo && $bar) #end
Five, macro
A macro in Velocity can be understood as a function definition. The syntax for the definition is as follows:
#macro (macroName arg1 arg2 ...) ... #end
Vi. #parse and #include
The function of #parse and #include directives is to reference the file externally, and the difference is that #parse will refer to the content as similar to the source file, the content will be introduced in the place to parse, #include is to introduce the file as a resource file, The incoming content will be output intact as text. See the following examples:
FOO.VM file:
#Set($name = "velocity")
PARSE.VM:
#parse ("FOO.VM")
The output is: velocity
INCLUDE.VM:
#include ("FOO.VM")
The output is: #set ($name = "velocity")
The above includes some of the velocity's syntax, with detailed syntax for reference to Velocity's official documentation.
Velocity Template Engine Introduction