直接在Mapper类上面添加注解@Mapper,这种方式要求每一个mapper类都需要添加此注解,比较麻烦。
通过使用@MapperScan可以指定要扫描的Mapper类的包的路径,比如:
@SpringBootApplication
@MapperScan("cn.test.water.monitor.mapper")
// 添加对mapper包扫描
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
使用@MapperScan注解多个包
@Configuration
@MapperScan(basePackages = {"cn.test.data.**.mapper","cn.test.face.**.mapper"})