<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=utf-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<bean id="freemakerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
<property name="viewNames">
<array>
<value>*.html</value>
</array>
</property>
<property name="contentType" value="text/html;charset=utf-8"/>
<property name="cache" value="false"/>
</bean>
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/html/"/>
<property name="freemarkerVariables">
<map>
<entry key="xml_escape" value-ref="fmXmlEscape"/>
</map>
</property>
</bean>
<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
<mvc:resources mapping="/statics/**" location="/statics/"/>
<context:component-scan base-package="cn.t11.controller"/>
</beans>
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- <mvc:default-servlet-handler/>-->
<!--注解驱动-->
<mvc:annotation-driven conversion-service="conversionService">
<mvc:message-converters>
<!--StringHttpMessageConverter默认为ISO-8859-1-->
<!--自己配置防止输出乱码-->
<!-- public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");-->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=utf-8</value>
</list>
</property>
</bean>
<!--不用fastjson了,用jackson,spring默认帮你配置好-->
<!--
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=utf-8</value>
</list>
</property>
<property name="fastJsonConfig">
<bean class="com.alibaba.fastjson.support.config.FastJsonConfig">
<property name="dateFormat" value="yyyy-MM-dd hh:mm:ss"/>
<property name="serializerFeatures">
<array>
<value>WriteMapNullValue</value>
</array>
</property>
</bean>
</property>
</bean>
-->
</mvc:message-converters>
</mvc:annotation-driven>
<!--自定义日期转换格式-->
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="cn.smbms.controller.StringToDateConverter">
<constructor-arg value="yyyy-MM-dd"/>
</bean>
</set>
</property>
</bean>
<!--内容协商管理(多视图解析器配置-->
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<!--是否支持通过扩展名指定格式
/test1.json
/test1.xml
/test1.html
-->
<property name="favorPathExtension" value="true"/>
<!--是否支持通过参数指定格式(参数名默认为format)
/test1?format=json
/test1?format=xml
/test1?format=html
-->
<property name="favorParameter" value="true"/>
<!--可以重新指定参数名-->
<property name="parameterName" value="mediaType"/>
<!--是否忽略http消息头中的accept部分指定的内容类型-->
<property name="ignoreAcceptHeader" value="true"/>
<property name="useJaf" value="false"/>
<!--指定默认的内容类型-->
<property name="defaultContentType" value="text/html"/>
<!--把什么参数值对应什么类型的内容-->
<property name="mediaTypes">
<map>
<entry key="json" value="application/json"/>
<entry key="xml" value="application/xml"/>
<entry key="html" value="text/html"/>
</map>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="contentNegotiationManager" ref="contentNegotiationManager"/>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
</bean>
<bean class="org.springframework.web.servlet.view.xml.MappingJackson2XmlView">
</bean>
</list>
</property>
<property name="viewResolvers">
<list>
<!--视图解析器配置-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--/WEB-INF/jsps/ index .jsp-->
<property name="prefix" value="/WEB-INF/jsps/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
</bean>
<!--静态资源文件不能使用-->
<!--<mvc:default-servlet-handler/>-->
<mvc:resources mapping="/static/**" location="/static/"/>
<!--文件上传的解释器-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"/>
<property name="maxUploadSize" value="10000000"/>
</bean>
<!--扫描控制器包下的控制器(servlet)-->
<!--<context:component-scan base-package="cn.smbms.controller"/>-->
<context:component-scan base-package="cn">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<mvc:interceptors>
<!--<bean class="cn.smbms.interceptors.SysLoginInterceptor"></bean>-->
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/static/**"/>
<mvc:exclude-mapping path="/login.html"/>
<mvc:exclude-mapping path="/login"/>
<mvc:exclude-mapping path="/"/>
<bean class="cn.smbms.interceptors.SysLoginInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
</beans>
<!-- 配置JSON视图 -->
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
<property name="objectMapper">
<bean class="org.codehaus.jackson.map.ObjectMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg index="0" type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
</bean>
</property>
</bean>
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean id="requestMappingHandlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter"/>
<ref bean="stringHttpMessageConverter"/>
</list>
</property>
</bean>
最后一段是 liu13430的