springMVC配置文件

<?xmlversion="1.0"encoding="UTF-8"?><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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--自动扫描含有@Controller的文件,base-package可用逗号隔开设置多个包--><context:component-scanbase-package="com.demo"><context:include-filtertype="annotation"expression="org.springframework.stereotype.Controller"/></context:component-scan><!--默认的注解映射的支持--><mvc:annotation-driven/><!--配置freeMarker视图解析器--><beanid="viewResolverFtl"class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"><propertyname="viewClass"value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/><propertyname="contentType"value="text/html;charset=UTF-8"/><propertyname="cache"value="true"/><propertyname="suffix"value=".ftl"/><!--将请求和会话属性作为变量暴露给FreeMarker模板使用。要做到这一点,可以设置exposeRequestAttributes或者exposeSessionAttributes为true--><propertyname="exposeRequestAttributes"value="true"/><propertyname="exposeSessionAttributes"value="true"/><!--使用这些宏,必须设置FreeMarkerViewResolver的exposeMacroHelpers属性为true--><propertyname="exposeSpringMacroHelpers"value="true"/><!--freemarker获取上下文${request.contextPath}--><propertyname="requestContextAttribute"value="request"/></bean><beanid="freemarkerConfiguration"class="org.springframework.beans.factory.config.PropertiesFactoryBean"><propertyname="location"value="classpath:freemarker.properties"/></bean><!--配置freeMarker的模板路径--><beanid="freemarkerConfig"class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"><propertyname="templateLoaderPath"value="/WEB-INF/ftl/"/><propertyname="freemarkerVariables"><map><entrykey="xml_escape"value-ref="fmXmlEscape"/></map></property><propertyname="defaultEncoding"value="UTF-8"/><propertyname="freemarkerSettings"><props><!--用来指定更新模版文件的间隔时间.0表示每次都重新加载,否则为多少毫秒检查是否更新--><propkey="template_update_delay">3600</prop><!--设置标签类型两种:[]和<>。[]这种标记解析要快些--><propkey="tag_syntax">auto_detect</prop><propkey="default_encoding">UTF-8</prop><propkey="output_encoding">UTF-8</prop><propkey="locale">zh_CN</prop><propkey="datetime_format">yyyy-MM-ddHH:mm:ss</prop><propkey="date_format">yyyy-MM-dd</prop><propkey="time_format">HH:mm:ss</prop><propkey="number_format">#.##</prop><!--可以满足一般需要。默认情况变量为null则替换为空字符串,如果需要自定义,写上${empty!"EmptyValueoffbysss"}的形式即可--><propkey="classic_compatible">true</prop><!--ignore,debug,html_debug,rethrow--><propkey="template_exception_handler">html_debug</prop></props></property></bean><beanid="fmXmlEscape"class="freemarker.template.utility.XmlEscape"/><!--拦截器:可分别针对不同的请求设置拦截器;也可设置近似全局拦截器.注:如果是rest风格静态资源也会被拦截--><mvc:interceptors><beanclass="com.demo.inteceptor.MyInteceptor"/></mvc:interceptors><!--对静态资源文件的访问方案一:使用默认的servlet来响应静态文件--><mvc:default-servlet-handler/><!--异常处理--><beanid="exceptionResolver"class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"><propertyname="defaultErrorView"><value>/error/error</value></property><propertyname="defaultStatusCode"><value>500</value></property><propertyname="warnLogCategory"><value>org.springframework.web.servlet.handler.SimpleMappingExceptionResolver</value></property></bean></beans>

属性配置文件

tag_syntax=auto_detecttemplate_update_delay=60default_encoding=UTF-8output_encoding=UTF-8locale=zh_CNdate_format=yyyy-MM-ddtime_format=HH:mm:ssdatetime_format=yyyy-MM-ddHH:mm:ssclassic_compatible=truetemplate_exception_handler=ignore


说明:需要导入freemarker.jar和spring-context-support.jar