mybatis mysql delete in操作只能刪除第一條數(shù)據(jù)的方法
出現(xiàn)的Bug
如圖,我開始復(fù)制delete語句和參數(shù)到數(shù)據(jù)庫執(zhí)行,刪除兩條數(shù)據(jù),但是后臺執(zhí)行確只刪除一條數(shù)據(jù),當(dāng)時(shí)表示一臉懵逼
分析原因
分析原因
如圖,正確的參數(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,去掉最后一個(gè)“,”
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ù),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- Mysql數(shù)據(jù)庫如何使用DELETE語句從數(shù)據(jù)庫表中刪除數(shù)據(jù)(數(shù)據(jù)庫數(shù)據(jù)刪除)
- mysql正確刪除數(shù)據(jù)的方法(drop,delete,truncate)
- Mysql數(shù)據(jù)庫delete操作沒報(bào)錯卻刪除不了數(shù)據(jù)的解決
- MySQL delete刪除數(shù)據(jù)后釋放磁盤空間的操作方法
- mysql之delete刪除記錄后數(shù)據(jù)庫大小不變
- MySQL防止delete命令刪除數(shù)據(jù)的兩種方法
- MySQL的DELETE刪除數(shù)據(jù)示例詳解
相關(guān)文章
sql腳本函數(shù)編寫postgresql數(shù)據(jù)庫實(shí)現(xiàn)解析
這篇文章主要介紹了sql腳本函數(shù)編寫postgresql數(shù)據(jù)庫實(shí)現(xiàn)解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
Mybatis報(bào)錯: org.apache.ibatis.exceptions.PersistenceException
這篇文章主要介紹了Mybatis報(bào)錯: org.apache.ibatis.exceptions.PersistenceException解決辦法的相關(guān)資料,需要的朋友可以參考下2016-12-12
MySQL數(shù)據(jù)庫主從復(fù)制與讀寫分離
大家好,本篇文章主要講的是MySQL數(shù)據(jù)庫主從復(fù)制與讀寫分離,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12

