zoukankan      html  css  js  c++  java
  • mybatis总结

    • mybatis-spring类结构

    scanner:

    <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方法:
    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/

  • 相关阅读:
    Windows 8 自带定时关机的4种实现方法
    Windows 7/8 自带定时关机命令
    将博客搬至CSDN
    【贪心】【POJ-3637】Shopaholic
    【贪心】【POJ-2437】Muddy roads
    【贪心】【POJ-1328&AOJ-195】Radar Installation
    【贪心】【POJ-1456】Supermarket
    【贪心】【HDOJ-1789】Doing Homework again
    【贪心】【POJ-1992】Ride to School
    【贪心】【POJ-1018】Communication System
  • 原文地址:https://www.cnblogs.com/leeying/p/3590051.html
Copyright © 2011-2022 走看看