1. MyBatis Plus

1.1 导入依赖

  1. <dependency>
  2. <groupId>com.baomidou</groupId>
  3. <artifactId>mybatis-plus-boot-starter</artifactId>
  4. <version>${mybatisplus.version}</version>
  5. </dependency>

1.2 配置

1.2.1 配置数据源

  1. 导入数据库驱动

    1. <!-- mysql-connector -->
    2. <dependency>
    3. <groupId>mysql</groupId>
    4. <artifactId>mysql-connector-java</artifactId>
    5. <version>8.0.17</version>
    6. </dependency>
  2. application.yml中配置数据源相关信息

    1. spring:
    2. datasource:
    3. username: root
    4. password: root
    5. url: jdbc:mysql://192.168.182.128:3306/gulimall_pms
    6. driver-class-name: com.mysql.cj.jdbc.Driver
  3. 配置mybatis-plus

1)在启动类上使用@MapperScan()注解,指定mapper接口包路径
2)在application.yml中配置mybatis-plus相关参数

  1. mybatis-plus:
  2. # 其中,classpath后的“*”代表不止扫描当前项目类路径下的mapper文件,也扫描所引用包的类路径下的mapper文件
  3. # mapper-locations: classpath*:/mapper/**/*.xml
  4. mapper-locations: classpath:/mapper/**/*.xml
  5. global-config:
  6. db-config:
  7. # 主键自增
  8. id-type: auto