整合步骤
- 导入mybatis官方starter
- 编写mapper接口(标注@Mapper注解)
- 编写sql映射文件并且绑定mapper接口
- 在application.yml文件中指定Mapper配置文件的位置,以及指定全局配置文件的信息(建议:将要配置在该文件中的内容写在application.yml中的mybatis.configuration项下)
1.pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>Springboot06_mybatis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Springboot06_mybatis</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<!--springboot和mybatis整合: mybatis-spring-boot-starter-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
<!--mysql驱动-->
<