解决mysql查询时间差八个小时,springboot插入date类型数据pojo无法接收
首先,linux的 /etc/my.cnf,进入,更改时区,系统默认世界子午线时间,中国在东八区需加上8小时
重启mysql,进入navcat查询时间,如下则成功
我是springboot开发,连接数据库时加上serverTimezone=Asia/Shanghai改为上海时间
spring.datasource.url=jdbc:mysql://xxx/xxx?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
然后配置中加上
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss spring.jackson.time-zone=GMT+8
如下pojo配置,gmtCreat,和gmtModified是年月日时分秒,lastOrder是时分秒,jsonFormat是为了解决无法映射成date类型,datetimeformat是为了日期格式转换
如下是查询结果,此处注明我的数据库,gmtModified用的是datetime类型保留年月日时分秒,lastOrder用的是time类型只保留时分秒