1.Velocity is a Java-based template engine. You can reference a Java object.
is the ability to adjust and populate page layouts and page content based on business logic, using Java objects.
I personally think that the template is to provide a shell, in what position to put what kind of data, how to put the data in order to achieve what kind of display effect.
So, the template is very similar, you just need to understand its rules of use.
2. Basic syntax:
1) "#" script statements to identify velocity, including #set, #if, #else, #end, #foreach, #end, #iinclude, #parse, #macro等;
2) "$" is used to identify an object (or to be interpreted as a variable); The first character must be a letter. can contain-_a-z0-9; can take the value of the object, the method of referencing the object;
3) "{}" is used to clearly identify the velocity variable;
4) "!" Used to force the non-existent variable to appear blank. $! return NULL character ~
I often confused is not understand $!msg and! $msg difference.
5) distinguish between single and double quotation marks:
#set ($var = "Helo")
Test "$var" returns Testhello
Test ' $var ' returns test ' $var '
You can change the default processing by setting Stringliterals.interpolate=false
3. Write an example:
# #我是注释
#* Me
Also
Comment *#
#set ($i =0)
#foreach ($info in $list)
Sequence Number: $i
#set ($i = $i + 1)
#end
I've written the same. More complex than this, it is to distinguish between the last element and other elements, plus other functions. Note here is the possible problem with "whitespace". No time bomb!
4. Have fun!
Individuals used to play smarty templates, do not like Java, there is no understanding of Java. The most recent background environment is VMS, so understand.
In fact, almost ~ ~
Personally, if it is not a traversal of the grammatical structure, it is suggested that some simple logical processing or in JS processing better. This facilitates the separation of the page and business logic, so that people maintain the code is not so painful!
Vm-velocity template-related ~