zoukankan      html  css  js  c++  java
  • mybatis spring sqlsession

    sqlsession是什么?

    http://blog.csdn.net/hupanfeng/article/details/9238127

    知道

    sqlsession创建

    可以看出,创建sqlsession经过了以下几个主要步骤:

    1)       从配置中获取Environment;

    2)       从Environment中取得DataSource;

    3)       从Environment中取得TransactionFactory;

    4)       从DataSource里获取数据库连接对象Connection;

    5)       在取得的数据库连接上创建事务对象Transaction;

    6)       创建Executor对象(该对象非常重要,事实上sqlsession的所有操作都是通过它完成的);

    7)       创建sqlsession对象。

    从官网知道

    In MyBatis you use the SqlSessionFactory to create an SqlSession. Once you have a session, you use it to execute your mapped statements, commit or rollback connections and finally, when it is no longer needed, you close the session. With MyBatis-Spring you don't need to use SqlSessionFactory directly because your beans can be injected with a thread safe SqlSession that automatically commits, rollbacks and closes the session based on Spring's transaction configuration.

    就是使用sqlsession可以使用事务功能,在一次sqlsession中增删改查可以回滚和提交

    在spring中是怎么创建mapper实例的?

    在spring中

    官网:

    http://www.mybatis.org/spring/zh/mappers.html

    说到可以利用

    <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">

      <property name="mapperInterface" value="org.mybatis.spring.sample.mapper.UserMapper" />

     <property name="sqlSessionFactory" ref="sqlSessionFactory" />

    </bean>

    利用MapperFactoryBean来进行mapper创建

    读源码知道创建一个MapperFactoryBean就要创建一个sqlsession,,所以数据库事务交给spring来管理

    sqlsession在close时没有close数据库连接,只是把数据库连接返回给数据库连接池

    一次sqlsession中update需要commite;

  • 相关阅读:
    git 拉取开发代码
    android webview
    H5 元素定位
    Python中模块
    服务器1
    活动
    宝塔面板-阿里部署
    最新版Xshell、Xftp注册机NetSarang
    最新版Navicat Premium激活,附激活工具
    9月29更新美版T-mobile版本iPhone7代和7P有锁机卡贴解锁方法
  • 原文地址:https://www.cnblogs.com/hong2016/p/8000745.html
Copyright © 2011-2022 走看看