错误提示:

org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.itheima.mapper.CustomerMapper.findAllCustomers

Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.itheima.mapper.CustomerMapper.findAllCustomers

图片:
Mybatis中<mappers>元素下使用包名引入错误

解决方案:
为com.itheima.mapper包下的xml文件创建一个对应的接口即可(且名字与xml名字相同)
如图:
Mybatis中<mappers>元素下使用包名引入错误



接口里面的内容应该与xml文件中的内容相对应才行,比如以这个方法为例:
xml文件中有这样一个方法,则接口文件中的方法的返回值类型和参数也应该是与它相统一的
Mybatis中<mappers>元素下使用包名引入错误


这里xml的传入参数为空,返回值是customer类型的,对应到接口:
Mybatis中<mappers>元素下使用包名引入错误


最后看一下测试类:
Mybatis中<mappers>元素下使用包名引入错误


运行成功!
Mybatis中<mappers>元素下使用包名引入错误

前路漫漫,道阻且长,行则将至,做则必成

相关文章: