码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • mybatis的简单执行流程-面试用


    1、Configuration

    XMLConfigBuilder调用parse()方法解析Mybatis配置文件,生成Configuration对象
    XMLConfigBuilder parser > Configuration

    SqlSessionFactory = new DefaultSqlSessionFactory ( config );
    session = factory.openSession();
    sqlSession.getMapper(UserMapper.class);

    通过Session来得到UserMapper.java类的代理对象。
    每一个Mapper文件都有一个对应的MapperProxyFactory,为什么需要MapperProxyFactory

    2、因为MapperProxyFactory可以用来生成代理对象。

    MapperProxyFactory是如何产生代理对象: 内部通过目标类转成MapperProxy,在通过Proxy生成代理对象。
    MapperProxy实现了InvocationHandler接口,所以MapperProxy具有拦截功能,

    Proxy如何产生对象的

    Proxy.newProxyInstance(getClassLoader(), new Class[]{this.mapperInterface}, mapperProxy);

    注意第一个参数是类加载器,第二个是代理要实现的接口,第三个参数是InvocationHandler的实例对象。

    Proxy把MapperProxy当做InvocationHandler,Mapper当做接口来生成代理类。最终代理类会实现UserMapper接口,并且被调用时,会被InvocationHandler拦截也就是被MapperProxy拦截。

    当调用方法,会被MapperProxy的invoke方法拦截,invoke会做下面操作

    通过方法名Method查询得到MapperMethodInvoker对象,MapperMethodInvoker是做什么

    3、MapperMethod

    MapperMethod主要包含下面2个东西

    private final MapperMethod.SqlCommand command;
    private final MapperMethod.MethodSignature method;
    
    public MapperMethod(Class<?> mapperInterface, Method method, Configuration config) {
        this.command = new MapperMethod.SqlCommand(config, mapperInterface, method);
        this.method = new MapperMethod.MethodSignature(config, mapperInterface, method);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    SqlCommand和MethodSignature干嘛用的。
    1、SqlCommand一个内部类 封装了SQL标签的类型insert update delete select
    2、MethodSignature一个内部类 封装了方法的参数信息 返回类型信息等

    MapperMethod有个execute,就是开始执行sql的操作.在execute里面,通过类型找到事insert还是update,在通过返回值类型找具体方法,处理类型
    在通过类+方法名当做ID去Mapper.xml里面找对应的sql执行语句。

    关于MapperMethod可以看这个文章:《MapperMethod》

  • 相关阅读:
    NIO的浅了解
    【LIUNX】机器互访:免密登陆
    读取windows日志
    基于多种GPU和CPU进行优化可选,最新基于机器学习模型单图换脸离线版软件包及使用方法,本地离线版本模型一键运行(免费下载)
    专家解读 | NIST网络安全框架(3):层级配置
    精心整理了超详细的Linux入门笔记,零基础也能看懂,一学就会
    51单片机学习:步进电机实验
    Python 基于PyCharm断点调试
    从 jsonpath 和 xpath 到 SPL
    SpringBoot + Redis +RabbitMQ 实现高并发并限时秒杀
  • 原文地址:https://blog.csdn.net/weixin_37862824/article/details/133923791
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号