2017年11月23日 09:18:03

阅读数:306

一.环境说明

  • Windows 10 1709
  • Spring 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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cslucifer/article/details/78610515

SpringMVC整合FastJson:用"最快的json转换工具"替换SpringMVC的默认json转换的更多相关文章

  1. springmvc整合fastjson

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. java处理json的工具类(list,map和json的之间的转换)

    需要下载第三方的jar :net.sf.json import java.io.BufferedReader; import java.io.InputStream; import java.io.I ...

  3. SpringMVC整合fastjson、easyui 乱码问题

    一.框架版本 SpringMVC:3.1.1.RELEASE fastjson:1.2.7 easyui :1.4.5 二.乱码现象    Action中使用@ResponseBody返回Json数据 ...

  4. Android 中的Json解析工具fastjson 、序列化、反序列化

    Android中通常需要访问服务器,然而服务器返回的数据很多时候都是Json格式 1.fastjson简介 阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备 ...

  5. Android进阶笔记17:3种JSON解析工具(org.json、fastjson、gson)

    一. 目前解析json有三种工具:org.json(Java常用的解析),fastjson(阿里巴巴工程师开发的),Gson(Google官网出的),其中解析速度最快的是Gson. 3种json工具下 ...

  6. Android进阶笔记14:3种JSON解析工具(org.json、fastjson、gson)

    一. 目前解析json有三种工具:org.json(Java常用的解析),fastjson(阿里巴巴工程师开发的),Gson(Google官网出的),其中解析速度最快的是Gson. 3种json工具下 ...

  7. 在线的JSON formate工具

    一个非常好的json formate工具 可以很容易发现json的错误,以及对json进行格式化 https://jsonformatter.curiousconcept.com/

  8. 2.FastJson公司--阿里巴巴开源的速度最快的Json和对象转换工具

    转自:https://blog.csdn.net/gongpulin/article/details/52062532 这是关于FastJson的一个使用Demo,在Java环境下验证的 这是关于Fa ...

  9. 分享知识-快乐自己:SpringMvc整合遇到-前台传JSON参数,后台实体类对象接收

    前台数据转JSON对象: /** * * @param $myFrom:from表单 * @returns {{}} */ function from($myFrom) { var ebookEntr ...

随机推荐

  1. Python学习(十八)—— 数据库(三)

    转载自http://www.cnblogs.com/linhaifeng/articles/7356064.html 一.数据操作 1.插入数据INSERT 1. 插入完整数据(顺序插入) 语法一: ...

  2. 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?

    假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解释: 有两 ...

  3. day70 cookie & session 前后端交互分页显示

    本文转载自qimi博客,cnblog.liwenzhou.com 概要: 我们的cookie是保存在浏览器中的键值对 为什么要有cookie? 我们在访问浏览器的时候,千万个人访问同一个页面,我们只要 ...

  4. POJ 1222 EXTENDED LIGHTS OUT (熄灯问题)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8417   Accepted: 5441 Description In an ...

  5. LINQ技术

    转载http://www.cnblogs.com/Dlonghow/p/1413830.html Linq (Language Integrated Query,语言集成查询),是微软公司提供的一项新 ...

  6. Unable to load configuration. - action - file:/F:/apache-tomcat-8.0.30/webapps/test1Struts2/WEB-INF/classes/struts.xml:11:71

    Unable to load configuration. - action - file:/F:/apache-tomcat-8.0.30/webapps/test1Struts2/WEB-INF/ ...

  7. 【LeetCode算法-9】Palindrome Number

    LeetCode第9题 Determine whether an integer is a palindrome. An integer is a palindrome when it reads t ...

  8. Squid正向代理(编译安装)

    编译安装 版本为squid-3.5.27 系统为Centos6.5 依赖环境 yum install -y perl gcc*autoconf automake make sudo wget libx ...

  9. JAG Practice Contest for ACM-ICPC Asia Regional 2016.K.Non-redundant Drive(点分治)

    Atcoder vjudge 这标题好长... \(Description\) 给定一棵\(n\)个点的树.在每个点\(i\)你可以补充\(g_i\)的油量,经过一条边需要花费边长的油量.你可以选择从 ...

  10. 2017-9-11-Linux开机启动脚本

    参考文章:https://www.magentonotes.com/ubuntu-config-autostart-shell-script.html 还是先开门见山的说,Linux需要添加开机启动程 ...