项目场景:
项目在整合mybatis-plus的时候发现总是报错,mybatis的xml文件中的sql使用正常,而mybatis-plus的接口持续报错
问题描述
postman测试使用mybatis-plus的接口总是报错,报错信息如下:
org.apache.ibatis.binding.BindingException:Invalid bound statement (not found): com.demo.mapper.ArticleMapper.selectList
代码片段如下:
@GetMapping("/getAll")
public Result<List<Article>> getAllArticles() {
List<Article> articleList = articleService.list();
return Result.success(articleList);
}
刚遇到这个问题我第一眼就看见了selectList()
,但是整个项目中都没有使用过selectList()
,后来在网上找了一大堆相关的解决方案都不生效
原因分析:
- 这种报错常见的原因就是
target
的mapper
文件夹中xml文件不在,但是检查了一遍没问题 - 试过更换mybatis-plus的版本,但是仍然不能起作用,没想过再去更换mybatis的版本
- controller,service,mapper,pojo每一个相关的类上检查格式都正确
- application.yml,还有各个配置类中 检查没有影响mybatis-plus生效的配置项
一筹莫展后,试了一下更换mybatis项目的依赖
之前:
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
之后:
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
运行项目,问题解决
发现了原因:mybatis-plus与mybatis的版本不兼容的问题
现在mybatis-plus的依赖如下:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3</version>
</dependency>
解决方案:
参考文章:
解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):xxx问题
如果无法解决,可再检查mybatis-plus和mybatis的兼容性