mybatis mysql delete in操作只能刪除第一條數(shù)據(jù)的方法
出現(xiàn)的Bug
如圖,我開(kāi)始復(fù)制delete語(yǔ)句和參數(shù)到數(shù)據(jù)庫(kù)執(zhí)行,刪除兩條數(shù)據(jù),但是后臺(tái)執(zhí)行確只刪除一條數(shù)據(jù),當(dāng)時(shí)表示一臉懵逼
分析原因
分析原因
如圖,正確的參數(shù)傳值應(yīng)該是這樣的,聰明的同學(xué),應(yīng)該就知道哪里錯(cuò)了
解決問(wèn)題
解決問(wèn)題
我就不貼開(kāi)始的代碼了,直接貼解決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ù),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Mysql數(shù)據(jù)庫(kù)如何使用DELETE語(yǔ)句從數(shù)據(jù)庫(kù)表中刪除數(shù)據(jù)(數(shù)據(jù)庫(kù)數(shù)據(jù)刪除)
- mysql正確刪除數(shù)據(jù)的方法(drop,delete,truncate)
- Mysql數(shù)據(jù)庫(kù)delete操作沒(méi)報(bào)錯(cuò)卻刪除不了數(shù)據(jù)的解決
- MySQL delete刪除數(shù)據(jù)后釋放磁盤(pán)空間的操作方法
- mysql之delete刪除記錄后數(shù)據(jù)庫(kù)大小不變
- MySQL防止delete命令刪除數(shù)據(jù)的兩種方法
- MySQL的DELETE刪除數(shù)據(jù)示例詳解
相關(guān)文章
mysql數(shù)據(jù)庫(kù)單表最大存儲(chǔ)依據(jù)詳解
這篇文章主要為大家介紹了mysql數(shù)據(jù)庫(kù)單表最大存儲(chǔ)的依據(jù)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
MySQL百萬(wàn)級(jí)數(shù)據(jù)分頁(yè)查詢優(yōu)化方案
在mysql中l(wèi)imit可以實(shí)現(xiàn)快速分頁(yè),但是如果數(shù)據(jù)到了幾百萬(wàn)時(shí)我們的limit必須優(yōu)化才能有效的合理的實(shí)現(xiàn)分頁(yè)了,否則可能卡死你的服務(wù)器哦。2017-11-11
mysql中一個(gè)普通ERROR 1135 (HY000)錯(cuò)誤引發(fā)的血案
ERROR 1135 (HY000): Can’t create a new thread (errno 11);if you are not out of available memory,you can consult the manual for a possible OS-dependent bug2015-08-08
mysql max 與 where 間的執(zhí)行問(wèn)題小結(jié)
這篇文章主要介紹了mysql max 與 where 間的執(zhí)行問(wèn)題小結(jié),需要的朋友可以參考下2018-01-01
SQL數(shù)據(jù)分表Mybatis?Plus動(dòng)態(tài)表名優(yōu)方案
這篇文章主要介紹了SQL數(shù)據(jù)分表Mybatis?Plus動(dòng)態(tài)表名優(yōu)方案,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08
mysql之validate_password_policy的使用
這篇文章主要介紹了mysql之validate_password_policy的使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05
MySQL三大日志(binlog、redo?log和undo?log)圖文詳解
日志是MySQL數(shù)據(jù)庫(kù)的重要組成部分,記錄著數(shù)據(jù)庫(kù)運(yùn)行期間各種狀態(tài)信息,下面這篇文章主要給大家介紹了關(guān)于MySQL三大日志(binlog、redo?log和undo?log)的相關(guān)資料,需要的朋友可以參考下2023-01-01

