一、错误内容
前后端分离项目,前端使用POST请求,将Date日期使用字符串String的类型传输给后端,后端加@RequestBody将JSON字符串,并将它转成对象。
但是,报了如下错误
Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property.
2023-03-24 10:05:54.508[XNIO-1 task-1] ERROR com.xxxx.common.security.handler.GlobalExceptionHandler - org.springframewor
SpringBoot处理前后端日期转换异常
本文讨论了SpringBoot在处理POST请求时遇到的日期转换错误,即从String到Date转换失败。分析了错误原因在于日期格式不匹配,Spring默认接受dd/mm/yyyy格式,而实际传入的是yyyy-MM-dd HH:mm:ss。解决方案是在application.yaml中配置JSON日期格式。同时,区分了`spring.jackson.date-format`和`spring.mvc.date-format`在不同Content-Type场景下的作用和优先级。
订阅专栏 解锁全文
6188

被折叠的 条评论
为什么被折叠?



