Home Tags Posts tagged with "Springboot整合JDBC"

Springboot整合JDBC

1.创建项目,导入依赖:JDBC+Mysql

<!--       JDBC,公共前缀:spring-boot-starter-->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<!--      Mysql,公共前缀:spring-boot-starter-->
<dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
</dependency>


2.配置数据库链接文件(application.yaml)
spring:
  datasource:
    username: root
    password: 123456789
    url: jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
    driver-class-name: com.mysql.cj.jdbc.Driver

3.开始测试
3.1注入数据源