Spring ~spring整合mybatis

  1. 读取applicationContext.xml
    1. 导入spring-dao.xml
      1. 读取db.properties
      2. 配置dataSource
      3. sqlSessionFactory
        1. 注入dataSource
        2. 绑定mybatis配置文件
        3. 绑定*Mapper.xml
      4. sqlSessionTemplate
        • 构造器注入sqlSessionFactory
    2. 注册bean
      1. accountMapper
        • AccountMapperImpl
        • 注入sqlSessionTemplate
      2. accountMapper2
        • AccountMapperImpl2
        • 注入sqlSessionFactory
  2. getBean
    • 获取accountMapper这个bean
  3. 调用accountMapper的selectAllAccount方法
    • AccountMapperImpl实现了该方法
    • 需要注入sqlSessionTemplate,applicationContext.xml配置好了
    • sqlSessionTemplate获取mapper(AccountMapper.class)
    • 该mapper和AccountMapper.xml绑定了
    • 执行SQL
  4. 输出返回结果

猜你喜欢

转载自blog.csdn.net/m0_47585722/article/details/120486249