首页 > 其他 > 详细

mybatis总结

时间:2014-03-09 16:35:14      阅读:464      评论:0      收藏:0      [点我收藏+]
  • mybatis-spring类结构

bubuko.com,布布扣

scanner:

1
2
3
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="xx.dao;ss.dao" />
    </bean>
  1.  scanner.doScan()方法扫描包路径下所有类,设置beanDefinition的相关属性,设置sqlSessionTemplate,设置SqlSessionFactory;
  2. FactoryBean.checkDaoConfig()设置conriguration.addMapper();
  3. FactoryBean.getObject():SqlSessionTemplate override getMapper():Configuration.getMapper():使用mapperRegistry.getMapper();使用MapperProxy.newInstance(),生成MapperMethod。
  4. spring autowired的dao对象时,使用到代理:MapperProxy对象。
  5. 调用mapper.invoke()方法,生成MapperMethod对象,调用execute方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public Object execute(Object[] args) {
    Object result = null;
    if (SqlCommandType.INSERT == type) {
      Object param = getParam(args);
      result = sqlSession.insert(commandName, param);
    } else if (SqlCommandType.UPDATE == type) {
      Object param = getParam(args);
      result = sqlSession.update(commandName, param);
    } else if (SqlCommandType.DELETE == type) {
      Object param = getParam(args);
      result = sqlSession.delete(commandName, param);
    } else if (SqlCommandType.SELECT == type) {
      if (returnsVoid && resultHandlerIndex != null) {
        executeWithResultHandler(args);
      } else if (returnsList) {
        result = executeForList(args);
      } else if (returnsMap) {
        result = executeForMap(args);
      } else {
        Object param = getParam(args);
        result = sqlSession.selectOne(commandName, param);
      }
    } else {
      throw new BindingException("Unknown execution method for: " + commandName);
    }
    return result;
  }

 再回掉SqlSessionTemplate的具体方法进行执行sql和resultMap。

其中涉及到事务的部分,走配置和特殊拦截器,默认无事务。

 

 

http://www.axure.org/tools/

mybatis总结,布布扣,bubuko.com

mybatis总结

原文:http://www.cnblogs.com/leeying/p/3590051.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!