默认情况下,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>

<dependency>

          <groupId>com.fasterxml.jackson.core</groupId>

          <artifactId>jackson-core</artifactId>

          <version>2.7.3</version>

</dependency>

<dependency>

          <groupId>com.fasterxml.jackson.core</groupId>

          <artifactId>jackson-databind</artifactId>

          <version>2.7.3</version>

</dependency>

相关文章:

  • 2022-12-23
  • 2021-10-12
  • 2021-05-22
  • 2021-08-08
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-16
  • 2021-08-31
  • 2022-12-23
  • 2021-11-11
  • 2021-11-21
  • 2021-12-13
  • 2021-08-19
相关资源
相似解决方案