Interview questions-11Mybatis

What are the MyBatis programming steps?

1. Create SqlSessionFactory
2. Create SqlSession through SqlSessionFactory
3. Perform database operations through sqlsession
4. Call session.commit() to submit the transaction
5. Call session.close() to close the session

$The difference between #{} and {}

#{} is a placeholder, pre-compilation processing; ${} is a splicing character, string replacement, no pre-compilation processing.

Cache

Mybatis's first level cache:
HashMap local cache based on PerpetualCache, its storage scope is
Session. After Session flush or close, all Caches in the Session will be emptied, and the first level cache is turned on by default.
2) The mechanism of the second-level cache is the same as that of the first-level cache. By default, PerpetualCache and HashMap are used for storage. The difference is that the storage scope is
Mapper (Namespace), and the storage source can be customized, such as
Ehcache. The second-level cache is not turned on by default. To enable the second-level cache, the use of the second-level cache attribute class needs to implement the Serializable serialization interface (which can be used to save the state of the object), which can be configured in its mapping file <cache/>
;
3) For the cache data update mechanism , When the C/U/D operation is performed in a certain scope (first-level cache Session/second-level cache Namespaces), all caches in select under this scope will be cleared by default.

Guess you like

Origin blog.csdn.net/zyf_fly66/article/details/114083051