springboot设置dao层/mapper接口扫描路径

方式一:在所有mapper接口使用@Mapper注解

@Mapper
public interface UserMapper {
    UserInfo getUserById(@Param("userId") String userId);
}

方式二:在springboot配置类或启动类使用@MapperScan注解
(作用:将指定包中的所有接口都标注为DAO层接口,相当于在每一个接口上写@Mapper)

@Configuration
@MapperScan(basePackages = "com.longfor.dao")
public class ApplicationConfig {

}

方式三:在springboot配置类或启动类使用@ComponentScan注解
(作用:扫描指定包中的所有接口,相当于在每一个接口上写@Service或@Component或@Repository或@Controller)

@ComponentScan
@MapperScan(basePackages = "com.longfor.dao")
 public class ApplicationConfig {
    
 }

猜你喜欢

转载自blog.csdn.net/qq_39387856/article/details/85159990
今日推荐