在SpringmMVC的配置文件中加入以下代碼
(目前最新版的配置是這樣,之前版本的配置方式貌似不行了.)html
<mvc:annotation-driven> <!--不使用默認消息轉換器 --> <mvc:message-converters register-defaults="false"> <!--spring消息轉換器 --> <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/> <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/> <!--解決@Responcebody中文亂碼問題 --> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg value="UTF-8"/> </bean> <!--配合fastjson支持 --> <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="defaultCharset" value="UTF-8"/> <property name="supportedMediaTypes"> <list> <!--順序保持這樣,避免IE下載出錯 --> <value>text/html;charset=UTF-8</value> <value>application/json</value> </list> </property> <property name="fastJsonConfig" ref="fastJsonConfig"/> </bean> </mvc:message-converters> </mvc:annotation-driven> <!--fastJsonConfig --> <bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig"> <!--默認編碼格式 --> <property name="charset" value="UTF-8"/> <property name="serializerFeatures"> <list> <value>WriteNullListAsEmpty</value> <value>WriteDateUseDateFormat</value> <value>PrettyFormat</value> <value>WriteMapNullValue</value> <value>WriteNullStringAsEmpty</value> <value>WriteNullListAsEmpty</value> <value>DisableCircularReferenceDetect</value> </list> </property> </bean> <!--fastjson支持配置結束 -->
2017/11/23
Luciferspring