Take you a brief understanding of MyBatis development steps

Introduction to MyBatis

MyBatis is used to simplify the interactive work between JDBC and MySQL or Oracle database. It
is a convenient tool for MyBatis.

What is MyBatis?

Let's take a look at what functions and responsibilities it has.

1. MyBatis is an excellent persistence layer framework. (There is a persistence layer: through the dao class combined with the MyBatis framework, we can quickly complete the operation of data addition, deletion, modification, and check.) The
so-called persistence refers to saving the data in memory to the database to prevent restarting. Data loss is called persistence.


2. Mybatis uses XML files to decouple SQL and programs for easy maintenance.
There is a typical feature: the SQL statements used in our applications are saved through files in this format of XML, which are maintained and managed separately as SQL, and our writing programs are provided through the methods provided by MyBatis. Complete the interactive work with the corresponding SQL. The biggest advantage of this is to effectively decouple our program and SQL statements. When the underlying SQL of a program changes, it is not necessary to change the Java source code, but only to open the XML file and modify the corresponding SQL text. Yes, it greatly facilitates the maintenance of our program.


3. MyBatis is simple to learn and efficient in execution. It is an extension of JDBC (you can get started quickly).
Note: The bottom layer of MyBatis is an extension of our jdbc (the technical core of the bottom layer is also our jdbc, but it is expanded and encapsulated on the basis of jdbc)

MyBatis Chinese document: (www.mybatis.org)

MyBatis development process

1. Introduce MyBatis dependency (by default, MyBatis recommends maven for component management by default)


2. Create a core configuration file (MyBatis is based on XML files for configuration management, so we have to create a core configuration file for MyBatis)


3. Create an Entity class


4. Create Mapper mapping file


5. Initialize SessionFactory (the core object of MyBatis: Session Factory). The
function is to read the configuration file, load the Mapper mapping, and also prepare for our later processing


6. Use the SqlSession object to manipulate data.
Sqlsession is created by the SessionFactory object. Each SqlSession object can be seen as a database connection Connection

The above are the six major development steps of MyBatis.

Guess you like

Origin blog.csdn.net/Turniper/article/details/108799683