在使用SpringMVC的ResponseBody自动返回json时,需要引入3个jar包!
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.9</version> </dependency> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.8.9</version> </dependency> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.8.9</version> </dependency>
单单引入这三个jar包还是不够的,还需要在Springmvc的配置文件中开启<mvc:annotation-driven />注解,直接把这个写到springmvc的配置文件中即可!
(我以前都是使用自己封装的一个response的工具类,使用response.getWritter.print向前台输出的,现在改用responsebody了才碰到这么多坑,所以跟大家提一下,避免各位像我一样浪费时间)
时间: 2024-10-07 12:31:00