spring之整合mybatis【TL spring 12】

UserMapper是代理对象成为一个bean放入spring

factorybean implement FactoryBean usermapper代理对象

1、思路ZhouyuFactoryBean构造方法传入要构造的接口类,使用beanDefinition创建

beandefinition.setBeanClass(ZhouyuFactoryBean.class);

beandefinition.getConstructorArgumentvalues().addGenericArgumentValue(OrderMapper.class)

context.registerBeanDefinition("orderMapper",beanDefinition)

把mybatis代理对象成为了一个bean

2、实现ImportBeanDefinitionRegistrar接口

3、继承ClassPathBeanDefinitionScanner类

bytype会自动找到beandefinition里面的set方法

Mapper来自sqlsessionTemplate.getMapper() mybatis代理对象

userMapper.selectById() ---> sqlSessionTemplate.selectOne()---->sqlsessionProxy.selectOne()---->DefaultSqlSession.selectOne() threadLocal

一级缓存失效

SpringManagedTransaction

相关推荐
Lethehong6 小时前
MySQL迁移如何做到零改造?四层兼容方案详解
数据库·mysql·adb
counting money7 小时前
Spring AI Alibaba 从入门到实战:构建企业级 AI 应用
java·人工智能·spring
竹枝溪8 小时前
MySQL进阶:约束、多表设计、多表查询与事务
java·数据库·mysql·事务·子查询·acid·多表查询
技术长镜头8 小时前
别再只会“加索引”:从磁盘页到 B+Tree,彻底理解 MySQL 索引的设计与运行
后端·mysql
城管不管9 小时前
MySQL 慢查询完整排查
java·服务器·jvm·数据库·mysql·spring·面试
树码小子9 小时前
MySQL 的事务隔离级别(重点面试题)
数据库·mysql
01_ice9 小时前
MySQL表的约束
数据库·sql·mysql
风流 少年18 小时前
Spring AI 2.0:Memory
java·后端·spring
J_bean21 小时前
MySQL 事务是否必须手动开启?
数据库·mysql·数据库事务·自动提交·手动提交