SpringMVC整合FastJson:用"最快的json转换工具"替换SpringMVC的默认json转换
2017-11-23 09:18
357 查看
一.环境说明
Windows 10 1709Spring 4.3.12.RELEASE
FastJson 1.2.40
IDEA 2017.3
JDK 1.8.0_144
二.开始配置
在SpringmMVC的配置文件中加入如下代码(目前最新版的配置是这样,以前版本的配置方式貌似不行了.)
<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
Lucifer
相关文章推荐
- SpringMVC整合FastJson:用"最快的json转换工具"替换SpringMVC的默认json转换
- 使用fastjson 替换springMvc默认的jackson
- SpringMVC整合FastJson及简单使用
- FastJson--阿里开源的速度最快的Json和对象转换工具
- FastJson--阿里开源的速度最快的Json和对象转换工具
- SpringMVC与fastjson整合并同时解决中文乱码问题
- json转换工具——fastjson的使用
- springmvc4.x+fastjson 整合及问题
- FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具(转)
- FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具
- FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具
- fastJson的使用(高效的json转换工具)
- SpringMVC整合fastjson-1.1.41
- FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具
- springMVC 与 fastjson整合
- SpringMVC整合fastjson、easyui 乱码问题
- springMVC整合FastJson实现RestFul风格API
- jackson ObjectMapper 序列化成json,属性值为null时转换为""空字符串
- FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具
- SpringMVC整合fastjson