Bugs As shown in the figure, I started to copy the delete statement and parameters to the database to execute and delete two data, but the background execution only deleted one data. I was confused at the time.
Analyze the causes As shown in the figure, the correct parameter value should be like this. Smart students should know what is wrong Solving the problem I won't post the initial code, I will directly post the code to solve the bug Code in mybatis <!-- Batch Delete --> <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> Code in controller /** * Delete and bulk delete */ @RequestMapping(value = "/del", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity<PCustomerVo> delete(@RequestParam String customerId) throws Exception { //Get the IDs for batch deletion and remove the last "," 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(str[i]); } pcustomerService.deletes(arr); return new ResponseEntity<>(HttpStatus.OK); } Summarize The above is what I introduced to you. The mybatis mysql delete in operation can only delete the first data. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Detailed explanation of two ways of Linux service management: service and systemctl
>>: Vue project implements left swipe delete function (complete code)
Table of contents 1 View the current database con...
Today I encountered a problem when I used Dockerf...
Table of contents 1. First look at COUNT 2. The d...
# contains a location information. The default anc...
Container lifecycle The life cycle of a container...
How to implement Mysql switching data storage dir...
Table of contents Container Hierarchy The process...
MySQL Users and Privileges In MySQL, there is a d...
1. Basic structure: Copy code The code is as follo...
At the beginning, I felt sad. The screenshots are...
A mysql-like php switch case statement. select xx...
The GROUP BY statement is used in conjunction wit...
I have been relearning HTML recently, which can be...
Preface: I recently encountered the problem of in...
Table of contents Preface: 1. Create a project wi...