我們在mapper的接口上使用@Mapper注解,在編譯之后會生成相應的接口實現類,這樣每個mapper接口上都要使用@Mapper注解,這樣太麻煩了,我們可以使用@MapperScan注解
1.@MapperScan注解的使用
Springboot啟動類上面添加@MapperScan注解,就指定mapper接口所在的包,然后包下面的所有接口在編譯之后都會生成相應的實現類
@SpringBootApplication @MapperScan(basePackages= {"com.qingfeng.mapper"}) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
使用掃描多個mapper,用逗號分隔開
@SpringBootApplication @MapperScan(basePackages= {"com.qingfeng.mapper","com.qing.mapper"}) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }