mybatis相关执行流程,原理等

来源:互联网 发布:修改linux的ip地址 编辑:程序博客网 时间:2024/06/05 17:59

《深入理解mybatis原理》 MyBatis的架构设计以及实例分析 http://blog.csdn.net/luanlouis/article/details/40422941 --必看

 MyBatis源码分析-SQL语句执行的完整流程   https://www.cnblogs.com/luoxn28/p/5932648.html

理分析之二:框架整体设计  http://chenjc-it.iteye.com/blog/1460990

Spring与Mybatis整合的MapperScannerConfigurer处理过程源码分析   --要看

http://www.cnblogs.com/fangjian0423/p/spring-mybatis-MapperScannerConfigurer-analysis.html

Mybatis解析动态sql原理分析 通过源码分析MyBatis的缓存 MyBatis拦截器原理探究

http://www.cnblogs.com/fangjian0423/category/610463.html

mybatis工作原理

https://www.zhihu.com/question/25007334

mybatis

http://www.iteye.com/blogs/subjects/mybatis

MapperScannerConfigurer实现了BeanDefinitionRegistryPostProcessor 。BeanDefinitionRegistryPostProcessor接口有获取BeanDefinitionRegistry的能力,BeanDefinitionRegistry是Spring所有Bean的注册中心,通过这个注册中心可以自定义修改已经定义好的Bean,这样可以加工甚至替换已经定义的Bean,高度化定制Bean的创建。

http://blog.csdn.net/csujiangyu/article/details/52540410


mybatis和spring整合概要:

0 MyMapper

public interface myMapper {
    public UserEO findUserEOById(Long id);
}

1 mybatis  sql 操作文件:config-mybatis.xml 

<!-- 定义Mapper  。注:此处已废弃,用下面的MapperScannerConfigurer配置方式代替,它俩的区别见上面的链接--><!--<bean id="myMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">指定Mapper接口地址<property name="mapperInterface" value="com.google.mapper.MyMapper" /><property name="sqlSessionFactory" ref="sqlSessionFactory" /></bean> --><!-- Mapper接口扫描,可以代替 MapperFactoryBean方式的配置 --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">     <property name="basePackage" value="com.google.mapper" /></bean><!-- 配置SqlSessionFactory --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 数据源 --><property name="dataSource" ref="dataSource" /><!--mybatis的全局的配置文件:                                                        可以配置驼峰命名 拦截器 等等  很重要--><property name="configLocation" value="classpath:xxx/mybatis.xml" /><!-- Mapper.xml                                         代替了全局的配置文件:mybatis.xml 里的       mappers  --><property name="mapperLocations" value="classpath:xxx/mappers/*.xml"/></bean>



2 全局的配置文件:mybatis.xml 具体配置的东西见官网 http://www.mybatis.org/mybatis-3/zh/configuration.html

<configuration><settings><!-- 开启驼峰映射 --><setting name="mapUnderscoreToCamelCase" value="true" /></settings><plugins> <!-- 配置各种拦截器:例如sql监听 分页插件     MyBatis提供了一种插件(plugin)的功能,虽然叫做插件,但其实这是拦截器功能。  --></plugins>     </configuration>

3 spring整合配置文件:

<!-- 配置扫描包 --><context:component-scan base-package="com...."/><!-- 引入 config-mybatis.xml --><!-- 数据源 --><bean id="dataSource" class="com.DataSource"<!-- 数据库驱动 --><property name="driverClass" value="${jdbc.driver}" /><property name="jdbcUrl" value="${jdbc.url}" /><!-- 数据库的用户名 --><property name="username" value="${jdbc.username}" /><!-- 数据库的密码 --><property name="password" value="${jdbc.password}" /></bean>