異常的大概意思就是,mapper方法的參數(shù)綁定異常,然后看看我的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>這個(gè)異常的產(chǎn)生原因是因?yàn)椋?dāng)mapper接口方法有多個(gè)參數(shù)時(shí),java不會(huì)保存行參的記錄,java在運(yùn)行的時(shí)候會(huì)把方法中的參數(shù)(long seckillId, long userPhone)變成這樣:(int arg0,int arg1),這樣我們就沒有辦法去傳遞多個(gè)參數(shù)(注意,在多個(gè)參數(shù)時(shí)才會(huì)發(fā)生)
需要在mapper接口中指定參數(shù)名稱:
SuccessKilled queryByIdWithSeckill(@Param("seckillId")long seckillId, @Param("userPhone") long userPhone);這樣才能使我們的MyBatis識(shí)別offset和limit兩個(gè)參數(shù),將Dao層方法中的這兩個(gè)參數(shù)與xml映射文件中sql語(yǔ)句的傳入?yún)?shù)完成映射
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注