"Java Interview" MyBatis article __java

Source: Internet
Author: User
"Java Interview" MyBatis ChapterWhat is the 1.MyBatis programming step? ① Create Sqlsessionfactory
② Create sqlsession through Sqlsessionfactory
③ perform database operations through sqlsession
④ call Session.commit () COMMIT Transaction
⑤ call Session.close () Close session
2.XML mapping files, in addition to the common select|insert|updae|delete tags, what are the tags. <resultMap>, <parameterMap>, <sql>, <include>, <selectkey&gt, plus 9 tabs of dynamic SQL, trim|where| Set|foreach|if|choose|when|otherwise|bind, etc.

What is the difference between 3.#{} and ${}.

#{} is a precompiled process, ${} is a string replacement.
mybatis when processing #{}, the #{} in SQL is replaced with a number, and the PreparedStatement set method is called to assign the value;
MyBatis when processing ${}, is to replace ${} with the value of the variable.
using #{} can effectively prevent SQL injection and improve system security.
4.Mybatis is how the page is paginated. What is the principle of paging plug-ins.

MyBatis uses the Rowbounds object for paging, which is the memory paging performed for the resultset result set, not the physical paging, which can be written directly into the SQL with physical paging to complete the physical paging functionality, or you can use the paging plug-in to complete the physical paging.

The basic principle of paging plug-ins is to use the plug-in interface provided by MyBatis, implement custom Plug-ins, intercept the pending SQL within the blocking method of the plug-in, and then rewrite SQL, adding corresponding physical paging statements and physical paging parameters according to the dialect dialect.

5.Mybatis caching mechanism

MyBatis has a level two cache.

The first level cache is the sqlsession level cache, and his scope is the same sqlsession, executing the same SQL statement in the same sqlsession, which will write the result set to the cache and then fetch the data from the cache the second time;

The secondary cache is the mapper level cache, the scope is the same namespace of mapper, different sqlsession execute the same SQL statement under the same namespace, the results of the first query are cached, and the second time the data can be obtained from the cache.

MyBatis the first cache is turned on by default, the level two cache is not turned on, and the level two cache needs to be manually configured in the XML configuration to open.


Comparison between 6.Mybatis and hibernate

1.MyBatis can perform more granular SQL optimizations to reduce query fields.

2.MyBatis easy to master, while the hibernate threshold is higher.

3.Hibernate powerful, database independent of Good, O/R mapping ability, the need for less code, development speed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.