日期:2014-05-16  浏览次数:20355 次

springmvc和jsp,velocity,freemarker等的整合
springmvc和jsp,velocity,freemarker等的整合


可以任意切换,使用jsp,velocity,freemarker的任意一个,也可以选择三个同时使用

使用springmvc controller在spring-servlet.xml里面这样配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!-- - Application context definition for "springserver" DispatcherServlet. -->
<beans default-autowire="byName">
<!-- resourceBundle view begin 三个一起使用-->
<!--
   <bean id="velocityConfig"
   class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
   <property name="resourceLoaderPath" value="/template/velocity/" />
   </bean>
 
   <bean id="freemarkerConfig"
   class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
   <property name="templateLoaderPath"
   value="/template/freemarker/" />
   </bean>
 
   <bean id="viewResolver"
   class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
   <property name="basename">
   <value>views</value>
   </property>
   </bean>
-->

<!-- resourceBundle view end -->
<!-- jsp view begin 使用JSP -->
<bean id="jspViewResolver"
   class="org.springframework.web.servlet.view.InternalResourceViewResolver">
   <property name="viewClass">
    <value>org.springframework.web.servlet.view.JstlView</value>
   </property>
   <property name="prefix" value="/template/jsp/" />
   <property name="suffix" value=".jsp" />
</bean>

<!-- jsp view end -->

<!-- velocity view begin 使用VELOCITY-->
<!--
   <bean id="velocityConfig"
   class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
   <property name="resourceLoaderPath" value="/template/velocity/" />
   </bean>
 
   <bean id="velocityViewResolver"
   class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
   <property name="cache" value="false" />
   <property name="suffix" value=".vm" />
   <property name="exposeSpringMacroHelpers" value="true" />
   </bean>
-->

<!-- velocity view end -->

<!-- freemarker view begin 使用FREEMARKER-->
<!--
   <bean id="freemarkerConfig"
   class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
   <property name="templateLoaderPath"
   value="/template/freemarker/" />
   </bean>
   <bean id="freemarkerViewResolver"
   class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
   <property name="cache" value="false" />
   <property name="suffix" value=".ftl" />
   <property name="exposeSpringMacroHelpers" value="true" />
   </bean>
-->
<!-- freemarker view end -->

<bean id="multipartResolver"
   class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
   <property name="maxUploadSize" value="2000000" />
</bean>

<bean id="methodNameResolver"
   class="org