What is Apache Velocity?
Apache Velocity is a Java-based template engine that provides a template language to reference objects defined in Java code. Here is a conversation or quarrel between Velocity (Apache) developers and Spring ones revolving around the reason why Velocity is not supported on the Spring framework.
Velocity is a Java-based templating engine.
It’s an open source web framework designed to be used as a view component in the MVC architecture, and it provides an alternative to some existing technologies such as JSP.
Velocity can be used to generate XML files, SQL, PostScript and most other text-based formats.The core class of Velocity is the VelocityEngine.
It orchestrates the whole process of reading, parsing and generating content using data model and velocity template.
Here are the steps we need to follow for any typical velocity application:
- Initialize the velocity engine
- Read the template
- Put the data model in context object
- Merge the template with context data and render the view
Velocity Template Language (VTL) provides the simplest and cleanest way of incorporating the dynamic content in a web page by using VTL references.
VTL reference in velocity template starts with a $ and is used for getting the value associated with that reference.
VTL provides also a set of directives which can be used for manipulating the output of the Java code. Those directives start with #.
Example
#set ($message = "Query Home")
#set ($customer.name = "Sandeep Bedi")
Video for Apache Velocity
https://www.youtube.com/watch?v=DnWe-QJHEzQ