Velocity User Guide (Chinese Version) (1)

zhaozj2021-02-16  91

What is Velocity?

Velocity is a Java-based template engine. It allows the web page developer to reference the method defined in the Java code. Web designers can develop a WEB site that follows the MVC mode with the Java program developer parallel. This means that the web designer can focus on a good Web site, while Java program developers can put their energy on writing code. Velocity Separates the Java code from the web page to make the Web site longer-maintainable and provide an alternative JSP or PHP solution.

VTL (Velocity Template Language)

VTL provides a simple, easy and quiet way to merge dynamic content into the web page. VTL uses references to insert dynamic content into the web page. Variables are a reference that can point to define content in the Java code, or a VTL statement in the web page. Below is an example of a VTL statement that can be inserted into the HTML document:

#set ($ a = "velocity")

The VTL statement begins with # and contains instructions (SET). The variable is started with a quotation mark. The quotation marks can be single or double quotes. The former references the specific string value; the latter can include Velocity references, such as "Hello, $ Name", $ NAME will replace it with its current value. The above example is to assign value Velocity to the variable a.

When the variable is assigned, you can reference anywhere in the HTML document, the following is an example of Hello Velocity World!

#set ($ foo = "velocity")

Hello $ foo world!

Comment

VTL supports a single-line annotation (starting in ##) and multi-line comments (including between # * and * #), the following is an example:

This text is visible. ## THIS TEXT IS NOT Visible.

This text is visible.

This text is visible. # * This text, as part of a multi-line comment,

Is Not Visible. This Text Is Not Visible; It is Also Part of The

Multi-line Comment. this text still not visible. * # this text is outside

The comment, so it is visible.

## THIS TEXT IS Not Visible.

转载请注明原文地址:https://www.9cbs.com/read-12973.html

New Post(0)