Mybatis异常 Parameter "..." not found

来源:互联网 发布:淘宝店铺产品布局 编辑:程序博客网 时间:2024/05/16 06:44

异常内容:

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
原创粉丝点击