springboot整合mybatis的时候,要扫描dao接口创建dao对象,一般都是在接口上加@mapper注解
@Mapper
public interface StudentMapper {
……
}
一般一个接口加一个@Mapper,如果有很多接口,每一个都加@Mapper注解非常麻烦呢,所以有了@MapperScan注解的使用
@MapperScan注解需要加在springboot启动类上,指定dao所在的包名,就可以扫描对应包下的接口创建对象,就不用一个dao一个dao的加mapper啦
@MapperScan(basePackages = "com.example.springbootfirst.mapper")
public class SpringbootFirstApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootFirstApplication.class, args);
}
}
---------------------------------
其他springboot相关知识看专栏其他内容