1、引入jar包
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.4</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency>
2、编写application.properties配置文件
mybatis.type-aliases-package=com.example.demo.model spring.datasource.url=jdbc:mysql://localhost:3306/day13?useUnicode=true&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password= spring.datasource.driver-class-name=com.mysql.jdbc.Driver
3、在application类上加@MapperScan扫描mapper类文件
@MapperScan("com.example.demo.model.mapper")
4、在pom.xml中放行mapper.xml
<resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources>