springmvc freemarker jsp多视图配置

spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">


<!--基于validate的加载配置-->
   <mvc:annotation-driven validator="validator"/>

<bean id= "validator" class= "org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
            <property name= "providerClass"  value= "org.hibernate.validator.HibernateValidator"/>
            <!-- 如果不加 默认使用classpath下的 ValidationMessages.properties -->
            <property name= "validationMessageSource" ref= "messageSource"/>
    </bean>
    
<context:component-scan base-package="com.icwant.client.controller">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>

<!-- 启用AspectJ对Annotation的支持          -->
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <bean id="inputFilterAspect" class="com.icwant.client.aop.InputFilterAspect"></bean>
    
<!-- jsp视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<property name="order" value="1" />
</bean>


<!-- 引入freemarker配置文件 -->
  <context:property-placeholder location="classpath:config/freemarker.properties"
ignore-unresolvable="true" />

<!-- 配置freeMarker视图解析器 -->
<bean id="viewResolverFtl"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
<property name="contentType" value="text/html; charset=utf-8" />
<property name="cache" value="true" />
<property name="suffix" value=".ftl" />
<!-- 解析器的优先级别。我们将FreeMarkerViewResolver的级别设为0,将InternalResourceViewResolver的级别设为1。 -->
<!-- 这样,解析器就会优先使用 FreeMarkerViewResolver 进行解析,如果找不到相应的模板,就使用InternalResourceViewResolver进行解析 -->
<property name="order" value="0" />
<property name="requestContextAttribute" value="request"/>
</bean>




<!-- 配置freeMarker的模板路径 -->
<bean id="freemarkerConfig"
class="com.icwant.client.freemarker.ShiroTagFreeMarkerConfigurer">
<property name="templateLoaderPath" value="${baseDir}" />
<property name="freemarkerVariables">
<map>
<entry key="xml_escape" value-ref="fmXmlEscape" />
</map>
</property>
<property name="defaultEncoding" value="${default_encoding}" />
<property name="freemarkerSettings">
<props>
<!-- 模版缓存和模版问卷同步频率 0表示不读取缓存,每次都读取模版文件 -->
<prop key="tagSyntax">${tag_syntax}</prop>
<prop key="template_update_delay" >${template_update_delay}</prop>
<prop key="auto_import">${auto_import}</prop>
<prop key="auto_include">${auto_include}</prop>
<prop key="outputEncoding">${output_encoding}</prop>
<prop key="numberFormat">${number_format}</prop>
<prop key="classicCompatible">${classic_compatible}</prop>
</props>
</property>
</bean>


<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" />


<!--文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="1000000000" />
</bean>


<!-- 异常处理类 -->
<bean id="exceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="defaultErrorView">
<value>error</value>
</property>
<property name="exceptionMappings">
<props>
<prop key="java.sql.SQLException">error</prop>
<prop key="java.lang.RuntimeException">error</prop>
</props>
</property>

</bean>

<mvc:resources mapping="/resources/**" location="/resources/" />

</beans>


freemarker.properties:

#ftl模版所在根路径
baseDir=/WEB-INF/ftl/
#设置标签类型:square_bracket:[]     auto_detect:[]<>    
tag_syntax=auto_detect    
#模版缓存时间,单位:秒   
template_update_delay=0
default_encoding=UTF-8
output_encoding=UTF-8
locale=zh_CN
#设置数字格式,防止出现000.00 
number_format=\#    
#变量为空时,不会报错 
classic_compatible=true   
#这个表示每个freemarker的视图页面都会自动引入这个ftl文件。里面定议的就是一些宏,如text文本框,各种form元素   
auto_import="/base/spring.ftl" as sp
auto_include="/base/constant.ftl"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值