Mybatics一级缓存分析

 1 @Test  
 2     public void test1() throws Exception {  
 3         User user = userService.getUserById(1);
 4         System.out.println(user);  
 5           
 6         user = userService.getUserById(1);
 7         System.out.println(user);  
 8           
 9         user = userService.getUserById(1);;
10         System.out.println(user);  
11           
12     }  

如上测试代码,从下Debug钟可以看到依次从数据库拿了3次连接,每次查询完毕,则把数据库连接返回druid连接池,SQL被执行3次

 [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
  [org.mybatis.spring.SqlSessionUtils] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@9e918ed] was not registered for synchronization because synchronization is not active
  [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
  [com.alibaba.druid.pool.DruidDataSource] - {dataSource-1} inited
  [org.mybatis.spring.transaction.SpringManagedTransaction] - JDBC Connection [com.mysql.jdbc.JDBC4Connection@41ee0498] will not be managed by Spring
  [com.ssmbase.dao.UserMapper.selectByPrimaryKey] - ==>  Preparing: select id, user_name, password, age from user_t where id = ? 
  [com.ssmbase.dao.UserMapper.selectByPrimaryKey] - ==> Parameters: 1(Integer)
  [com.ssmbase.dao.UserMapper.selectByPrimaryKey] - <==      Total: 1
  [org.mybatis.spring.SqlSessionUtils] - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@9e918ed]
  [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
  com.ssmbase.domain.User@59f52a1d
[org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
  [org.mybatis.spring.SqlSessionUtils] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6ea0040e] was not registered for synchronization because synchronization is not active
  [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
  [org.mybatis.spring.transaction.SpringManagedTransaction] - JDBC Connection [com.mysql.jdbc.JDBC4Connection@41ee0498] will not be managed by Spring
  [com.ssmbase.dao.UserMapper.selectByPrimaryKey] - ==>  Preparing: select id, user_name, password, age from user_t where id = ? 
  [com.ssmbase.dao.UserMapper.selectByPrimaryKey] - ==> Parameters: 1(Integer)
  [com.ssmbase.dao.UserMapper.selectByPrimaryKey] - <==      Total: 1
  [org.mybatis.spring.SqlSessionUtils] - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6ea0040e]
  [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
  com.ssmbase.domain.User@37d02427
[org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
  [org.mybatis.spring.SqlSessionUtils] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@41f59911] was not registered for synchronization because synchronization is not active
  [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
  [org.mybatis.spring.transaction.SpringManagedTransaction] - JDBC Connection [com.mysql.jdbc.JDBC4Connection@41ee0498] will not be managed by Spring
  [com.ssmbase.dao.UserMapper.selectByPrimaryKey] - ==>  Preparing: select id, user_name, password, age from user_t where id = ? 
  [com.ssmbase.dao.UserMapper.selectByPrimaryKey] - ==> Parameters: 1(Integer)
  [com.ssmbase.dao.UserMapper.selectByPrimaryKey] - <==      Total: 1
  [org.mybatis.spring.SqlSessionUtils] - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@41f59911]
  [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource

 

转载于:https://www.cnblogs.com/iaoc/p/5194993.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值