首页编程methodinvoker,【mybatis-高级篇】

methodinvoker,【mybatis-高级篇】

编程之家2023-11-04193次浏览

大家好,今天来为大家解答methodinvoker这个问题的一些问题点,包括【mybatis-高级篇】也一样很多人还不知道,因此呢,今天就来为大家分析分析,现在让我们一起来看看吧!如果解决了您的问题,还望您关注下本站哦,谢谢~

methodinvoker,【mybatis-高级篇】

c#Invoke加Join()为什么会死机

因为发生了死锁。

thread.Join();会阻塞主线程直到thread线程结束,而thread线程会执行zixian方法,在zixian方法中又调用了SetText方法,SetText方法中的this.Invoke又请求主线程同步执行委托方法,但主线程已阻塞,主线程在等待thread线程结束,而thread线程又阻塞在对this.Invoke的调用中,等待主线程执行完委托方法,所以发生了死锁。

【mybatis-高级篇】

Mybatis的四大对象

Executor

ParameterHandler

ResultSetHandler

methodinvoker,【mybatis-高级篇】

StatementHandler

一个MappedStatement代表一个增删改查的详细信息

Configuration包含全局配置,所有映射文件信息,接口信息

MappedStatement:一个sql对应一个MappedStatement

MapperProxyFactory:生成MapperProxy实例

Executor:执行增删改查,其中调用StatementHandler处理

methodinvoker,【mybatis-高级篇】

原理分析

1、获取SqlSessionFactory对象

把配置文件的信息解析并保存在Configuration对象中(包含所有的映射文件信息、接口信息等),返回包含了Configuration的DefaultSqlSession对象

SqlSessionFactory sqlSessionFactory= new SqlSessionFactoryBuilder().build(inputStream);

2、获取SqlSession

返回SqlSession的实现类Default对象,包含了Executor和Configuration;会有拦截器链(interceptChain.pluginAll(executor))对Executor进行插入修饰。

3、getMapper

getMapper使用MapperProxyFactory创建一个MapperProxy的代理对象,包含了DefaultSqlSession(Executor)

4、执行方法

创建MapperMethodInvoker(接口,有invoke方法),PlainMethodInvoker写入本次方法查询相关信息(MapperMethod),MapperMethod包括SqlCommand和MethodSignature。调用MapperMethodInvoker.invoke方法执行操作=>PlainMethodInvoker中调用MapperMethod.excute方法。MapperMethod.excute是真正执行方法。调用MapperStatment

通过调用代理类执行方法,创建StatementHandler(ParameterHandler,ResultSetHandler)处理器对象,使用处理器调用底层JDBC执行SQL返回结果。

责任链模式+动态代理+反射机制

插件编写

https://github.com/abel533/MyBatis-Spring-Boot

方法一:

设置全局步骤defaultExecutorType=BATCH,表示所有的查询都使用批量处理

方法二:

获得批量处理的sqlSession进行处理 SqlSession sqlSessin= sqlSessionFactory.openSession(Executor.BATCH)

方法三:

整合注入sqlSession,class=SqlSessionTemplate,类型executorTyepe=BATCH,然后aurowired使用

1、实现TypeHandler接口,或者继承BaseTypeHandler

2、配置使用自定义TypeHandler

方式一:全局配置

方式二:独立配置

END,本文到此结束,如果可以帮助到大家,还望关注本站哦!

网站制作设计?公司网站如何制作兰州网站设计公司 兰州有名的软件开发公司