[Introduction to Velocity of Apache]

What is Velocity?

Velocity is a Java-based template engine. It permits anyone to use a simple yet powerful template language to reference objects defined in Java code.

 

When Velocity is used for web development, Web designers can work in parallel with Java programmers to develop web sites according to the Model-View-Controller (MVC) model, meaning that web page designers can focus solely on creating a site that looks good, and programmers can focus solely on writing top-notch code. Velocity separates Java code from the web pages, making the web site more maintainable over its lifespan and providing a viable alternative to Java Server Pages (JSPs) or PHP.

 

Velocity's capabilities reach well beyond the realm of the web; for example, it can be used to generate SQL, PostScript and XML from templates. It can be used either as a standalone utility for generating source code and reports, or as an integrated component of other systems. For instance, Velocity provides template services for various web frameworks, enabling them with a view engine facilitating development of web applications according to a true MVC model.

 

The Apache Velocity Project

Velocity is a project of the Apache Software Foundation, charged with the creation and maintenance of open-source software related to the Apache Velocity Engine. All software created at the Velocity project is available under the Apache Software License and free of charge for the public.

 

 

Velocity is a java-based template engine (template engine). It allows anyone to refer to objects defined by java code using only a simple template language.

 

Velocity's capabilities go far beyond web site development, for example, it can generate SQL and PostScript, XML from templates, it can also be used as a standalone tool to generate source code and reports, or as an integrated component of other systems use. Velocity can also provide a template service for the Turbine web development framework. The way Velocity+Turbine provides a template service allows a web application to be developed in a true MVC model.

 

Basic steps to use Velocity

1 initialize an engine

2 create a context and put data into it

3 choose a template and merge it

 

Velocity is not only used in the MVC architecture, but can also be used in the following scenarios.

1. Web application: Developers can use Velocity to make HTML have the characteristics of dynamic content without using JSP.

2. Source code generation: Velocity can be used to generate Java code, SQL or PostScript. There are many open source and commercially developed software developed using Velocity.

3. Automatic Email: Many software's user registration, password reminder or reports are automatically generated by Velocity. Instead of concatenating strings in Java code, use Velocity to generate email content in a text file.

4. Convert xml: Velocity provides an ant task called Anakia that can read XML files and make them readable by Velocity templates. A common application is converting xdoc documents into styled HTML files.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326313500&siteId=291194637