@MapperScan注解

我们在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);
	}

}

  

原文地址:https://www.cnblogs.com/Amywangqing/p/12896663.html