欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-07 19:28:48
错误提示:org.apache.ibatis.exceptions.PersistenceException:Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.itheima.mapper.UserMapper.findAllUserCaused by: java.lang.IllegalArgu...

错误提示:

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>元素下使用包名引入错误

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

本文地址:https://blog.csdn.net/qq_44230700/article/details/109258783