Mybatis mysql delete in operation can only delete the first data method

Mybatis mysql delete in operation can only delete the first data method

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

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

  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:
  • Solve the problem that mybatis only displays one piece of data in one-to-many association query
  • Solve the problem that mybatis plus paging query has a number of entries, total and pages are both zero
  • Oracle combined with Mybatis to achieve the top 10 data in the table
  • Mybatis example code for querying the number of records
  • Mybatis RowBounds implementation code to limit the number of queries
  • Mybatis batch insert returns the number of successful examples

<<:  Detailed explanation of two ways of Linux service management: service and systemctl

>>:  Vue project implements left swipe delete function (complete code)

Recommend

Upgrade Docker version of MySQL 5.7 to MySQL 8.0.13, data migration

Table of contents 1. Back up the old MySQL5.7 dat...

Ubuntu 20.04 connects to wifi (2 methods)

I recently installed Ubuntu 20.04 and found that ...

How to implement email alert in zabbix

Implemented according to the online tutorial. zab...

Why the disk space is not released after deleting data in MySQL

Table of contents Problem Description Solution Pr...

Concat() of combined fields in MySQL

Table of contents 1. Introduction 2. Main text 2....

Docker FAQ

Docker only maps ports to IPv6 but not to IPv4 St...

Linux editing start, stop and restart springboot jar package script example

Preface In the springboot configuration file, the...

About 3 common packages of rem adaptation

Preface I wrote an article about rem adaptation b...

Five guidelines to help you write maintainable CSS code

1. Add a comment block at the beginning of the sty...

In-depth understanding of the role of Vuex

Table of contents Overview How to share data betw...

Vue+echart realizes double column chart

This article shares the specific code of vue+echa...

How to use Nginx to solve front-end cross-domain problems

Preface When developing static pages, such as Vue...

Detailed steps for installing, configuring and uninstalling QT5 in Ubuntu 14.04

1. I downloaded QT5.13 version before, but after ...