@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);
	}

}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM