今天碰到一个情况就是 get 请求到后端的时候日期无法转换,但是 Date 上明明使用了注解但是就是报错
@DateTimeFormat(pattern = "yyyy-MM-dd")
//@JsonFormat(pattern = "yyyy-MM-dd" , timezone="GMT+8")
private Date date;
报错信息是这样的
code:400
data:{}
msg:
"date:Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.alibaba.excel.annotation.format.DateTimeFormat java.util.Date] for value '2023-9-01'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2023-9-01]"
success:false
迷惑的点在于如果加上 HH:mm:ss 的话,把日期+00:00:00 就不会报错。 请教一下大佬到底怎么办才能让后端正确接收这个不带时分秒的日期?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.