In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to implement the batch operation of Mybatis, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
How to perform batch operations in Mybatis
Use foreach tags
Foreach is mainly used in building in conditions, which can iterate over a collection in a SQL statement. The main attribute of the foreach tag is item,index,collection,open,separator,close.
Item represents the alias of each element in the collection when iterating, a random variable name.
Index specifies a name that indicates the location of each iteration during the iteration, which is not commonly used
Open indicates what the statement begins with, and "(" is commonly used.
Separator indicates what symbol is used as a separator between each iteration. It is commonly used as ","
Close denotes what it ends with. It is often used as ")".
The most critical and error-prone attribute when using foreach is the collection attribute, which must be specified, but the value of this attribute is different in different cases. There are three main cases:
If a single parameter is passed and the parameter type is a List, the value of the collection attribute is list
If a single parameter is passed and the parameter type is an array array, the property value of collection is array
If multiple parameters are passed, we need to encapsulate them into a Map. Of course, a single parameter can also be encapsulated as a map. In fact, if you pass a parameter, it will also be encapsulated as a Map in the MyBatis.
The key of map is the parameter name, so the value of the collection attribute is the key of the passed List or array object in the map encapsulated by itself.
The specific usage is as follows:
/ / INSERT INTO emp (ename,gender,email,did) VALUES (# {emp.eName}, # {emp.gender}, # {emp.email}, # {emp.dept.id}) INSERT INTO emp (ename,gender,email,did) VALUES (# {emp.eName}, # {emp.gender}, # {emp.email}) is recommended # {emp.dept.id}) these are all the contents of the article "how does Mybatis perform batch operations" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.