Could not read document: Cannot deserialize value of type `java.util.Date` from String

文章目录

现象

    @ResponseBody
    @RequestMapping("/ooxx/save")
    public ResultStatus saveOOxx(@RequestBody ooxx ooxx, HttpSession session, Model model) {}

后台接受实体类时,报错

[WARN](2020-04-20 16:43:59,046)-Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Cannot deserialize value of type `java.util.Date` from String "2020-04-20 00:00:00": not a valid representation (error: Failed to parse Date value '2020-04-20 00:00:00': Cannot parse date "2020-04-20 00:00:00": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
 at [Source: (PushbackInputStream); line: 1, column: 127] (through reference chain: com.ooxx.pojo.ooxx["ooxx"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2020-04-20 00:00:00": not a valid representation (error: Failed to parse Date value '2020-04-20 00:00:00': Cannot parse date "2020-04-20 00:00:00": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
 at [Source: (PushbackInputStream); line: 1, column: 127] (through reference chain: com.ooxx.pojo.ooxx["ooxx"])-org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.handleHttpMessageNotReadable(DefaultHandlerExceptionResolver.java:377)-

解决

前端传时间属性的参数时,不要直接传字符串,使用 new Date(‘timeStr’) 把这个字符串包起来就好了

var request = {
//ooxx: finishDate
ooxx: new Date(finishDate)
}
发布了84 篇原创文章 · 获赞 10 · 访问量 4415

猜你喜欢

转载自blog.csdn.net/AlphaBr/article/details/105638791
今日推荐