Invalid bound statement (not found): com.example.mapper.EmployeeMapper.selectAll
时间: 2025-07-06 20:57:33 浏览: 11
### MyBatis 中 `Invalid bound statement (not found)` 错误解决方案
当遇到 `Invalid bound statement (not found): com.XXX.mapper.EmployeeMapper.selectAll` 的错误时,通常意味着 MyBatis 无法定位到对应的 Mapper XML 文件中的 SQL 映射语句。以下是几种常见的排查方向:
#### 检查 XML 文件位置
确保 XML 配置文件位于正确的目录下,并且遵循项目结构。如果项目的包名为 `com.example.project.mapper`,那么相应的 XML 应该放置于资源目录下的相同路径中[^1]。
```plaintext
src/main/resources/
└── com/example/project/mapper/EmployeeMapper.xml
```
#### 校验命名空间与接口匹配度
确认 `EmployeeMapper.xml` 内部定义的 namespace 是否完全对应 Java 接口全限定名。例如对于 `com.example.project.mapper.EmployeeMapper` 接口而言,XML 命名空间应设置为相同的字符串值。
```xml
<mapper namespace="com.example.project.mapper.EmployeeMapper">
<!-- SQL statements here -->
</mapper>
```
#### 设置映射器扫描路径
为了使 Spring Boot 或其他框架能够自动发现并加载所有的 Mapper 资源文件,在应用程序属性配置文件 (`application.properties`) 中指定这些文件所在的位置是非常重要的[^2]。
```properties
mybatis.mapper-locations=classpath*:mapper/**/*.xml
```
或者如果是 YAML 格式的配置,则可以这样写[^3]:
```yaml
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.example.project.entity
```
#### 确认 IDE 已同步更新
有时即使修改了代码或资源配置之后仍然会碰到此类问题,这可能是由于开发环境未能及时反映最新的更改所引起的。尝试刷新 Maven/Gradle 构建工具以及重启应用服务器来排除这类潜在因素[^4]。
通过以上几个方面的核查应该可以帮助解决大多数情况下发生的 "Invalid bound statement (not found)" 类型的问题。
阅读全文
相关推荐




















