spring boot项目中的application.properties设置了时区不生效的处理
1.有时候在spring boot中连接数据库时设置了时区,但是还是不生效,
如在application.properties 的pring.datasource.url中设置了
2.但结果,查询出来的时间数据不对
解决办法
a. 在配置文件application.properties连接数据库后加上useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC(如1)
b. 在启动类中添加
@PostConstruct
void setTimeZone() {
TimeZone.setDefault(TimeZone.getTimeZone(“UTC”));
}
如图: