写Mybatis时报错Mapped Statements collection does not contain value for com.i...

### 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

下面是项目结构

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值