springMVC + velocity 的结合

来源:互联网 发布:淘宝店铺美工主管职责 编辑:程序博客网 时间:2024/05/01 05:04

1:应用jar包

<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>

2:spring视图配置

     <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath" value="/html" />
        <property name="velocityProperties">
        <props>
        <prop key="input.encoding">UTF-8</prop>
        <prop key="output.encoding">UTF-8</prop>
        </props>
        </property>
    </bean>
    <!-- 配置视图的显示 -->
    <bean id="ViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
    <property name="cache" value="true" />
        <property name="prefix" value="/" />
        <property name="suffix" value=".html" />
        <property name="toolboxConfigLocation" value="/WEB-INF/velocity-tools.xml" />
        <property name="contentType" value="text/html;charset=UTF-8" />
        <property name="layoutUrl" value="layout/default.html"/>
<property name="order" value="0" />
    </bean>

3:velocity-tools.xml

<?xml version="1.0" encoding="UTF-8"?>
<toolbox>
<tool>
<key>dateTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DateTool</class>
</tool>
<tool>
<key>escapeTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
</toolbox>

4:layout/default.html

$screen_content

0 0
原创粉丝点击