创建com.wenpopo.mybatis.mapper.UserMapper.class文件后
在resources.wenpopo.mybatis.mapper文件夹下创建了UserMapper.xml映射文件,
但运行时就会报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.wenpopo.mybatis.mapper.StudentMapper.getStudentAndSuNoByStudentId错误,
意思为:MyBatis 在解析映射文件时找不到对应的 SQL 语句
我检查了以下两点问题:
-
检查一下映射文件中是否存在名为
getStudentAndSuNoByStudentId
的 SQL 语句(getStudentAndSuNoByStudentId是我要执行的mapper方法
) - 映射文件中 SQL 语句的 id 与注解中指定的不一致
发现都是没有问题的,最后我想起来在resources创建的不是软件包,而是目录,
这就意味着创建 wenpopo.mybatis.mapper文件夹时不能直接以wenpopo.mybatis.mapper命名,
要以wenpopo/mybatis/mapper命名,不然创建出来的只是一个名称为wenpopo.mybatis.mapper的文件夹,修改过后问题解决