一
在pom.xml文件中添加依赖(这里就不详细叙述了,可以百度)。
二
在启动类中通过@MapperScan注解配置扫描mapper接口
package com.syc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tk.mybatis.spring.annotation.MapperScan;
@SpringBootApplication
//通过注解配置扫描mapper接口所在包
@MapperScan(value="com.syc.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
三
在application.yml文件中添加mybatis相关配置
mybatis:
#配置实体类别名包扫描
type-aliases-package: com.syc.domain
#配置mybatis中mapper接口对应xml文件所在路径
mapper-locations: classpath*:mapperConfig/*Mapper.xml
四
给mapper接口添加@Mapper注解(由于我之前引用了通用mapper,所以代码中@Mapper注解为全路径