Home > Java > javaTutorial > body text

Sharing tips on using velocity in Java

黄舟
Release: 2017-09-06 09:45:38
Original
1709 people have browsed it

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

使用velocity 技巧总结 - 继学 - 继学

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.

使用velocity 技巧总结 - 继学 - 继学

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template