Mybatis异常 Parameter "..." not found

本文分析了在SpringMVC&Mybatis开发中遇到的BindingException,并提供了有效的解决方案。问题出现在Service调用Mapper的更新方法时,由于Mapper.xml文件中的参数类型与方法签名不匹配导致。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

异常内容:

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的形参则按需求决定是否要保留。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值