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

