springboot整合mybatis-plus
1.导入依赖
<!--mybatis-plus--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.2.0</version> </dependency>
2.配置
1、配置数据源:
1).导入驱动(驱动8.0兼容MySQL5.7以及其他版本)
<!-- MySQL驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.17</version> </dependency>
2).在application.yml里面配置数据源相关信息
spring: datasource: username: root password: 123456 url: jdbc:mysql://localhost:3306/gulimall_pms driver-class-name: com.mysql.jdbc.Driver
2、配置mybatis-plus
1).在application.yml里面使用@MapperScan("mapper接口的引用地址")
2).告诉mybatis-plus,sql映射文件的位置(在application.yml里面去配置)
mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml
再给实体类有@TableId的主键的在配置文件设置统一自增
mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml global-config: db-config: id-type: auto
本文来自博客园,作者:迷糊桃,转载请注明原文链接:https://www.cnblogs.com/mihutao/p/15702435.html