mybatis-plus和xml一起使用报错Invalid bound statement (not found)
时间: 2023-10-12 19:19:27 浏览: 54
这个错误一般是因为 Mybatis-Plus 无法找到指定的 mapper 文件,可以尝试以下几种方法:
1. 确认 `Mybatis-Plus` 的版本是否与 `mybatis` 版本兼容,可以查看 `Mybatis-Plus` 文档或者官方仓库的 `pom.xml` 文件。
2. 确认 `mapper` 文件的路径是否正确,可以在 `Mybatis-Plus` 的配置文件(一般是 `application.yml` 或者 `application.properties`)中添加以下配置:
```
mybatis-plus:
mapper-locations: classpath*:mapper/*.xml
```
其中 `classpath*:mapper/*.xml` 表示从 `classpath` 下的 `mapper` 目录中查找所有 `xml` 文件。
3. 确认 `mapper` 文件中的命名空间是否与 `mapper` 接口的全限定名一致,例如:
```
<!-- UserMapper.xml -->
<mapper namespace="com.example.mapper.UserMapper">
...
</mapper>
```
```
// UserMapper.java
package com.example.mapper;
public interface UserMapper {
...
}
```
如果命名空间不一致,可以手动指定 `mapper` 的位置和命名空间:
```
@Mapper
public interface UserMapper extends BaseMapper<User> {
@Override
@Select("classpath*:mapper/UserMapper.xml")
List<User> selectList(Wrapper<User> queryWrapper);
}
```
其中 `@Mapper` 注解是 `Mybatis-Plus` 提供的,表示这是一个 `mapper` 接口,`@Select` 注解中的 `classpath*:mapper/UserMapper.xml` 表示从 `classpath` 下的 `mapper` 目录中查找 `UserMapper.xml` 文件。