JAVA velocity grammar explanations

velocity syntax rules:

1. Get:

! $ (Var): if the value is output, if it is empty, is not displayed;

$ {Var}: if the value is output, if it is empty, then the code is output as it is;

2. Set:

#set {$ var = 5}: set var is 5;

3. Judgment:

#if {! $ var} var is empty is determined

#elseif {$ var} is not empty is determined var

#else{}
#end

4 cycles:

Cycling an array or List:

#foreach($var in list)

## times the output current iteration

$velocityCount

$ {Was}

#end

5 determines whether null

1) Use #ifnull () or #ifnotnull () 
   #ifnull ($ foo) 
   To use this feature must be added in velocity.properties file: 
userdirective = org.apache.velocity.tools.generic.directive.Ifnull 
userdirective = ORG. apache.velocity.tools.generic.directive.Ifnotnull 
2) is determined using the tool null 
   #if ($ null.isNull ($ foo)  )

6. # define () d custom scripts

7. # inclede #parse local files are used to introduce the
difference:

#parse only the introduction of a single document, # include multiple files can be introduced, with a separated
file #parse will be introduced parsing engine, # include file parsing engine will not be introduced
between the files and the parent file #parse introduced variables are shared

Published 316 original articles · won praise 33 · views 210 000 +

Guess you like

Origin blog.csdn.net/yz18931904/article/details/103860067