Spring MVC4设置使用fastjson作为json解析器,替代jackson
来源:互联网 发布:搜图的软件 编辑:程序博客网 时间:2024/05/19 14:01
引用
不论是性能、易用性、特性支持,fastjson都要远好于默认的jackson,所以如果应用程序经常使用ajax进行数据交互,建议用fastjson作为默认解析器,官网:www.fhadmin.org只需要简单配置:
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json"/>
<!--设置fastjson特性-->
<property name="features">
<array>
<!--设置null值也要输出,fastjson默认是关闭的-->
<value>WriteMapNullValue</value>
<!--设置使用文本方式输出日期,fastjson默认是long-->
<value>WriteDateUseDateFormat</value>
</array>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
然后引入fastjson的包就好了。
附Spring MVC4示例配置文件:
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!--包扫描-->
<context:component-scan base-package="com.rs" />
<!--数据连接池,此处使用c3p0-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://x.x.x.x:3306/test" />
<property name="user" value="USER" />
<property name="password" value="PASS" />
</bean>
<!--配置事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!--使用fastjson作为json解析器-->
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json"/>
<property name="features">
<array>
<value>WriteMapNullValue</value>
<value>WriteDateUseDateFormat</value>
</array>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!--注入JdbcTemplate-->
<bean id="jdbc" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
<!--配置视图-->
<bean id="jspView" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<!--配置拦截器-->
<mvc:interceptors>
<mvc:interceptor>
<!--拦截匹配路径的html和do文件-->
<mvc:mapping path="/*/*.html" />
<mvc:mapping path="/*/*.do" />
<!--放过部分请求-->
<mvc:exclude-mapping path="/home/login.html" />
<mvc:exclude-mapping path="/home/logout.html" />
<!--自定义的拦截器-->
<bean class="com.nids.web.ActionInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
</beans>
阅读全文
0 0
- Spring MVC4设置使用fastjson作为json解析器,替代jackson
- java json解析fastjson jackson
- J2EE 工程中使用JSON作为协议的话,可以使用Fastjson作为更好的替代了
- java中使用fastjson、jackson、json-lib解析JSON-------------------妈妈再也不用担心JSON解析
- java中使用fastjson、jackson、json-lib解析JSON-------------------妈妈再也不用担心JSON解析
- Spring Boot使用FastJson解析JSON数据
- spring boot:使用fastJson解析json数据
- FastJson、Gson、Jackson json解析性能比较
- Android中Json数据解析(二)--使用Gson、Jackson和FastJson解析Json数据
- Android中Json数据解析(二)--使用Gson、Jackson和FastJson解析Json数据
- Spring-boot中使用fastjson作为json框架
- Spring mvc4使用JSON
- 4. Spring Boot 完美使用FastJson解析Json数据
- Spring Boot 学习4--完美使用FastJson解析Json数据
- 【Spring Boot】完美使用FastJson解析JSON数据
- Spring Boot 使用第三方json解析 : fastjson
- Spring Boot完美使用FastJson解析JSON数据(十三)
- 大话JSON:fastjson、jackson、json
- ros:kcf算法+行人检测 = 让机器人自动识别并追踪行人
- 漫谈程序员系列:咦,你也在混日子啊
- 【Linux】升级pyhton版本
- Android 关于网络通信
- 最小均方算法 LMS
- Spring MVC4设置使用fastjson作为json解析器,替代jackson
- 移动click消除300毫秒及摇一摇
- android vold初始化及sd卡挂载流程
- 发邮件
- JS
- 数组、List和ArrayList的区别
- 数据库三大范式
- CentOS6.5搭建ZooKeeper集群与单机
- handler消息传递机制