mybatis: nested exception is org.apache.ibatis.binding.BindingException:

免责声明:转载仅仅因为解决了我的问题,如果对你无效,麻烦出门右拐别瞎在评论里怨天尤人。

异常
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'seckillId' not found. Available parameters are [1, 0, param1, param2]
1
分析
异常的大概意思就是,mapper方法的参数绑定异常,然后看看我的mapper.xml和mapper.java文件:

SuccessKilled queryByIdWithSeckill(long seckillId, long userPhone);
1
 <insert id="insertSuccessKilled">
        INSERT ignore INTO success_killed(seckill_id,user_phone,state)
        VALUES (#{seckillId},#{userPhone},0)
    </insert>

这个异常的产生原因是因为,当mapper接口方法有多个参数时,java不会保存行参的记录,java在运行的时候会把方法中的参数(long seckillId, long userPhone)变成这样:(int arg0,int arg1),这样我们就没有办法去传递多个参数(注意,在多个参数时才会发生)

解决
需要在mapper接口中指定参数名称:

SuccessKilled queryByIdWithSeckill(@Param("seckillId")long seckillId, @Param("userPhone") long userPhone);

这样才能使我们的MyBatis识别offset和limit两个参数,将Dao层方法中的这两个参数与xml映射文件中sql语句的传入参数完成映射

点赞 5
————————————————
版权声明:本文为CSDN博主「JeffCoding」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/jeffleo/article/details/55803548

猜你喜欢

转载自blog.csdn.net/muyimo/article/details/105573716