MyBatis Implement bulk Delete operations

Source: Internet
Author: User

one of the main considerations here is the two types of parameters: arrays or collections.

And this difference mainly manifests in the Empmapper.xml file the Label collection attribute : When collection= "array", the table name parameter is an array; When collection= "list", the table name parameter is a collection.

two. Note:

Whether MyBatis is in combination with MySQL databases or with Oracle databases, the following settings and operations are also appropriate.

three. The specific examples are as follows:

Empmapper.xml:

    <!--Bulk Delete employee information-->
    <delete id= "batchdeleteemps" parametertype= "int" >
        delete from emp where empno in< C10/><foreach item= "Empnoitem" collection= "Array" open= "(" separator= "," close= ")" >
            #{empnoitem}
        </foreach>
    </delete>
<!--parameter description-->
<!-- 
    emp   : Table name
    empno: Field Name
    collection: represents type, where the argument is an array, and if it is a collection, Write list
    item  : is a variable name, oneself casually name

-->

Empmapper.java:

    
     * * Bulk Delete Employee information * *
    void Batchdeleteemps (int[] empno);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.