maven依赖(之后返回的结果,默认就会自动进行json序列化)
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.3</version>
</dependency>
java
@PostMapping("/test77")
@ResponseBody
public User test7() {
User user = new User();
user.setUserName("pjw");
user.setPassword("123456");
return user;
}
处理Date(不处理的话,默认返回时间戳)
public class User {
private String userName;
private String password;
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")//响应格式,timezone解决时区问题
@DateTimeFormat(pattern = "yyyy-MM-dd")//接收请求时格式
private Date date;
}