mybatis执行流程源码分析

Mybatis 底层源码分析-Mybatis 执行流程 1 MyBatis 流程图 2 MyBatis 源码分析2.1 该配置文件是 MyBatis 的全局配置文件,在这个文件中可以配置诸多项目。常用的内容 是别名设置,拦截器设置等。 2.1.1(属性) 将数据库连接 参数 单独配置在 中 , 放在类路径 下 。 这样 只 需要在 中加载 的属性值。这样在 中就不需要对数 据库连接参数硬编码。 将数据库连接参数只配置在 中,原因:方便对参数进行统一管理 2.1.2Settings(全局配置参数) Mybatis 全局配置参数,全局参数将会 阅读详情

mybatis执行流程源码分析

mybatis官网 https://mybatis.org/mybatis-3/

需要准备的环境:mysql、maven、idea

根据官网的入门教程进行项目搭建

项目结构图

在这里插入图片描述
pom文件配置
我这项目存在父工程,可以把parent标签删除

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>parent-mybatis</artifactId>
        <groupId>org.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mybatis-demo1</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.5</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.49</version>
        </dependency>
    </dependencies>

</project>

mybatis configuration 文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/mybatis-test"/>
                <property name="username" value="xxx"/>
                <property name="password" value="xxx"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <!--        配置资源文件-->
        <mapper resource="DeptMapper.xml"/>
    </mappers>
</configuration>

mybatis 资源文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
        
        <!-- namespace 代表了一个唯一的类,如果唯一可以去掉包名如:
        <mapper namespace="Dept"> 或者通过配置文件可以进行别名配置(自行百度。)-->
        
<mapper namespace="com.lhl.demo1.Dept">
    <insert id="insertDept" >
        insert into dept(name,loc) values(#{name},#{loc})
    </insert>
</mapper>

实体类自行加getset或者用lombok

public class Dept {

    private int id;

    private String name;

    private String loc;
}

测试类

package com.lhl.demo1;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;


public class TestMain {

    public static void main(String[] args) {
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        Dept dept =new Dept();
        dept.setLoc("湖北");
        dept.setName("金融事业单位");
        int insertDept = sqlSession.insert("insertDept", dept);
        sqlSession.commit();
        System.out.println(insertDept);
    }


}

源码解析
在这里插入图片描述

1、首先在第22行打下断点,14-22行就是一个读取mybatis配置文件的输入流通过debug的变量可以看到获取到的是一个缓冲输入流 BufferedInputStream对象
2、在第22行可以发现调用了SqlSessionFactoryBuilder的builder方法获取到了一个SqlSessionFactory对象。首先进入SqlSessionFactoryBuilder类下发现使用默认空参构造方法无任何代码存在。

在这里插入图片描述

builder 方法是一个重载方法,最终调用方法提供三个参数的builder方法

 public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) {
    try {
    	// 第一步调用 XMLConfigBuilder 三个参数的构造方法
      XMLConfigBuilder parser = new XMLConfigBuilder(inputStream, environment, properties);
      // 调用parse的parse方法返回Configuration,包含了配置文件中的所有属性值,调用build方法传递Configuration到DefaultSqlSessionFactory构造方法生成DefaultSqlSessionFactory实例
      return build(parser.parse());
    } catch (Exception e) {
      throw ExceptionFactory.wrapException("Error building SqlSession.", e);
    } finally {
      ErrorContext.instance().reset();
      try {
        inputStream.close();
      } catch (IOException e) {
        // Intentionally ignore. Prefer previous error.
      }
    }
  }
public SqlSessionFactory build(Configuration config) {
    return new DefaultSqlSessionFactory(config);
  }


// XMLConfigBuilder类
 public Configuration parse() {
    if (parsed) {
      throw new BuilderException("Each XMLConfigBuilder can only be used once.");
    }
    parsed = true;
    parseConfiguration(parser.evalNode("/configuration"));
    return configuration;
  }
  // 根据mybatis配置文件dtd约束文档的标签进行解析xml文件封装成configuration对象的属性
private void parseConfiguration(XNode root) {
    try {
      // issue #117 read properties first
      //第一个举例说明
      propertiesElement(root.evalNode("properties"));
      Properties settings = settingsAsProperties(root.evalNode("settings"));
      loadCustomVfs(settings);
      loadCustomLogImpl(settings);
      typeAliasesElement(root.evalNode("typeAliases"));
      pluginElement(root.evalNode("plugins"));
      objectFactoryElement(root.evalNode("objectFactory"));
      objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));
      reflectorFactoryElement(root.evalNode("reflectorFactory"));
      settingsElement(settings);
      // read it after objectFactory and objectWrapperFactory issue #631
      environmentsElement(root.evalNode("environments"));
      databaseIdProviderElement(root.evalNode("databaseIdProvider"));
      typeHandlerElement(root.evalNode("typeHandlers"));
      mapperElement(root.evalNode("mappers"));
    } catch (Exception e) {
      throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + e, e);
    }
  }

 private void propertiesElement(XNode context) throws Exception {
    if (context != null) {
      Properties defaults = context.getChildrenAsProperties();
      String resource = context.getStringAttribute("resource");
      String url = context.getStringAttribute("url");
      if (resource != null && url != null) {
        throw new BuilderException("The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.");
      }
      if (resource != null) {
        defaults.putAll(Resources.getResourceAsProperties(resource));
      } else if (url != null) {
        defaults.putAll(Resources.getUrlAsProperties(url));
      }
      Properties vars = configuration.getVariables();
      if (vars != null) {
        defaults.putAll(vars);
      }
      parser.setVariables(defaults);
      //解析出来的值最终封装成立了configuration的属性
      configuration.setVariables(defaults);
    }
  }

第23行 SqlSession sqlSession = sqlSessionFactory.openSession();

// DefaultSqlSessionFactory类的实现
 @Override
  public SqlSession openSession() {
    return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, false);
  }
  // 打开session从数据源,三个参数值如下图
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
    Transaction tx = null;
    try {
    // 从configuration获取各种配置信息,
      final Environment environment = configuration.getEnvironment();
      final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
      //生成事务实例tx
      tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
      // 根据配置信息生成新的执行器
      final Executor executor = configuration.newExecutor(tx, execType);
      // 最终创建DefaultSqlSession对象
      return new DefaultSqlSession(configuration, executor, autoCommit);
    } catch (Exception e) {
      closeTransaction(tx); // may have fetched a connection so lets call close()
      throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
    } finally {
      ErrorContext.instance().reset();
    }
  }

在这里插入图片描述

//Configuration类
// mybatis实现了多个执行器
public Executor newExecutor(Transaction transaction, ExecutorType executorType) {
    executorType = executorType == null ? defaultExecutorType : executorType;
    executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
    Executor executor;
    if (ExecutorType.BATCH == executorType) {
      executor = new BatchExecutor(this, transaction);
    } else if (ExecutorType.REUSE == executorType) {
      executor = new ReuseExecutor(this, transaction);
    } else {
      executor = new SimpleExecutor(this, transaction);
    }
    if (cacheEnabled) {
      executor = new CachingExecutor(executor);
    }
    executor = (Executor) interceptorChain.pluginAll(executor);
    return executor;
  }

在这里插入图片描述

到这步也未看到跟jdbc有关的内容,都是基于配置文件mybatis-config.xml做的初始化工作,继续进行下步工作,初始化并赋值dept对象,然后调用sqlSession对象的insert方法

// DefaultSqlSession
 @Override
  public int insert(String statement, Object parameter) {
  // 调用update方法
    return update(statement, parameter);
  }

  @Override
  public int update(String statement) {
    return update(statement, null);
  }

  @Override
  public int update(String statement, Object parameter) {
    try {
    // DefaultSqlSession存在一个属性dirty ,赋值为true,初始值看到是false,先不管。。
      dirty = true;
      // 调用configuration获取MappedStatement 对象,跟源码发现是在初始化时创建了一个
      //protected final Map<String, MappedStatement> mappedStatements = new //StrictMap<MappedStatement>("Mapped Statements collection")
   //   .conflictMessageProducer((savedValue, targetValue) ->
    //      ". please check " + savedValue.getResource() + " and " + //targetValue.getResource()); 来进行内存存储的。从下面debug内容可以看到,他是根据statement来进行查找到已经配置好的内容,如类型信息,namespace,sql语句等。。
      MappedStatement ms = configuration.getMappedStatement(statement);
      // 调用executor的update方法
      return executor.update(ms, wrapCollection(parameter));
    } catch (Exception e) {
      throw ExceptionFactory.wrapException("Error updating database.  Cause: " + e, e);
    } finally {
      ErrorContext.instance().reset();
    }
  }

 private Object wrapCollection(final Object object) {
    return ParamNameResolver.wrapToMapIfCollection(object, null);
  }
// 包装对象,将Collection、array类型进行包装
public static Object wrapToMapIfCollection(Object object, String actualParamName) {
    if (object instanceof Collection) {
      ParamMap<Object> map = new ParamMap<>();
      map.put("collection", object);
      if (object instanceof List) {
        map.put("list", object);
      }
      Optional.ofNullable(actualParamName).ifPresent(name -> map.put(name, object));
      return map;
    } else if (object != null && object.getClass().isArray()) {
      ParamMap<Object> map = new ParamMap<>();
      map.put("array", object);
      Optional.ofNullable(actualParamName).ifPresent(name -> map.put(name, object));
      return map;
    }
    return object;
  }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


 @Override
  public int doUpdate(MappedStatement ms, Object parameter) throws SQLException {
    Statement stmt = null;
    try {
      Configuration configuration = ms.getConfiguration();
      // 根据ms创建StatementHandler 对象
      StatementHandler handler = configuration.newStatementHandler(this, ms, parameter, RowBounds.DEFAULT, null, null);
      // 根据StatementHandler 对象创建Statement 对象
      stmt = prepareStatement(handler, ms.getStatementLog());
      // 执行最终的stmt对象
      return handler.update(stmt);
    } finally {
      closeStatement(stmt);
    }
  }
 private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException {
    Statement stmt;
    //jdbc操作 获取数据库连接
    Connection connection = getConnection(statementLog);
    // 创建prepareStatement对象
    stmt = handler.prepare(connection, transaction.getTimeout());
    //处理prepareStatement对象
    handler.parameterize(stmt);
    return stmt;
  }

  protected Connection getConnection(Log statementLog) throws SQLException {
  // 从transaction对象的datasource连接池里拿出来一个连接
    Connection connection = transaction.getConnection();
    if (statementLog.isDebugEnabled()) {
      return ConnectionLogger.newInstance(connection, statementLog, queryStack);
    } else {
      return connection;
    }
  }

// RoutingStatementHandler
 @Override
  public Statement prepare(Connection connection, Integer transactionTimeout) throws SQLException {
  // 委托
    return delegate.prepare(connection, transactionTimeout);
  }

// BaseStatementHandler 
@Override
  public Statement prepare(Connection connection, Integer transactionTimeout) throws SQLException {
    ErrorContext.instance().sql(boundSql.getSql());
    Statement statement = null;
    try {
    // 实例化
      statement = instantiateStatement(connection);
     // 设置属性如超时时间等
      setStatementTimeout(statement, transactionTimeout);
      setFetchSize(statement);
      return statement;
    } catch (SQLException e) {
      closeStatement(statement);
      throw e;
    } catch (Exception e) {
      closeStatement(statement);
      throw new ExecutorException("Error preparing statement.  Cause: " + e, e);
    }
  }


@Override
  protected Statement instantiateStatement(Connection connection) throws SQLException {
   // 获取sql语句
    String sql = boundSql.getSql();
    if (mappedStatement.getKeyGenerator() instanceof Jdbc3KeyGenerator) {
      String[] keyColumnNames = mappedStatement.getKeyColumns();
      if (keyColumnNames == null) {
        return connection.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
      } else {
        return connection.prepareStatement(sql, keyColumnNames);
      }
    } else if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
      return connection.prepareStatement(sql);
    } else {
      return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
    }
  }

//对sql语句的参数进行赋值
 @Override
  public void setParameters(PreparedStatement ps) {
    ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
    List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
    if (parameterMappings != null) {
      for (int i = 0; i < parameterMappings.size(); i++) {
        ParameterMapping parameterMapping = parameterMappings.get(i);
        if (parameterMapping.getMode() != ParameterMode.OUT) {
          Object value;
          String propertyName = parameterMapping.getProperty();
          if (boundSql.hasAdditionalParameter(propertyName)) { // issue #448 ask first for additional params
            value = boundSql.getAdditionalParameter(propertyName);
          } else if (parameterObject == null) {
            value = null;
          } else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
            value = parameterObject;
          } else {
            MetaObject metaObject = configuration.newMetaObject(parameterObject);
            value = metaObject.getValue(propertyName);
          }
          TypeHandler typeHandler = parameterMapping.getTypeHandler();
          JdbcType jdbcType = parameterMapping.getJdbcType();
          if (value == null && jdbcType == null) {
            jdbcType = configuration.getJdbcTypeForNull();
          }
          try {
            typeHandler.setParameter(ps, i + 1, value, jdbcType);
          } catch (TypeException | SQLException e) {
            throw new TypeException("Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e, e);
          }
        }
      }
    }
  }

@Override
  public int update(Statement statement) throws SQLException {
    PreparedStatement ps = (PreparedStatement) statement;
    //jdbc
    ps.execute();
    int rows = ps.getUpdateCount();
    Object parameterObject = boundSql.getParameterObject();
    KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
    keyGenerator.processAfter(executor, mappedStatement, ps, parameterObject);
    //返回影响的行数
    return rows;
  }

 @Override
  public void commit() {
    commit(false);
  }

@Override
  public void commit(boolean force) {
    try {
    // force初始为false
      executor.commit(isCommitOrRollbackRequired(force));
      dirty = false;
    } catch (Exception e) {
      throw ExceptionFactory.wrapException("Error committing transaction.  Cause: " + e, e);
    } finally {
      ErrorContext.instance().reset();
    }
  }

 private boolean isCommitOrRollbackRequired(boolean force) {
 	//dirty 用来进行是否提交的
    return (!autoCommit && dirty) || force;
  }

// 只有进行了
 @Override
  public void commit(boolean required) throws SQLException {
    if (closed) {
      throw new ExecutorException("Cannot commit, transaction is already closed");
    }
    clearLocalCache();
    flushStatements();
    // 如果为false,不进行事务提交
    if (required) {
      transaction.commit();
    }
  }
centos7部署mysql8.0.35,主从复制,主主集群 centos7 linux部署mysql,主从复制,主主模式 阅读详情

相关推荐

STM32L476低功耗实战:LPTIM精准定时唤醒STOP2模式与系统级功耗优化

本文深入探讨了STM32L476低功耗实战技巧,重点解析了LPTIM精准定时唤醒STOP2模式的配置与优化。通过详细的步骤指南和实战经验分享,帮助开发者实现系统级功耗优化,特别适合电池供电设备开发。文章涵盖LPTIM1定时器配置、STOP2模式进入流程及常见问题排查,助力将整机功耗降至8.2uA级别。

weixin_33686714的博客 435

Could not set parameters for mapping解决方法 xml文件内有注释符号导致的

Could not set parameters for mapping解决方法

Muxiu 343

深入浅出Mybatis源码解析——SqlSession执行主流程(补)

前言 由于Mybatis的源码系列文章,期间有长时间的脱节,导致笔者在写代码解析的时候中间出现了断裂,这个要和大家说声对不起,因此本篇文章是补深入浅出Mybatis源码解析——获取Mapper代理对象流程照片文章的,在这篇文章中简单的说了一下SqlSession执行主流程,也只是简单的说了说,后面的核心代码还没有涉及。 说到这里,我们还是尽快进入主题,首先回顾下前面提到的那篇文章最后的代码,如...

寒山道杳 456

【机器学习】图神经网络(NRI)模型原理和运动轨迹预测代码实现

NRI模型利用VAE和GNN从观测数据中学习系统动态和交互图,展现出在无监督学习、图结构建模、多步预测和连续松弛方面的强大能力。未来工作可探索动态图结构学习、应用于更复杂系统、提高模型泛化能力和计算效率,以及与其他模型的结合。NRI作为新兴的图神经网络方法,在理解和预测相互作用系统方面潜力巨大,有望在各领域发挥重要作用。

MUKAMO的博客 2777

DSI3协议介绍

分布式系统接口(DSI)是一种通用且功能强大的总线协议,旨在将多个遥感器和执行器设备互连到中央控制模块。该网络的主要目标应用是汽车安全系统。这种应用的一些特点是需要低成本、高鲁棒性、中速互连,仅限于两根导线。此外,它必须具有故障安全性、确定性和良好的EMC特性。即使具有所有级别的智能和可编程性的设备都可以连接到网络,远程设备也必须能够通过简单的状态机实现。由于模块尺寸非常重要,因此中央模块和远程单元中的最小组件至关重要。

汽车电子软件领域知识分享 1万+

深入了解mybatis参数

深入了解MyBatis参数 相信很多人可能都遇到过下面这些异常: “Parameter ‘xxx’ not found. Available parameters are […]” "Could not get property ‘xxx’ from xxxClass. Cause: “The expression ‘xxx’ evaluated to a null value.” “Error ...

weixin_43242688的博客 1100

ADS电路仿真方法综述:原理与应用

在射频与微波电路设计中,精确的仿真技术是验证性能的关键。ADS(Advanced Design System)作为行业标准工具,集成了多种仿真方法,适用于不同场景。本文将系统解析瞬态分析、谐波平衡(HB)、交流分析(AC)、直流分析(DC)、S参数、大信号SP(LSSP)及包络分析的原理、实现机制与应用场景。

u014344410的博客 480

Mybatis核心-StatementHandler

Mybatis核心-StatementHandler

MAX_VALUE的博客 341

ISOLAR Autosar BSW 配置 之 Com

Autosar ISOLAR Bsw Configuration 之 Com

qq_42262743的博客 453

C#上位机+YOLO实时目标检测:摄像头采集+多线程推理+精度调优全流程

标注数据集:使用LabelImg工具标注目标对象,按YOLO格式整理数据集;模型训练:使用Ultralytics库训练自定义模型,提升特定目标的检测精度;训练参数优化:增加训练轮数(epochs=100200)、调整批次大小(batch=1632)、使用数据增强(flip、mosaic等)。摄像头采集:封装通用采集类,支持USB摄像头/网口相机,实现稳定帧读取与异常处理;多线程推理:采用“采集线程+推理线程+UI线程”解耦架构,使用线程安全队列传递帧数据,彻底解决界面卡顿;核心封装。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 673

nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping错误的决方法

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='missionId', mode=IN, javaType=class java.lang.Long, jdbcType=null, numericScale=null, resu

念兮为美 8844

强化学习实战——OpenAI Gym环境配置+实战演示(win10)

遇到问题:无法安装pickle5原因是:python3.8与该包不兼容,必须降python3.7的版本。

LZL2020LZL的博客 4899

MyBatis执行流程源码分析

MyBatis执行流程源码分析1. MyBatis概述2. MyBatis执行流程分析2.1 MyBatis执行流程2.2 MyBatis执行流程图3.MyBatis传统模式源码分析3.1 传统模式执行流程3.2 读取Mybatis配置文件3.3 创建SqlSessionFactory3.4 创建SqlSession3.5 sqlSession执行查询4. MyBatis接口模式源码分析4.1 接口模式执行流程4.2 读取Mybatis配置文件4.3 创建SqlSessionFactory4.4 创建Sql

靖节先生的博客 1040

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

myBatis执行流程及源码分析

一、简介 MyBatis 是一款优秀的持久层框架,它支持自定义 SQL、存储过程以及高级映射。MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型、接口和 Java POJO(Plain Old Java Objects,普通老式 Java 对象)为数据库中的记录。 那接下来,就来看一下MyBatis到底是如何执行的。 二、执行流程 1、获取sqlsessio...

weixin_44941128的博客 1397

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

mybatis-sql执行流程源码分析

1. SqlSessionFactory 与 SqlSession.   通过前面的章节对于mybatis 的介绍及使用,大家都能体会到SqlSession的重要性了吧, 没错,从表面上来看,咱们都是通过SqlSession去执行sql语句(注意:是从表面看,实际的待会儿就会讲)。那么咱...

84

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Mybatis执行流程源码分析

那么,这一段代码是Mybatis是如何执行,如何获取到SqlSessionFactory,如何获取到Mapper,又是如何执行Sql呢?方法依次对xml中的各节点进行解析,实质是将各个节点的信息解析成对应的配置类,全都放到Configuration类中(存放所有配置信息)

u014135956的博客 1633

mybatis源码分析执行流程

前言 在上一篇,我们了解了mybatis的整体执行流程,以及内部的各个组件在执行过程中的功能,下面我们来通过源码的方式对其中比较重要的几个组件在执行过程的使用进行简单的分析与说明 环境准备 基于第一篇搭建好的源码过程和demo,我们通过一个简单的查询进行分析,完整的代码如下: userDao public interface UserDao { User findUserById(int id); } MyUserMapper.xml <mapper namespace="com.congge.

congge 1102

mybatis执行流程的源码分析

mybatis执行流程的源码分析 文章目录mybatis执行流程的源码分析一、**通过SqlSessionFactoryBuilder类创建SqlSessionFactory。****二、再通过SqlSessionFactory取获取sqlSession。****三、具体的执行流程。****四、注册mapper到注册中心( 类Configuration),下面以xml方式举例。******五、通过...

hanbingbbs的专栏 199

mybatis 执行流程 源码分析

mybatis执行流程,源码分析 一直在用mybatis,始终没有对mybatis的执行流程进行过深入了解,周末闲来无事,进行一次记录。 1.加载配置文件 InputStream in = Resources.getResourceAsStream("sqlMapConfig.xml"); 2.创建SqlSessionFactory SqlSessionFactory sqlSessionFac...

Jhon1994的博客 255

mybatis执行流程源码分析总结

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 ...

s297485987的专栏 272

【Mybatis】执行流程及源码分析

要了解mybatis的底层原理,我们就得先知道在mybatis中,是如何实现查询的。 现在我们具体来介绍Mybatis的ju

Zc_orange的博客 260
上一篇: idea中基于数据库表的JPA实体生成(lombok)
下一篇: mybatis的类型转换器TypeHandler
li_a_long
博客等级 码龄9年 1粉丝 15原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值