Take a look at the following code:
-
- # Foreach ($ ID in [1 .. 50])
-
- # Set ($User = $ user. Get ($ id ))
-
- $ ID: $ {user. name}
-
- # End
-
-
In the above Code, assume that only one user with the ID of 1 exists, but it will show that 50 IDs are the users with the ID of 1 and their names, because in velocity, if the result returned by a value assignment statement is null, the value of the assigned object is not changed, that is, the $ user variable remains the previous valid value.
The solution provided in the official document is to change the above Code:
-
# foreach ($ ID in [1 .. 50])
- # Set ($ User = false)
- # Set ($ User = $ user. Get ($ id)
- $ id :$ {user. name}
- # End
other methods (recommended):
the problem was finally met by me. The fundamental solution should be:
solution: Modify velocity. properties
original configuration: Directive. set. null. allowed = false
modified configuration: Directive. set. null. allowed = true
after the modification is complete, use # If ($ diary) to determine whether the object is empty ~~~
see: http://www.itsmile.net/blog/article_show/20/273559/Velocity-Set-Null-value-method-Foreach