1 导入依赖
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency>
2 配置mybatis
在application.yml中添加:
mybatis:
mapper-locations: classpath:cn/xh/mapper/*Mapper.xml
3 配置Mapper接口扫描包
在主配置类(ApplicationConfig.java)中添加注解@MapperScan:
@SpringBootApplication @MapperScan("cn.xh.web.controller.mapper") public class ApplicationConfig { ... }