记一次工作中alibaba.fastjson无法使用问题

时间:2019-05-29 17:25:53   收藏:0   阅读:1531

默认情况下,springMVC的@ResponseBody返回的是String类型,如果返回其他类型则会报错。
使用fastjson的情况下,在springmvc.xml配置里加入:

<mvc:annotation-driven>
<mvc:message-converters
register-defaults="true">
<bean
class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json</value>
<value>application/xml;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

在pom.xml引入依赖:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>

原文:https://www.cnblogs.com/chxwkx/p/10945029.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!