zoukankan      html  css  js  c++  java
  • SpringBoot注入Mapper失败

    SpringBoot注入Mapper失败,可能是因为没有加扫描Mapper层的注解

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

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

    方式二:在springboot配置类或启动类使用@MapperScan注解

    (作用:将指定包中的所有接口都标注为DAO层接口,相当于在每一个接口上写@Mapper)

    1 @Configuration
    2 @MapperScan(basePackages = "com.test.dao")
    3 public class ApplicationConfig {
    4 }

    方式三:在springboot配置类或启动类使用@ComponentScan注解

    (作用:扫描指定包中的所有接口,相当于在每一个接口上写@Service或@Component或@Repository或@Controller)

    1 @ComponentScan(basePackages = "com.test.dao")
    2  public class ApplicationConfig { 
    3  }
  • 相关阅读:
    MongoDB的简单操作
    MongoDB下载安装
    enctype="multipart/form-data" form表单提交值为null
    shiro
    json简单介绍
    Sql Server 安装
    MySQL面试常问的查询操作
    关于分页
    Vuex
    Vue基础安装(精华)
  • 原文地址:https://www.cnblogs.com/phyqxx/p/11636319.html
Copyright © 2011-2022 走看看