1. 声明Mapper接口

package com.hundsun.one.mapper;

@Repository
public interface ResultUserRoleMapper extends BaseMapper {

    /**
     * 分页查询
     * @param page
     * @return
     */
    Page pageUsers(@Param("page") Page page);
}

2. 创建Mapper配置文件


3. 启动类上扫描Mapper包

@EnableSwagger2
@SpringBootApplication
@MapperScan("com.hundsun.one.mapper")
public class OneApplication {

    public static void main(String[] args) {
        SpringApplication.run(OneApplication.class, args);
    }
}

4. 运行项目,访问接口,结果报错

// 报错原因:找不到mapper接口下的pageUsers接口方法

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.hundsun.one.mapper.ResultUserRoleMapper.pageUsers

5. 排查问题

-- 检查了启动类上的注解@mapperscan,发现包扫描路径是对的

-- 检查了xml配置文件,命名空间配置的接口路径也是对的

-- 检查了方法标签的 方法id也是对的

-- 排查以上几个都没有问题,那就是xml配置文件的路径问题

-- 尝试了几种办法,将xml配置文件放到接口所在的包下,将xml文件放到resource目录下,将xml文件方法resource目录下,路径配置的跟接口所在的全限定包名路径一样
                
-- 都没有解决问题

-- 在网上搜索了很多方案,都没有解决

6. 在Mybatis Plus官网找到了解决方案

Spring Boot配置自定义mapper.xml文件

7. 将mapper.xml配置文件放到resource目录下,在applicaton.yml或者applicaton.yaml或者applicaton.properties文件配置路径

-- 配置mapper.xml文件
mybatis-plus.mapper-locations=classpath:*.xml

 8. mapper自定义接口找不到的问题解决了,正常访问数据库

相关文章:

  • 2021-11-16
  • 2021-08-07
  • 2021-10-14
  • 2021-03-02
  • 2021-05-29
  • 2022-12-23
  • 2021-12-13
  • 2021-06-24
猜你喜欢
  • 2021-11-23
  • 2021-07-29
  • 2021-09-22
  • 2021-11-23
  • 2021-11-14
  • 2021-05-17
相关资源
相似解决方案