<!--整合jdbc--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!--整合jdbc-->
个人配置文件使用的是yml:application.yml,因此配置数据源的格式是yml的
spring: datasource: username: root password: root url: jdbc:mysql://localhost:3306/MOxor?serverTimezone=UTC driver-class-name: com.mysql.cj.jdbc.Driver
url中加上了 “?serverTimezone=UTC”这里采用的全球标准时间,避免链接报错
注意!!!注意!!!注意!!!html
中国时区比UTC快8小时,在插入数据中有时间数据时,会有时差,这里能够用:
// 北京时间==东八区时间!=北京当地时间 serverTimezone=GMT%2B8 // 或者使用上海时间 serverTimezone=Asia/Shanghai
@Autowired private DataSource dataSource; @Test public void contextLoads() {} @Test public void testDbType() { System.out.println("自动装配数据源的类型:"+dataSource.getClass()); }
JDBC链接数据库 mysql serverTimezone 时差问题java
如有不足,敬请指正 虚心若愚,求知若渴