一.pom.xml添加MybatisPlus依赖
<!-- mybatis plus 依赖 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.3</Version> </dependency> <!-- mysql 和 druid连接池 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.26</Version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.2.6</Version> </dependency>
二.application.yml添加数据库配置信息并声明druid数据源
spring:
# mysql 配置
datasource:
url: jdbc:mysql://localhost:3306/demo? useSSL=false&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=Asia/Shanghai
username: root
password: root
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver#控制台打印sql
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
三.配置注解和mapper,entity
1.启动类添加包扫描
@SpringBootApplication