Home > Common Problem > body text

The basic working principle of mybatis

Release: 2020-03-16 09:58:07
Original
11803 people have browsed it

The basic working principle of mybatis

The working principle of MyBatis

Before learning the MyBatis program, readers need to understand the working principle of MyBatis in order to understand the program.

The working principle is as follows:

The basic working principle of mybatis

Introduction to the working principle:

1) Read the MyBatis configuration file: mybatis-config.xml is The global configuration file of MyBatis configures the running environment of MyBatis and other information, such as database connection information.

2) Load the mapping file. The mapping file is the SQL mapping file. The SQL statements for operating the database are configured in this file and need to be loaded in the MyBatis configuration file mybatis-config.xml. The mybatis-config.xml file can load multiple mapping files, each file corresponding to a table in the database.

3) Construct a session factory: Construct a session factory SqlSessionFactory through MyBatis environment and other configuration information.

4) Create session object: The SqlSession object is created by the session factory, which contains all methods for executing SQL statements.

5) Executor executor: The bottom layer of MyBatis defines an Executor interface to operate the database. It will dynamically generate SQL statements that need to be executed based on the parameters passed by SqlSession, and is also responsible for the maintenance of the query cache.

6) MappedStatement object: There is a MappedStatement type parameter in the execution method of the Executor interface. This parameter is an encapsulation of mapping information and is used to store the id, parameters and other information of the SQL statement to be mapped.

7) Input parameter mapping: Input parameter types can be collection types such as Map and List, or basic data types and POJO types. The input parameter mapping process is similar to the JDBC process of setting parameters on a preparedStatement object.

8) Output result mapping: The output result type can be collection types such as Map and List, or basic data types and POJO types. The output result mapping process is similar to the JDBC result set parsing process.

The above is the detailed content of The basic working principle of mybatis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!