1. Introduction to MyBatis

One, MyBatis introduction:

  1. MyBatis is an excellent persistence layer framework (the DAO class combined with the mybatis framework allows us to quickly complete the addition, deletion, modification, and check operation. Persistence: save the data in memory to the database to prevent data loss after restart
  2. MyBatis uses XML to decouple SQL from the program for easy maintenance
  3. MyBatis is simple to learn and efficient in execution. It is an extension of JDBC. Beginners who have learned JDBC can usually get started in 1,2 days, because the bottom layer of MyBatis is JDBC.

Two, MyBatis online learning documents

https://mybatis.org/mybatis-3/zh/index.html

Three, MyBatis development process

  1. Introduce MyBatis dependency: maven
  2. Create a core configuration file: configuration management based on xml
  3. Create Entity class/pojo simple object: As a persistence layer framework, MyBatis is characterized by one-to-one correspondence between the underlying data table and the defined java class. At the same time, the fields in the data table and the attributes in the class have a corresponding relationship. The class corresponding to the underlying table is called the entity class
  4. Create Mapper mapping file: Mapper is the key for MyBatis to map entities and data tables. The Mapper file is used to map which table and which class corresponds, and which attribute in this table corresponds to which attribute in the class.
  5. Initialize SessionFactory: the core step, at this step, the coding link is carried out, the function is to read the configuration file, load the Mapper mapping, and also prepare for the subsequent processing
  6. Use the SqlSession object to manipulate data: If you want to add, delete, modify, and check a table or data, use the SqlSession object. The SqlSession object is created by the SessionFactory object. Each SqlSession object can be regarded as a database connection Connection, but it has been extended in many ways on the basis of the original

Guess you like

Origin blog.csdn.net/qq_36792120/article/details/112123361