免责声明:转载仅仅因为解决了我的问题,如果对你无效,麻烦出门右拐别瞎在评论里怨天尤人。
转自:/jeffleo/article/details/55803548
一、异常
:
nested exception is :
Parameter 'seckillId' not found.
Available parameters are [1, 0, param1, param2]
二、分析
异常的大概意思就是,mapper方法的参数绑定异常,然后看看我的和文件:
SuccessKilled queryByIdWithSeckill(long seckillId, long userPhone);
<insert >
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语句的传入参数完成映射