In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the operation principle and query implementation of mybatis". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the operation principle and query implementation of mybatis".
The mybatis interface is programmed and implemented dynamically using jdk.
1. No matter which method the proxy object executes, it executes the invoke method of mapperProxy to determine whether the method of the current executor is a method of the Object class, because part of the method of the proxy object is implemented from the interface that needs to be proxied, and the other part is the methods in Object, such as equals, toString and so on.
two。 Then the Method is wrapped into a MapperMethod object, which contains two objects, sqlCommand and MegthodSignature. SqlCommand (initially, the Configuration is passed into the object, the Class object of the interface is initialized by Method, and the splicing statementId is obtained by calling its own resolveMappedStatement method, that is, the full path name of the interface + method name, and the Configuration.getMappedStatement method is called to obtain the MappedStatement object. The object maintains the encapsulation of a node. Here, we can see the effect of passing these three parameters into sqlCommand initialization. MegthodSignature stores the details of the current method to be called.
3.MapperMethod calls the execute method to pass in sqlsession and method parameters, and first determines the type of the current statement through sqlCommand. Here we first talk about the situation where the query returns the object. Mybatis will use the MegthodSignature object to determine the number and type of entries and types returned by the current method to execute the corresponding method. First call convertArgsToSqlCommandParam to parse the currently executed method parameters, and then call the method of defaultSqlSession.selectOne (command.getName (), param). The value of command.getName () here is statementId, that is, the namespace we developed and configured plus the id of the corresponding statement.
Here we analyze the selectList method. The screenshot is as follows:
The first step is to get the MappedStatement object from configuration through statement, which is actually the statementId we just mentioned. MappedStatement wraps the sql statement corresponding to the current running method and its type. Then call executor.query (ms, wrapCollection (parameter), rowBounds, Executor.NO_RESULT_HANDLER)
The next layer wraps the parameters of the execution method, the logical paging object, and the MappedStatement object. Pass it into the method and call the query method in the CachingExecutor executor to determine whether the cache is currently configured. There is no cache to call the query method in SimpleExecutor by default. Move on to the simpleExecutor.query method, which first queries the current interface to be queried from the local cache, that is, the first-level cache. Mybatis generates a cache key to uniquely determine whether the current query is consistent with the previous query, which is taken from the cache. (at this point, we can find that mybatis will check the second-level cache first and then the first-level cache).
Enter the doQuery method and declare the Statement object of the native jdbc. Get the global configuration information Configuration,new a StatementHandler pair, that is, one of the four major objects of mybatis.
The prepareStatement method mainly gets the connection, that is, the database connection object. Finally, the underlying data query is called, and the query interface is given to ResultSetHandler for encapsulation.
Thank you for your reading, the above is the content of "the operation principle and query implementation of mybatis". After the study of this article, I believe you have a deeper understanding of the operation principle and query implementation of mybatis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.