SpringBoot 版本为2.7.6
1:首先引入mybatis 依赖
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.23</version> </dependency>
2:yml 文件配置
spring: application: name: demoTest # 项目名 datasource: druid: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/peixun?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: root password: root #上面是mysql 数据库连接配置 mybatis: configuration: map-underscore-to-camel-case: true #是否开启驼峰命名 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # mybatis 日志打印 mapper-locations: classpath:mapper/*.xml # resources 目录下mapper.xml 对应的文件 type-aliases-package: com.example.demotest.pojo # 实体类所在的项目包路径