In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article "how to choose the corresponding SQL statement according to the database type in mybatis mapper.xml", the sample code in this article is very detailed and has certain reference value. Interested friends must refer to "how to choose the corresponding SQL statement according to the database type in mybatis mapper.xml". The editor has sorted out the following knowledge points, please follow the pace of the editor to understand step by step. Next, let's get to the subject.
Mapper.xml selects the corresponding SQL statement 1 according to the database type. Configure db2 oracle mysql in the spring-database.xml file.
For the configuration of sessionFactory, the main statement is red must have, others in accordance with their own original configuration.
HelperDialect=oracle reasonable=true supportMethodsArguments=true params=count=countSql autoRuntimeDialect=true 2. Configure select * from SM_USERS_TB select * from SM_USERS_TB in the mapper.xml file
If databaseId = "mysql" is written, the SQL statement is executed automatically when the data source is of mysql type. If the databaseId is not written and the SQL statement of the same ID exists at the same time, the SQL statement will be called as long as it is a data source of a non-mysql database.
Mapper.xml dynamic SQL statement usage
The main elements used to implement dynamic SQL are
If
Used to determine the example
Update smbms_user userCode=# {userCode}, userName=# {userName} UserPassword=# {userPassword}, gender=# {gender} Phone=# {phone}, address=# {address} UserRole=# {userRole}, createdBy=# {createdBy}, where id=# {id} trim
The trim attribute prefix suffix prefixOverrides suffixOverrides provides more flexibility in removing redundant keywords instead of where and set
If+trim uses if+trim instead of if+set to update user table data, and the effect is as follows:
Update smbms_user userCode = # {userCode}, userCode = # {userName}, userPassword=# {userPassword}
Where:
Prefix indicates that if an if is established, insert a where statement.
Suffix stands for suffix and is inserted at the end, just the opposite of perfix
SuffixOverrides= "xxx" means that if the final generated sql statement has one more xxx, it will be removed automatically.
PrefixOverrides means to remove the prefix, which is the opposite of the use of suffixOverrides
Here, if any of the conditions is true, the element inserts WHERE and removes the (and or or) immediately after where.
Where SELECT u.roleCode FROM smbms_user u INNER JOIN smbms_role r ON u.userrole=r.id AND userCode LIKE CONCAT ('%', # {usercode}) '%') AND userRole=# {userrole} AND gender=# {gender} set Update smbms_user userCode=# {userCode} UserName=# {userName}, userPassword=# {userPassword} Gender=# {gender}, phone=# {phone} Address=# {address}, userRole=# {userRole} CreatedBy=# {createdBy}, where id=# {id} choose (when, otherwise)
It is equivalent to the switch statement in Java. When the condition of when is satisfied, it jumps out of choose.
... ... ... ... ... Foreach
Iterate over a collection, usually used for the in conditional attribute item index collection: list array map-key open separator close must be specified
Select * from smbms_user where userCode in # {userCode} above are all the contents of the article "how to choose the corresponding SQL statement according to the database type in mybatis mapper.xml". 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.