spring-mybatis与mybatis区别

本文对比了Spring-Mybatis与Mybatis在一级缓存和Session管理上的区别。Spring-Mybatis使用sqlsessionTemplate,每次请求会关闭由代理对象proxysession管理的session,导致一级缓存失效。而Mybatis的DefaultSqlSession在同一会话期间保持打开状态,session的关闭可手动控制,提供更好的资源利用率。
摘要由CSDN通过智能技术生成

1,spring-mybatis一级缓存失效,因为是sqlsesstionTemplate,其使用了一个代理proxysession,每次请求都会关闭session;

spring-mybatis扩展了一个类sqlsessiontemplate,这个类在spring容器启动时被注入给mapper, 这个类替代了原来的mybatis的DefaultSqlSession,sqlsessiontemplate的所有查询并不直接查询,而是经过一个代理对象,代理对象增加了查询方法,主要是每次关闭了session

 

public SqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType executorType, PersistenceExceptionTranslator exceptionTranslator) {
    Assert.notNull(sqlSessionFactory, "Property 'sqlSessionFactory' is required");
    Assert.notNull(executorType, "Property 'executorType' is required");
    this.sqlSessionFactory = sqlSessionFactory;
    this.executorType = executorType;
    this.exceptionTranslator = exceptionTranslator;
    this.sqlSessionProxy = (SqlSession)Proxy.newProxyInstance(SqlSessionFactory.class.getClassLoader(), new Class[]{SqlSession
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值