1.有时候在spring boot中连接数据库时设置了时区,但是还是不生效,
如在application.properties 的pring.datasource.url中设置了
spring boot项目中的application.properties设置了时区不生效的处理
2.但结果,查询出来的时间数据不对
spring boot项目中的application.properties设置了时区不生效的处理

解决办法

a. 在配置文件application.properties连接数据库后加上useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC(如1)
b. 在启动类中添加
@PostConstruct
void setTimeZone() {
TimeZone.setDefault(TimeZone.getTimeZone(“UTC”));
}

如图:spring boot项目中的application.properties设置了时区不生效的处理

结果

spring boot项目中的application.properties设置了时区不生效的处理

相关文章:

  • 2022-01-02
  • 2021-08-24
  • 2021-04-09
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-12
  • 2021-09-01
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案