In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.