springMVC4 怎样和velocity整合
展开全部
添加velocity.jar.
为spring mvc配置多视图, 并添加velocity的视图配置
设置velocity参数.
以下是部分整合配置代码:
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="favorParameter" value="false" />
<property name="ignoreAcceptHeader" value="true" />
<property name="defaultContentType" value="text/html" />
<property name="mediaTypes">
<map>
<entry key="html" value="text/html" /><!-- 真正静态页面,使用htm后缀(文件格式) -->
<entry key="json" value="application/json" />
<entry key="jsonp" value="application/javascript" />
<entry key="xml" value="application/xml" />
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<!-- 页面请求时先找此配置,无的话再找jsp的视图配置 -->
<bean
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true" />
<property name="suffix" value=".ftl" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="exposeRequestAttributes" value="true" />
<property name="exposeSessionAttributes" value="true" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="order" value="1" />
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/view/jsp/" />
<property name="suffix" value=".jsp" />
<property name="order" value="0" />
</bean>
</list>
</property>
<!-- view 接口 下的视图解析对象 -->
<property name="defaultViews">
<list>
<bean
class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
<bean class="com.base.view.jsonp.MappingJacksonJsonpView" />
<!-- <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" -->
</list>
</property>
</bean>
<!-- freemarker的配置 -->
<bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/view/freemarker/" />
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">0</prop>
<prop key="defaultEncoding">UTF-8</prop>
<prop key="number_format">0.##########</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="classic_compatible">true</prop>
<prop key="template_exception_handler">ignore</prop>
</props>
</property>
</bean>
<!-- velocity的配置 -->
<bean id="velocityConfigurer"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/view/velocity/" />
<property name="velocityProperties">
<props>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding">UTF-8</prop>
<prop key="contentType">text/html;charset=UTF-8</prop>
</props>
</property>
</bean>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询