MyBatis 异常:Invalid bound statement (not found) - 如何解决 "com.example.demo1.mapper.StudentMapper.selectList" 找不到映射语句
这个异常是 MyBatis 在执行 SQL 语句时,找不到对应的映射语句(Mapped Statement)。具体来说,是找不到 'com.example.demo1.mapper.StudentMapper.selectList' 这个映射语句。
可能的原因有:
-
映射文件(Mapper XML)中没有定义这个映射语句。
-
映射文件没有被正确加载或配置,导致 MyBatis 找不到映射语句。
-
映射语句的名称或命名空间不正确。
解决方法:
-
检查映射文件是否包含名为 'com.example.demo1.mapper.StudentMapper.selectList' 的映射语句。
-
检查 MyBatis 的配置文件是否正确,是否正确加载了映射文件。
-
检查映射语句的名称和命名空间是否正确。可以在代码中检查这个问题,例如:
List<Student> studentList = sqlSession.selectList('com.example.demo1.mapper.StudentMapper.selectList');如果这里的参数不正确,也会抛出类似的异常。
-
如果以上方法都没有解决问题,可以尝试重新构建项目,重新生成 Mapper 接口和 XML 文件。
原文地址: https://www.cveoy.top/t/topic/lB7z 著作权归作者所有。请勿转载和采集!