日期时间类型转换
@DateTimeFormat(pattern = “yyyy-MM-dd”)
包:org.springframework.format.annotation.DateTimeFormat;
作用:接收pattern格式的字符串<input type="date">
转为date类型的数据
@JsonFormat(pattern = “yyyy-MM-dd”)
包:com.fasterxml.jackson.annotation.JsonFormat;
作用:将date类型的数据转为pattern格式的字符串返回前端
例:
public class Book {
private Integer id;
private Integer categoryId;
private String name;
private Double price;
private Category category;
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date updateDate;
}