Mybatis一級快取

加瓦攻城獅發表於2017-11-20
@Transactional
public Student selectStudent(String stuId){    
    Student stu = new Student();    
    stu = studentMapper.selectByPrimaryKey(stuId);    
    stu = studentMapper.selectByPrimaryKey(stuId);    
    return stu;  
}複製程式碼

2017-11-20 10:22:59,517 [http-bio-8088-exec-6] DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'spring' processing GET request for [/spring-demo2/test/index1]2017-11-20 10:22:59,517 [http-bio-8088-exec-6] DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Looking up handler method for path /test/index12017-11-20 10:22:59,518 [http-bio-8088-exec-6] DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Returning handler method [public java.lang.String com.unionpay.ssyan.controller.HelloController.initIndex(org.springframework.ui.Model)]2017-11-20 10:22:59,518 [http-bio-8088-exec-6] DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'helloController'2017-11-20 10:22:59,519 [http-bio-8088-exec-6] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Last-Modified value for [/spring-demo2/test/index1] is: -12017-11-20 10:22:59,519 [http-bio-8088-exec-6] DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Creating new transaction with name [com.unionpay.ssyan.service.impl.HelloServiceImpl.selectStudent]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''2017-11-20 10:22:59,522 [http-bio-8088-exec-6] DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Acquired Connection [jdbc:mysql://172.21.22.175:60001/chmpldb2, UserName=cup_dba@172.20.6.7, MySQL Connector Java] for JDBC transaction2017-11-20 10:22:59,524 [http-bio-8088-exec-6] DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Switching JDBC Connection [jdbc:mysql://172.21.22.175:60001/chmpldb2, UserName=cup_dba@172.20.6.7, MySQL Connector Java] to manual commit2017-11-20 10:22:59,526 [http-bio-8088-exec-6] DEBUG [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession2017-11-20 10:22:59,526 [http-bio-8088-exec-6] DEBUG [org.mybatis.spring.SqlSessionUtils] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5e51f9]2017-11-20 10:22:59,527 [http-bio-8088-exec-6] DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] - JDBC Connection [jdbc:mysql://172.21.22.175:60001/chmpldb2, UserName=cup_dba@172.20.6.7, MySQL Connector Java] will be managed by Spring2017-11-20 10:22:59,528 [http-bio-8088-exec-6] DEBUG [com.unionpay.ssyan.dao.StudentMapper.selectByPrimaryKey] - ==> Preparing: select stu_id, score, stu_nm from tbl_chmpl_ssyan_test_stu where stu_id = ? 2017-11-20 10:22:59,528 [http-bio-8088-exec-6] DEBUG [com.unionpay.ssyan.dao.StudentMapper.selectByPrimaryKey] - ==> Parameters: 1111(String)2017-11-20 10:22:59,530 [http-bio-8088-exec-6] DEBUG [com.unionpay.ssyan.dao.StudentMapper.selectByPrimaryKey] - <== Total: 12017-11-20 10:22:59,531 [http-bio-8088-exec-6] DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5e51f9]=======================2017-11-20 10:24:38,244 [http-bio-8088-exec-6] DEBUG [org.mybatis.spring.SqlSessionUtils] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5e51f9] from current transaction2017-11-20 10:24:38,244 [http-bio-8088-exec-6] DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5e51f9]2017-11-20 10:24:38,244 [http-bio-8088-exec-6] DEBUG [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5e51f9]2017-11-20 10:24:38,245 [http-bio-8088-exec-6] DEBUG [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5e51f9]2017-11-20 10:24:38,245 [http-bio-8088-exec-6] DEBUG [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5e51f9]2017-11-20 10:24:38,245 [http-bio-8088-exec-6] DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Initiating transaction commit2017-11-20 10:24:38,253 [http-bio-8088-exec-6] DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Committing JDBC transaction on Connection [jdbc:mysql://172.21.22.175:60001/chmpldb2, UserName=cup_dba@172.20.6.7, MySQL Connector Java]2017-11-20 10:24:38,259 [http-bio-8088-exec-6] DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Releasing JDBC Connection [jdbc:mysql://172.21.22.175:60001/chmpldb2, UserName=cup_dba@172.20.6.7, MySQL Connector Java] after transaction2017-11-20 10:24:38,259 [http-bio-8088-exec-6] DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource2017-11-20 10:24:38,260 [http-bio-8088-exec-6] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'index'; URL [/WEB-INF/jsp/index.jsp]] in DispatcherServlet with name 'spring'2017-11-20 10:24:38,260 [http-bio-8088-exec-6] DEBUG [org.springframework.web.servlet.view.InternalResourceView] - Added model object 'stu' of type [java.lang.String] to request in view with name 'index'2017-11-20 10:24:38,260 [http-bio-8088-exec-6] DEBUG [org.springframework.web.servlet.view.InternalResourceView] - Forwarding to resource [/WEB-INF/jsp/index.jsp] in InternalResourceView 'index'2017-11-20 10:24:38,263 [http-bio-8088-exec-6] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request


如上日誌,可以看出兩次訪問相同的方法,傳如相同的引數,只進行了一次查詢,Fetched SqlSession從當前事務獲取相同session




























相關文章