The running process of mybatis

The operation process of MyBatis is divided into three stages:

  1. Initialization phase : read the configuration information in XML configuration files and annotations, create configuration objects, and complete the initialization of each module;
  2. Proxy encapsulation stage : Encapsulate iBatis programming model, use mapper interface to develop initialization work;
  3. Data access phase : complete the SQL parsing, parameter mapping, SQL execution, and result parsing process through SqlSession;

In order to get familiar with the running process of Mybatis, let's first look at a piece of code

public class MybatisDemo { ​ private SqlSessionFactory sqlSessionFactory; @Before public void init() throws IOException { //--------------------第一步:加载配置---------------------------   // 1.读取mybatis配置文件创SqlSessionFactory String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); // 1.读取mybatis配置文件创SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); inputStream.close(); } @Test // 快速入门 public void quickStart() throws IOException { //--------------------第二部,创建代理对象------------------

Guess you like

Origin blog.csdn.net/yetaodiao/article/details/131068581