异常
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'seckillId' not found. Available parameters are [1, 0, param1, param2]
分析
异常的大概意思就是,mapper方法的参数绑定异常,然后看看我的mapper.xml和mapper.java文件:
SuccessKilled queryByIdWithSeckill(long seckillId, long userPhone);
<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语句的传入参数完成映射