springboot 后台LocalDateTime接收参数,前台传递2022-03-28 15:03:25,报错Caused by: java.time.format.DateTimeParseEx
【代码】springboot 后台LocalDateTime接收参数,前台传递2022-03-28 15:03:25,报错Caused by: java.time.format.DateTimeParseEx。
·
报错详细信息
JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String "2021-09-30 16:05:15": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2021-09-30 16:05:15' could not be parsed at index 10; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDateTime` from String "2021-09-30 16:05:15": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2021-09-30 16:05:15' could not be parsed at index 10
at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 6, column: 13] (through reference chain: cn.haiwang.mybatis_test.generator.domain.DtsArticle["addTime"])
解决办法
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime addTime;
原因分析,注意看中间有个T,所以
报错原因,没有指定pattern,默认使用所以会使用默认的格式,也就是:DateTimeFormatter.ISO_LOCAL_DATE_TIME,就是类似这样的:2011-12-03T10:15:30
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)