Date类型的属性字段可以用@DateTimeFormat和@JsonFormat注解
@DateTimeFormat
可以把前端string类型转换到后端date类型
/**
* 支出时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date spendingTime;
@JsonFormat
能够把后端date类型转换到前端string
pattern:是你需要转换的时间日期的格式
timezone:要设置为东八区,避免时间在转换中有误差
/**
* 支出时间
*/
@JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
private Date spendingTime;