SpringMVC接收Date时间数据问题报错

转载出处  https://blog.csdn.net/u011321758/article/details/80310678

Failed to convert value of type 'java.lang.String' to required type 'java.util.Date';

实体类参数需要加上注解

@DateTimeFormat
@JsonFormat
   /** 开始时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern="yyyy-MM-dd",timezone="GMT+8")
    private Date startTime;

    /** 结束时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern="yyyy-MM-dd",timezone="GMT+8")
    private Date endTime;

@JsonFormat 默认是标准时区的时间, 北京时间 东八区 timezone=”GMT+8” 
作用:后台的时间 格式化 发送到前台

@DateTimeFormat 接受前台的时间格式 传到后台的格式

原文地址:https://www.cnblogs.com/javaLin/p/14164144.html