1|0一、問題描述
1|11.異常信息
org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error:Cannot deserialize value of type `java.util.Date` from String "2020-06-16": not a valid representation (error: Failed to parse Date value '2020-06-16': Unparseable date: "2020-06-16");
nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2020-06-16": not a valid representation (error: Failed to parse Date value '2020-06-16': Unparseable date: "2020-06-16")
1|22.報錯原因
1)服務器用@RequestBody接收數(shù)據(jù)時,前端傳的格式是yyyy-MM-dd; 2)異常描述:反序列化失敗,yyyy-MM-dd不是有效的格式。
2|0二、解決方案
給對應實體屬性添加@JsonFormat注釋,pattern格式要與前端一致。
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd" , timezone = "GMT+8")
private Date date;
__EOF__
|