fix: 数据源会话时区强制 +08:00,修复创建时间早 8 小时
生产数据库容器(1Panel-mariadb-ZOpD)的 system_time_zone 是 UTC,而数据源 URL 写着 serverTimezone=Asia/Shanghai:JDBC 会话时区是 UTC、驱动却按 +08 解析服务端返回的字面量, 于是 timestamp 列(分类管理、文章、系统日志、审核流、AI 对话等)读出来整体早 8 小时。 数据源 URL 增加 connectionTimeZone=%2B08:00&forceConnectionTimeZoneToSession=true, 连接建立时把会话时区设为 +08:00,与 JVM 默认时区、spring.jackson.time-zone 保持一致。 用偏移量而非命名时区,避免 MariaDB 容器未加载时区表时报 Unknown or incorrect time zone。 附 sql/20261026_timezone_8h_check.sql:部署后的时区自检、分类管理核对, 以及 datetime 列历史 UTC 字面量与教师建号行的时间回填模板(默认注释未执行)。
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
# 数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://132.232.214.96:13306/tuanwei?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
|
||||
# 与生产保持一致:会话时区强制 +08:00,避免 DB 容器时区不同导致 8 小时偏差
|
||||
url: jdbc:mysql://132.232.214.96:13306/tuanwei?useUnicode=true&characterEncoding=utf8&useSSL=false&connectionTimeZone=%2B08:00&forceConnectionTimeZoneToSession=true&rewriteBatchedStatements=true
|
||||
username: tuanwei
|
||||
password: TytQZsSW5m4wGh38
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
# 数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://1Panel-mariadb-ZOpD:3306/tuanwei?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
|
||||
# forceConnectionTimeZoneToSession:连接建立时把会话时区设为 +08:00。
|
||||
# 生产 DB 容器(1Panel-mariadb-ZOpD)system_time_zone=UTC,若不强制,会话时区会是 UTC,
|
||||
# 与驱动连接时区(+08) 不一致,timestamp/date 列读出会早 8 小时。
|
||||
url: jdbc:mysql://1Panel-mariadb-ZOpD:3306/tuanwei?useUnicode=true&characterEncoding=utf8&useSSL=false&connectionTimeZone=%2B08:00&forceConnectionTimeZoneToSession=true&rewriteBatchedStatements=true
|
||||
username: tuanwei
|
||||
password: TytQZsSW5m4wGh38
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
Reference in New Issue
Block a user