In the previous article we covered the content of the velocity template engine, and below we describe how to use velocity in spring mvc.
--------------------------------------------------------------------------------------------------------------- -----------------------------------------------
Velocity is a Java template engine.
Similar to Jsp,freemarker, it is used to display Web content.
Unlike JSPs, Velocity can show only the data in the action and cannot process the data. You cannot write Java code, but you can use velocity notation.
Velocity's page (template) is a file of any type (text/html).
When velocity is applied to web development, velocity separates Java code from Web pages, and interface designers can synchronize with Java program developers to develop a Web site that follows the MVC architecture.
That is, the page designer can focus on the display of the page, while the Java program developer focuses on the business logic code.
The following is a brief description of the steps to configure velocity in spring MVC:
1. The package required for the introduction of velocity
2. Adding configuration information
3. Testing
Detailed steps:
1. Introducing Velocity Package: Velocity-1.7.jar, Velocity-tools-2.0.jar, Spring-context-support-4.2.5.release.jar (ignoring version number)
Pom file configuration, the following jar package can be introduced
[HTML] View plain copy print? <!--velocity start--> <dependency> <groupid >org.apache.velocity</groupId> <artifactid>velocity</ artifactid> <version>1.6</version> </ dependency> <dependency> <groupId> org.apache.velocity</groupid> <artifactid>velocity-tools</ artifactid> <version>2.0</version> </ dependency> <dependency> <groupId> org.springframework</groupid> <artifactId> spring-context-support</artifactid> <version>4.2.5.release</ version> </dependency> <!--velocity end-->
2, add configuration information in the configuration file
The velocityconfigurer is responsible for setting the velocity engine in spring. Here, through the property resourceloaderpath tell velocity where to look for its template. It is recommended that you place the template under a subdirectory under Web-inf to ensure that the templates are not directly accessible.
There are two ways to configure properties when you configure them:
(1) by configuration file mode
[HTML] view plain copy print? <!--profile information--<bean id= "Velocityconfigurer" class= " Org.springframework.web.servlet.view.velocity.VelocityConfigurer "> <