出現的Bug
如圖,我開始復制delete語句和參數到數據庫執行,刪除兩條數據,但是后臺執行確只刪除一條數據,當時表示一臉懵逼
分析原因
分析原因
如圖,正確的參數傳值應該是這樣的,聰明的同學,應該就知道哪里錯了
解決問題
解決問題
我就不貼開始的代碼了,直接貼解決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 ResponseEntityPCustomerVo> 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;istrarr.length;i++){
arr[i]=Integer.parseInt(strarr[i]);
}
pcustomerService.deletes(arr);
return new ResponseEntity>(HttpStatus.OK);
}
總結
以上所述是小編給大家介紹的mybatis mysql delete in操作只能刪除第一條數據,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
您可能感興趣的文章:- 解決mybatis一對多關聯查詢多條數據只顯示一條的問題
- 解決mybatis plus 分頁查詢有條數,total和pages都是零的問題
- Oracle結合Mybatis實現取表TOP 10條數據
- Mybatis查詢記錄條數的實例代碼
- Mybatis RowBounds 限制查詢條數的實現代碼
- Mybatis批量插入返回成功的數目實例