springboot 前后端日期json格式化
1、常规代码
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;//创建时间
2、由于字段类型是LocalDateTime,所以可以手动设置序列化与反序列化的类
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
3、后端到前端格式化@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
4、前端到后端格式化@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")