注解


日期时间类型转换
@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;
}

文章作者: zrh
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 zrh !
  目录