Java study notes 5-Integration of Velocity with Spring MVC and usage instructions

Source: Internet
Author: User

Velocity is a java-based template engine that allows anyone to reference objects defined by java code simply using the template language. Configuration: 1. in pom. add the dependent velocity package in xml [html] <dependency> <groupId> velocity </groupId> <artifactId> velocity </artifactId> <version> 1.5 </version> </dependency> 2. add the following content to the servlet-context.xml If jsp configuration first comment out [html] <beans: bean id = "velocityConfig" <span style = "white-space: pre "> </span> class =" org. springframework. web. servlet. view. velocity. velocitycycler "> <beans: property name =" resourceLoaderPath "value ="/WEB-INF/vie Ws "/> <beans: property name =" configLocation "value =" classpath: common/velocity. properties "/> </beans: bean> <beans: bean id =" velocityViewResolver "class =" org. springframework. web. servlet. view. velocity. velocityViewResolver "> <beans: property name =" suffix "value = ". htm "/> </beans: bean> 3. create velocity in the resources/common directory. properties [html] # encoding input. encoding = UTF-8 output. encoding = UTF-8 contentType = tex T/html; charsets = UTF-8 # autoreload when vm changed file. resource. loader. cache = false file. resource. loader. modificationCheckInterval = 1 velocimacro. library. autoreload = false 4. create testController [java] @ RequestMapping (value = "/test") @ Controller public class TestController {@ RequestMapping (value = "/index") public String index (Model model) {String name = "tester"; model. addAttribute ("name", name); return" Test/index ";}}5. Create a test/index.htm template

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.