首页 > 其他 > 详细

mybatis缓存介绍

时间:2016-01-08 20:17:12      阅读:122      评论:0      收藏:0      [点我收藏+]

原文地址: http://www.cnblogs.com/selene/p/4638648.html

一级缓存示例:

 1 public static void main(String[] args){
 2         String resource = "mybatis-config.xml";
 3         try {
 4             Reader reader = Resources.getResourceAsReader(resource);
 5             SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(reader);
 6             SqlSession sqlSession  = sqlSessionFactory.openSession();
 7             AccountDao accountDao = sqlSession.getMapper(AccountDao.class);
 8 
 9             Account account = accountDao.selectById(1);
10             Account account1 = accountDao.selectById(1);
11             sqlSession.commit();
12             Account account2 = accountDao.selectById(1);
13         } catch (IOException e) {
14             e.printStackTrace();
15         }
16     }

mysql执行日志:

技术分享

可以看到,方法调用了三次,但SQL语句只执行了两次,第二次调用查询的时候取的是缓存

mybatis缓存介绍

原文:http://www.cnblogs.com/stefanking/p/5114254.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!