《《《Springboot 配置 application.yml 连接MySQL数据库

转载地址:https://www.cnblogs.com/linliquan/p/10987673.html

1.在pom.xml的<dependencies></dependencies>标签中中加入以下依赖

 1 <dependency>
 2             <groupId>org.springframework.boot</groupId>
 3             <artifactId>spring-boot-starter-web</artifactId>
 4         </dependency>
 5 
 6         <dependency>
 7             <groupId>org.mybatis.spring.boot</groupId>
 8             <artifactId>mybatis-spring-boot-starter</artifactId>
 9             <version>2.0.1</version>
10         </dependency>
11 
12         <dependency>
13             <groupId>mysql</groupId>
14             <artifactId>mysql-connector-java</artifactId>
15             <scope>runtime</scope>
16         </dependency>
17 
18         <dependency>
19             <groupId>com.alibaba</groupId>
20             <artifactId>druid</artifactId>
21             <version>1.1.10</version>
22         </dependency>

2.把resource包下的application.properties复制一份再粘贴名字改成application.yml,加入以下内容

server:
  port: 8080
  servlet:
    context-path: /
spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver

我的数据库密码是123456,数据库名是mybatis

posted @ 2020-08-23 11:08  贩卖长江水  阅读(1370)  评论(0编辑  收藏  举报