Mapper注解与MapperScan注解

1.Mapper注解

在接口类上添加@Mapper,在运行时动态代理生成实现类

@Mapper
public interface UserDao {
  // User getUser();
}

如果想要每个接口都要变成实现类,那么需要在每个接口上都添加@Mapper注解,比较麻烦,可以使用@MapperScan注解扫描

2.MapperScan注解

作用 : 指定要变成实现类的接口所在包,然后包下面的接口在在运行时动态代理生成实现类

@SpringBootApplication
@MapperScan("com.winter.dao")
public class SpringbootMybatisDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootMybatisDemoApplication.class, args);
    }
}
posted @ 2021-06-01 15:22  SpecialSpeculator  阅读(564)  评论(0编辑  收藏  举报