Mybatis异常 Parameter "..." not found

异常内容:

Cause: org.apache.ibatis.binding.BindingException: Parameter 'title' not found. 
Available parameters are [1, 0, param1, param2]  
  • 异常发生描述:
    在整合SpringMVC & Mybatis开发时,系统结构大致分为Controller层、Mapper层、PO层和Service层;在Service调用Mapper的 Update 时,出现了问题。
  • com.wqt.ssm.Service.StudentService (interface)
void updateStudent(Integer id,Student student)throws Exception;
  • com.wqt.ssm.Mapper.StudentMapper (interface)
void updateStudent(Integer id,Student student)throws Exception;
  • com.wqt.ssm.Mapper.StudentMapper.xml
<update id="updateStudent" parameterType="com.wqt.ssm.PO.Student">
    update student set Name=#{name},Sex=#{sex}... where id=#{id}
</update>
  • 分析:
    注意Mapper.xml中update的parameterType,参数类型表明是PO类,但是在Mapper中的方法updateStudent形参却存在其他形参”Integer id”,所以在传递参数类型时,Mybatis的binding组件无法正确匹配参数类型,从而导致出现上面的异常。

  • 解决:
    传递的Integer id主要是在Service层中用于一些数据处理,如验证等等;连带着放进了Mapper中导致了问题的出现,则将Mapper对应方法中的其他形参去掉即可,Service的形参则按需求决定是否要保留。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值