1. Load the velocity expansion package to the project first via Pom.xml:
1 <Dependency>2 <groupId>Velocity</groupId>3 <Artifactid>Velocity</Artifactid>4 <version>1.5</version>5 </Dependency>
2. Then add the following configuration in the XML that automatically loads the bean:
1 <BeanID= "Velocityconfig"2 class= "Org.springframework.web.servlet.view.velocity.VelocityConfigurer">3 < Propertyname= "Resourceloaderpath"value= "/web-inf/views/" />4 < Propertyname= "Velocitypropertiesmap">5 <Props>6 <propKey= "Input.encoding">Utf-8</prop>7 <propKey= "Output.encoding">Utf-8</prop>8 </Props>9 </ Property>Ten </Bean> One <BeanID= "Viewresolver" A class= "Org.springframework.web.servlet.view.velocity.VelocityViewResolver"> - < Propertyname= "Cache"value= "true" /> - < Propertyname= "Exposespringmacrohelpers"value= "true" /> the < Propertyname= "suffix"value= ". VM" /> - < Propertyname= "ContentType"value= "Text/html;charset=utf-8" /> - </Bean>
With the above configuration, spring Engineering supports the Velocity template engine, where the template file is located under the:/web-inf/views/directory, specifying the input and output encoding for UTF-8 encoding, and specifying the template suffix name for the. VM end.
Spring Integrated Velocity template engine