对于使用element-ui中的日期时间选择器产生的json数据转换格式报错
报错如下所示
JSON parse error: Cannot deserialize value of type java.time.LocalDateTime
from String "2023-03-29 19:00:00": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2023-03-29 19:00:00' could not be parsed, unparsed text found at index 16; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.time.LocalDateTime
from String "2023-03-29 19:00:00": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2023-03-29 19:00:00' could not be parsed, unparsed text found at index 16
前端
在日期选择器标签中添加日期格式化 value-format="yyyy-MM-dd HH:mm:ss"
<el-form-item label="时间" prop="meetingStartTime">
<el-date-picker v-model="time" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss">
</el-date-picker>
</el-form-item>
后端
在接受参数的Dto类中在对应的日期类中的成员变量上, 添加@JsonFormat注解
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
private LocalDateTime meetingEndTime;
然后问题就解决了
标签:00,java,LocalDateTime,json,报错,time,选择器 From: https://www.cnblogs.com/hzxc/p/17269407.html