Note/大学笔记/Java/Springboot/3.整合MyBatis-plus、Druid.md

61 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 1.整合MyBatis-Plus
1.导入starter
```xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
```
2.配置数据源相关信息
```yaml
#2.配置相关信息
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ssm_db
username: root
password: root
```
3.前数据库的表名定义规则是tbl_模块名称为了能和实体类相对应需要做一个配置相关知识各位小伙伴可以到MyBatisPlus课程中去学习此处仅给出解决方案。配置application.yml文件添加如下配置即可设置所有表名的通用前缀名
```yaml
mybatis-plus:
global-config:
db-config:
#设置所有表的通用前缀名称为tbl_
table-prefix: tbl_
```
## 2.整合Druid
1.导入对应的starter
```XML
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.6</version>
</dependency>
</dependencies>
```
2.修改配置
```YAML
spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ssm_db?serverTimezone=UTC
username: root
password: root
```