mybatis mysql delete in操作只能刪除第一條數(shù)據(jù)的方法
出現(xiàn)的Bug
如圖,我開始復(fù)制delete語句和參數(shù)到數(shù)據(jù)庫執(zhí)行,刪除兩條數(shù)據(jù),但是后臺執(zhí)行確只刪除一條數(shù)據(jù),當時表示一臉懵逼
分析原因
分析原因
如圖,正確的參數(shù)傳值應(yīng)該是這樣的,聰明的同學(xué),應(yīng)該就知道哪里錯了
解決問題
解決問題
我就不貼開始的代碼了,直接貼解決bug的代碼
mybatis中的代碼
<!-- 批量刪除-->
<delete id="deleteByIds" parameterType="int[]">
<![CDATA[
DELETE FROM p_customer
WHERE customerId in
]]>
<foreach collection="array" item="arr" index="no" open="("
separator="," close=")">
#{arr}
</foreach>
</delete>
controller中的代碼
/**
* 刪除和批量刪除
*/
@RequestMapping(value = "/del", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<PCustomerVo> delete(@RequestParam String customerId) throws Exception {
//獲取批量刪除的id,去掉最后一個“,”
customerId=customerId.substring(0,customerId.length()-1);
String[] strarr=customerId.split(",");
int[] arr=new int[strarr.length];
for(int i=0;i<strarr.length;i++){
arr[i]=Integer.parseInt(strarr[i]);
}
pcustomerService.deletes(arr);
return new ResponseEntity<>(HttpStatus.OK);
}
總結(jié)
以上所述是小編給大家介紹的mybatis mysql delete in操作只能刪除第一條數(shù)據(jù),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對本站網(wǎng)站的支持!
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信