@Mapper注解和@MapperScan注解的使用

@MapperScan 如果想要每个接口都要变成实现类,那么需要在每个接口类上加上@Mapper注解,比较麻烦,解决这个问题用@MapperScan; 作用:指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类; 添加位置:是在Springboot启动类上面添加; @SpringBootApplication @MapperScan("com.winter.dao") public class SpringbootMybatisDemoApplication { public static void main(String[] args) { SpringApplication.run(SpringbootMybatisDemoApplication.class, args); } } 添加@MapperScan(“com.winter.dao”)注解以后,com.winter.dao包下面的接口类,在编译之后都会生成相应的实现类。 3、使用@MapperScan注解多个包 实际用的时候根据自己的包路

2023年3月4日 23:53
526
1