Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the method of bulk inserting statements into MySQL by Mybatisd?

Shulou Source: shulou.com Published: 2022-06-01 18:07:39 09月13日 Update

This article introduces the relevant knowledge of "what is the method of Mybatisd inserting sentences into MySQL in bulk?". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Batch insert

Insert into

T_student (name, age, class)

Values

(

# {item.name,jdbcType=VARCHAR}

# {item.age,jdbcType=INTEGER}

# {item.class,jdbcType=LONGVARCHAR}

)

2. Batch updates

Method 1:

Update t_studetn set

Name = # {stud.name}

Age = # {stud.age}

Class = # {stud.sex}

Where id = # {stud.id}

Method 2:

UPDATE t_student

SET name = CASE id

WHEN # {i.id} THEN # {i.name}

END

Age = CASE id

WHEN # {i.id} THEN # {i.age}

END

WHERE id IN

Id=# {i.id}

3. Batch deletion

Delete from

T_student

Where

Id IN

# {item}

The concrete object in the body of the item loop. Supports point path access to attributes, such as item.age,item.info.details.

Specific description: in list and array is one of the objects, in map is value.

This parameter is required. Collection

To do the foreach object, as the input parameter, the List object defaults to list instead of the key, the array object has array instead of the key, and the Map object has no default key.

Of course, you can use @ Param ("keyName") to set the key as an input parameter. After setting keyName, list,array will fail. In addition to the case of input parameters, there is also a time when a field is used as a parameter object. For example:

If User has an attribute List ids. If the input parameter is a User object, then this collection = "ids"

If User has an attribute Ids ids; where Ids is an object and Ids has an attribute List id; input parameter is a User object, then collection = "ids.id"

The above is just an example of what collection equals, depending on which element you want to loop.

This parameter is required.

Separators between separator elements, such as separator= "," are automatically separated by "," in the middle of the element when in (), to avoid sql errors caused by manually entering commas, such as in (1Magne2,). This parameter is optional. The opening symbol of openforeach code is usually used (with close= ")". Commonly used in in (), values (). This parameter is optional. The closing symbol for closeforeach code, usually) and open= "(" are used together. Commonly used in in (), values (). This parameter is optional. Index in list and array, index is the sequence number of the element, in map, index is the key of the element, this parameter is optional. This is the end of the content of "what is the method of Mybatisd inserting statements in bulk to MySQL". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Objects parameters elements attributes arrays methods statements code content commonly used situations ways times more knowledge symbols loops utility learning and then Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Xiaomi Docker Huawei Shulou Tech Info