SpringBoot中默认的JSON解析方案
一、pom依赖
# 在这边我们不需要去导入专门的json解析,因为在spring-boot-stater-web中含有spring-boot-stater-json依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
二、User实体
# User实体来做测试返回,在User中加入了date类
public class User {
private Integer id;
private String name;
private Date birthday;
private String address;
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", birthday=" + birthday +
", address='" + address + '\'' +
'}';
}
}
三、UserController控制器
# 在这边我们就不连接数据库进行测试了,直接去循环添加一下假数据进行返回
@RestController
public class UserController {
@GetMapping("user")