Spring MVC Integration Velocity

Source: Internet
Author: User

Spring MVC consolidates the velocity to introduce the packages that need to be imported, such as

Pom Introduction:

<dependency>

<groupId>org.apache.velocity</groupId>

<artifactId>velocity</artifactId>

<version>1.6.2</version>

</dependency>

<dependency>

<groupId>org.apache.velocity</groupId>

<artifactId>velocity-tools</artifactId>

<version>2.0</version>

</dependency>

<dependency>

Then, is a very simple configuration, then, here, modify the next spring-mvc.xml content, the content is modified as follows

<?XML version= "1.0" encoding= "UTF-8"?><!--See below the beans this element tag does not have to have the label declaration -<Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd        Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd ">    <!--Scan all classes in a Web package to complete bean creation and automatic dependency injection -    <Context:component-scanBase-package= "qust.thb.*" />    <!--support for spring3.0 new MVC annotations -    <Mvc:annotation-driven/>     <!--start the Spring MVC Annotation feature to complete the mapping of requests and annotations Pojo -    <Beanclass= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>    <!--Viewresolver -    <!--<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "  Viewclass "value=" Org.springframework.web.servlet.view.JstlView "/> <property name=" prefix "value="/web-inf/" /> <property name= "suffix" value= ". jsp"/> </bean> -         <BeanID= "Velocityconfig"class= "Org.springframework.web.servlet.view.velocity.VelocityConfigurer">          < Propertyname= "Resourceloaderpath"value= "/web-inf/"/>          < Propertyname= "Configlocation"value= "/web-inf/velocity.properties"/>    </Bean>     <BeanID= "Viewresolver"class= "Org.springframework.web.servlet.view.velocity.VelocityViewResolver">          < Propertyname= "Cache"value= "true"/>        < Propertyname= "prefix"value=""/>        < Propertyname= "suffix"value= ". VM"/>    </Bean></Beans>

Then create the Velocity.properties file under the Web-inf folder, the content is very simple, two words

Input.encoding=utf-8
Output.encoding=utf-8

Then, the View folder under the hello.jsp Delete, create a new file, called HELLO.VM, the content is very simple, as follows

< Div >     ${message}</div>

The overall directory structure is as shown

Enter address http://localhost:8080/SpringMVC/user/getUser.do, Access normal access

With velocity, it's definitely going to be decorated with Sitemesh, which allows us to create consistent page layouts and appearances in projects that are heavily page-engineered, such as consistent navigation bars, consistent banner, consistent copyrights, and so on.

Spring MVC Integration Velocity

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.