Note/JAVA/Springboot/3.整合MyBatis-plus、Druid.md
2023-08-31 11:30:31 +08:00

1.3 KiB
Raw Blame History

1.整合MyBatis-Plus

1.导入starter

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.4.3</version>
</dependency>

2.配置数据源相关信息

#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文件添加如下配置即可设置所有表名的通用前缀名

mybatis-plus:
  global-config:
    db-config:
    #设置所有表的通用前缀名称为tbl_
      table-prefix: tbl_		

2.整合Druid

1.导入对应的starter

<dependencies>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.2.6</version>
    </dependency>
</dependencies>

2.修改配置

spring:
  datasource:
    druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/ssm_db?serverTimezone=UTC
      username: root
      password: root