Due to the company's needs, I used the velocity template for file generation. Here are some tips when using velocity templates:
1. Intercept string
Note that (1) you need to use .length( ) Get the string length;
(2) It is best to use the form of "+(-1)" instead of "-1", because the support for the minus sign "-" in velocity is not friendly and easy to confuse.
2.$velocityCount (loop traversal counter)
After encountering character traversal, we need to perform operations between strings (such as adding a comma or other identical symbols), But for the last character, we don't need to add it. At this time, we need to use $velocityCount to operate.
The above picture shows that after traversing the strings, "," is used between the strings to separate the output, and the last one is not added with ",".
Note that $velocityCount will automatically increase by 1 each time it loops, where fields.size() is the length of the collection.
The above is the detailed content of Sharing tips on using velocity in Java. For more information, please follow other related articles on the PHP Chinese website!