目录
1. pom.xml中导入Jackson依赖
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
2. springmvc配置文件diapatcherServlet.xml中注册注解驱动。
一定要注意注册的是xmlns:mvc="http://www.springframework.org/schema/mvc xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd""
否则报错500,不能转换JSON格式。
<!-- 在响应ajax请求和处理静态资源访问都要用到注解驱动,一定要注意注册的是哪个驱动!!!!!!-->
<mvc:annotation-driven />