MyBatis is a semi-automatic lightweight ORM framework that helps eliminate almost all of the JDBC coding, parameter setting, and fetching results in a project.

At the heart of every MyBatis application is an instance of SqlSessionFactory, which can be obtained from SqlSessionFactoryBuilder. The SqlSessionFactoryBuilder generates the DefaultSqlSessionFactory by loading an XML Configuration file or pre-setting the Configuration. The XML Configuration file is parsed by XMLConfigBuilder into a Configuration object. There are two more basic tags in the XML configuration schema, environment in Environments and Mapper in Mappers. MyBatis, as an ORM framework, helps us reduce the coding of JDBC, which requires connecting to the database. TransactionManager and datasource can be configured in the environment. Mapper is a database table interface defined by namespace mapping. Methods in the interface are associated with MappedStatement. StatementId is the name of the method.

With the SqlSessionFactory created, we can create sqlSessions from the factory. SqlSessionFactory provides can get DefaultSqlSession openSessionFromDataSource method from the data source, You can call MappedStatement by passing in statementId and parameters. You can also get the mapped interface proxy class by passing in getMapper. The proxy class dynamically implements the methods defined in the interface using JDK. The logic of the implementation is based on the input parameters defined in the interface map, the return result and the SQL statement of the mapping. The parameter setting and the return result encapsulation function are realized by calling THE JDBC encoding. The implementation of MyBatis involves four core components, namely Executor, StatementHandler, ParameterHandler, ResultSetHandler.