vue Spring 传参时,日期 date类型,前端传入日期字符串【带有时分秒】,bean类接收JSON转换异常问题,异常详情如下


Cannot deserialize value of type `java.util.Date` from String "2020-08-12 11:45:12": not a valid representation (error: Failed to parse Date value '2020-08-12 11:45:12':
 Cannot parse date "2020-08-12 11:45:12": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
 at [Source: (PushbackInputStream); line: 9, column: 15]

解决办法:

在对应的bean日期属性上增加注解 @JsonFormat 注解

@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    private Date followTime;
Logo

前往低代码交流专区

更多推荐