1.引入依赖
<!--mysql依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--MyBatis-Plus (简称 MP)是一个 MyBatis 的增强工具,
在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.2.0</version>
</dependency>
<!--数据库连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
2.dev中 编写配置信息
#数据库链接信息
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/clothing?useSSL=false&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
username: root
password: ZhangFan!!1
initial-size: 1
min-idle: 1
max-active: 20
test-on-borrow: true
#扫描mapper包下以Dao.xml结尾的文件
mybatis-plus:
mapper-locations: classpath*:mapper/*Dao.xml
3.编写配置类
1. 在 config 包下创建 MyMybatisPlusConfiguration 类
2. 为类增加 @Configuration 和 @MapperScan
3. 配置分页插件
package com.zhiyou100.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;