赞
踩
线上环境后台接收日期字段时,前端页面传的是String字符串格式的日期,后端实体类该日期字段类型为Date
,使用Jackson
工具包是可以做到年月日的自动转换,本地并无异常,但是线上环境却无法进行转换,异常信息如下:
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2024-06-04"
排查后发现,问题在于线上环境的nacos配置有问题。
在Spring Boot应用中,可以通过application.properties或application.yml文件统一配置Jackson的日期格式:
# application.properties
spring.jackson.date-format=yyyy-MM-dd
spring.jackson.time-zone=GMT+8
或者
# application.yml
spring:
jackson:
date-format: yyyy-MM-dd
time-zone: GMT+8
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。