Springboot整合MybatisPlus

发布时间 2023-12-16 22:05:41作者: ccblblog

1、引入mybatis-plus坐标

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

2、配置数据源

spring:
  datasource:
    username: root
    password: root
    url: jdbc://192.168.5.1:3306/admin?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
    driver-class-name: com.mysql.cj.jdbc.Driver

3、开启Mapper扫描

使用@MapperScan开启mapper扫描,指定需要扫描的mapper位置

image

4、指定Mapper.xml所在的文件的位置

mybatis-plus:
  mapper-locations: classpath*:/mapper/**/*.xml

image