阶段3 1.Mybatis_06.使用Mybatis完成DAO层的开发_6 Mybatis中使用Dao实现类的执行过程分析-增删改方法



从测试类入手,断点调试
找到实现类,进入到insert方法里面

这里是SqlSession的接口里面的方法。

我们需要找SqlSession的实现类。




DefaultSqlSession



里面有两个insert方法,第一个insert执行的是第二个insert方法,德尔格insert方法又执行的是下面的update方法

delete最终执行的也是update方法


我们的update方法传了两个参数

所以他最终执行的是这里两个参数的

update再往后走就是executor.update方法。也就是不管执行增删改,最终都会归到这个executor对象





delegate.update

又回到了Executor里面的update

在executor的父类BaseExecutor里面有update方法。里面调用了一个叫做doUpdate的方法

doUpdate是一个抽象方法,它是没有具体代码的。于是就要找BaseExecutor的子类

BaseExecutor的子类SimpleExecutor

SimpleExecutor里面就会有一个doUpdate方法。里面又调用了handler.update

handle就是StatementHandler



RoutingStatementHandler里面的update方法

RoutingStatementHandler里面的update方法 最终调用的是PreparedStatementHandler



在这里传统的jdbc操作就出来了。其实最终执行的也是PreparedStatement的execute方法

前面不管使用update、delete、insert最终都是update方法执行 ,也就是PreparedStatement的execute方法。
所以在实际开发过程中,其实我们只要使用一个update方法就可以实现操作。当然他系统其它的对应方法我们也是拿过来用


 

原文地址:https://www.cnblogs.com/wangjunwei/p/11313263.html