日常开发过程中经常会使用json进行数据的传输,这就涉及到了对象和json的相互转化,常用的解决方案:Jackson(推荐)
JSON ( JavaScript Object Notation) ,是一种数据交互格式
SpringMVC中使用json数据类型格式(jackson的方式)
我们的方法:
1.使用前导入相关依赖让我们能使用jackson
<dependencies>
<dependency>
<groupId>de.plushnikov.lombok-intellij-plugin</groupId>
<artifactId>lombok-plugin</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.1</version>
</dependency>
</dependencies>
2.编写web.xml
配置servlet和过滤器
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!-- 配置web.xml 配置DispatcherSeervlet和过滤器-->
<servlet>
<servlet-name>SpringMVC