### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.itheima.mapper.CustomerMapper.findCustomerByNameAndJobs
新手学习中,批评指正。
这个错,
1,可能是因为xxMapper.xml文件中命名空间namespace的内容写错了,需要好好检查一下。
2,也可能是因为xxMapper.xml文件中 <select id=idName" 的id idName与调用时写的
session.selectOne("idname");不一样,需要好好检查一下。
注意
<mapper namespace="com.xxx.xxx.xxxMapper.xml">是不对的,不加xml
<mapper namespace="com.xxx.xxx.xxxMapper">才对
可以试试把原调用语句改写成只有SQL语句id的形式,如
int rows = sqlSession.update("com.itheima.mapper.CustomerMapper.updateCustomerBySet", customer);
---->int rows = sqlSession.update("updateCustomerBySet",customer);
int rows = sqlSession.update("com.itheima.mapper.CustomerMapper.updateCustomerBySet",customer);
//改成
int rows = sqlSession.update("updateCustomerBySet",customer);
如果成功运行则更加一步,可能是mapper.xml中namespace写错了,
比如comxxx.xxx.UsersMapper误写成了comxxx.xxx.useMapper
对于namespace里的内容,当Mapper.xml的位置放在resources资源文件下时,调用SQL直接写SQL语句的id,不用加路径。
List<Customer> customers = session.selectList("findCustomerByNameAndJobs",customer);
List<Customer> customers = session.selectList("findCustomerByNameAndJobs",customer);
而且namespace里面随便写。
而把mapper文件放在java下面时就要写对namespace
下面是项目结构