MyBatis-Plus 通用CRUD启动注入SQL原理分析

  @Test
    public void getUser() {
        User user = userMapper.selectById(1);
        System.out.println("user:" + user);
    }

A、userMapper的本质是org.apache.ibatis.binding.MapperProxy

B、MapperProxy中有一个SqlSession,SqlSession中有一个SqlSessionFactroy

 

 C、SqlSessionFactroy中有一个 Configuration -->  MappedStatements

  每一个MappedStatement都表示mapper接口中的一个方法与mapper映射文件中的一个sql

  MP启动就会挨个分析xxxMapper中的方法,并且将对应的sql预计处理好,保存到Configuration 对象中的MappedStatements

 D、本质 addMappedStatement

AutoSqlInjector中的addMappedStatement

SqlMethed :枚举对象,MP支持的sql方法,sql的模板
TableInfo :数据库的反射表信息,可以获取到数据库表相关的信息
SqlSource :sql语句处理对象 存放处理完的sql语句
MapperBuilderAssistant :用于缓存、sql参数、查询返回结果集处理,通过MapperBuilderAssistant将每一个MappedStatement添加到configuration中的MappedStatement中
原文地址:https://www.cnblogs.com/lc0605/p/14149661.html