1、方式一:使用注解@Mapper

在所有mapper接口上添加注解@Mapper;Spring boot启动注解自动扫描。

以下是Spring Boot缺省扫描配置,自动开启自动扫描,即启动就会自动扫描所有自定义bean

2、方式二:使用注解@MapperScan

在springboot启动类上添加注解@MapperScan,标注dao所在包路径。一劳永逸,推荐使用!!

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@EnableDiscoveryClient
@MapperScan(basePackages = {"com.mp.service.provider.dao"})
@SpringBootApplication
public class MpServiceProviderApplication {
    public static void main(String[] args) {
        SpringApplication.run(MpServiceProviderApplication .class, args);
    }
}

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐