springboot怎样接收前端的Date类型对象

先说答案:

  1. 这两个注解@DateTimeFormat @JsonFormat 一个不能少
  2. yyyy-MM-dd 只能接收日期,需要时间类型自己自定义yyyy-MM-dd HH:mm:ss
  3. timezone = "GMT+8" 时区必须加上,不然日期转换过来的时间是上午8点
@Data
public class TimeRangeVO {
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat( pattern="yyyy-MM-dd", timezone = "GMT+8")
    private Date startDate;
    @JsonFormat( pattern="yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。