In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about the introduction of mybatis, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
1.mybatis programming steps
Create a SqlSessionFactory object
Get sqlSession object through SqlSessionFactory
Get the proxy object of Mapper through sqlSession
Perform database operations through the proxy object of mapper
If the execution succeeds, the transaction is committed using sqlsession
If execution fails, sqlsession is used to roll back the transaction
Finally, close the session
2.The difference between {} and ${}
${} is a variable placeholder in the properties file, which can be used for xml tag attribute values and within sql, and belongs to string substitution.
${} can also splice the passed parameters in sql as is. In real-world scenarios, ${} is not recommended because of the risk of sql injection.
# {} is a parameter placeholder for sql, and mybatis replaces # {} in sql with? Number, the parameter setting method of PreparedStatement will be used before the execution of sql, and will be given to sql in sequence. Number placeholder setting parameters. So # {} is precompiled, which can effectively prevent sql injection and improve system security.
3. The attribute name of the entity class is different from the field name in the table, how to deal with it
The first is to make the alias of the field name consistent with the attributes of the entity class by defining the field alias in the sql statement of the query
Second: in most scenarios, the difference between the field name of the database and the attribute name of the entity class is mainly an underscore and a hump style. In this case, it can be directly configured as follows to realize the function of automatic underlining to hump.
The third is to map the one-to-one correspondence between the field name and the entity class attribute name.
In addition to the common select | insert | update | delete tags in 4.mybatis 's xml mapping file, what other tags are there?
Refer to mybatis Chinese documentation
Cache-caching configuration for a given namespace
Cache-ref references to other namespace cache configurations
ResultMap is used to describe how to load objects from a database result set
A reusable block of statements that sql can be referenced by other statements.
What are the dynamic sql of 5.mysql?
Refer to mybatis Chinese documentation
、 、 、
6. How to get the automatically generated primary key
There are different ways to get the automatically generated primary key in different databases. There are two ways to mysql. The code is as follows
/ / method 1, use the useGeneratedKeys + keyProperty attribute INSERT INTO user (name, pswd) VALUE (# {name}, # {pswd}) / / method 2, use the ``tag SELECT LAST_INSERT_ID () INSERT INTO user (name, pswd) VALUE (# {name}, # {pswd}) to read the above content, do you have any further understanding of mybatis related introduction? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.