Continue to create, accelerate growth! This is the 12th day of my participation in the "Nuggets Daily New Plan · June Update Challenge", click to view the details of the event
background
- Record the function modules of mybatis3 to help understand how mybatis works.
process
- Source module display
- annotations
Annotations, such as the commonly used @Select, @Insert, @Update, @Delete and many others. The usage is to use the knowledge of reflection to get the meta information of the class, and then analyze it step by step according to the defined rules. 2. Binding (a very important module) generates a corresponding mapper proxy class for the mapper interface, and can be obtained through statementId. Each mapper file has a corresponding mapper proxy class. MapperProxyFactory produces the MapperProxy corresponding to the Mapper interface file and puts it into the MapperRegistry as part of the configuration information, so that it can be obtained from the container through statementId. The statementId here is actually the namespace + id (method name) of the mapper.xml file. Among them, in MapperMethod The execute method is very core, all the upper-level entries for executing SQL. 3. The builder
builds the content of the xml file. Read the nodes in the xml file one by one and build them into java beans, which are convenient to obtain directly through the get method. 4. Cache cache, mybatis cache is stored in the map container, this module provides the calculation process of the cache key. 5. cursor cursor, pointer. A way to query a relational database. 6. datasource, database source, pooled data source and non-pooled data source. It just contains some basic information, such as username, password, url, driver, etc. 7. exeception, the exception handling class of mybatis. 8. executor, very core function
sql executor. The statement that interacts with the database, executes the parameter preparation before, and executes the result set processing afterwards. 9. io, resource function module, read files 10. jdbc, basic operation database, used for testing, in fact, other core source code does not use the classes under this package.
11. logging, log module 12. mapping , very core module
MappedStatement is a very important class. Contains a lot of metadata information. The mapper interface and the mapper.xml file will generate an instance MappedStatement 13. parsing, XPathParser, XNode, providing the basic class for parsing xml configuration files. 14. plugin, extends the function of mybatis. For example, paging query is to use the working principle of mybatis plug-in. 15. reflection, enriches the reflection function on the basis of jdk 16. scripting, will process tags in xml files and sql
17. session, core function package.
SqlSessionFactoryBuilder builds a SqlSessionFactory, and then builds a SqlSession instance from the SqlSessionFactory instance. Finally, the sqlSession instance interacts with the relational database. 18. transaction , relational database transaction management. The general use process is handed over to spring for transaction management.
transaction operation. submit. rollback. 19. When the type
interacts with the relational database, how does the parameter setting convert the java type to the jdbc type? When the result set of the relational database is obtained after executing SQL, how to convert the jdbc type to java type
summary
-
After reading the source code of mybatis and understanding its work project, deepen your familiarity and understanding of mybaits by recording.
-
Through the function modules recorded above, the working process of mybatis can be connected in series.
-
Be able to understand the work process, if there is a problem, be able to understand which specific link the problem occurs in, and assist in solving the problem quickly.