happy birthday BNTang!

2 Elment Ui 日期选择器 格式化问题

Elment Ui 日期选择器 格式化问题

在前后端联调过程中 我们常常会遇到日期无法被反序列化 这个问题 会有点头疼

下面以我这边为例 后端使用的是springboot 默认集成了jackjson 可以配置 就能实现序列化时间啦

image-20220617003509941

.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String "2022-06-17 00:31:04": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2022-06-17 00:31:04' could not be parsed at index 10; 

大概意思是 这个时间格式 无法被反序列化

解决办法

后端配置

很简单 在接收参数的属性上添加 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")

大概意思是 可以反序列化的格式 是yyyy-MM-dd HH:mm:ss

image-20220617003903450

前端

官方文档

image-20220617002224306

因为我们用的是 elmentui组件 配置就更简单了 只需要指定格式化的时间格式

注意这个日期格式 要跟后端一一对应哦

image-20220617004048446

posted @ 2022-06-17 00:46  look-word  阅读(172)  评论(0编辑  收藏  举报