Mybatis学习第14节 -- 一级缓存被刷新的情况

测试

@Test
public void testCacheLevelOne1() {
SqlSession session = MyBatisUtil.getSqlSession();
ShopMapper mapper = session.getMapper(ShopMapper.class);
Shop shop = mapper.getShopById(1);
System.out.println(shop);
// update
shop.setName("new "+shop.getName());
mapper.updateShopBySet(shop);


// session = MyBatisUtil.getSqlSession();
// mapper = session.getMapper(ShopMapper.class);
// // select again
System.out.println(mapper.getShopById(1));
session.close();
}
结果
2018-12-28 17:10:40,900 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.getShopById] - ==> Preparing: select * from tb_shop where `shop_id` = ? 
2018-12-28 17:10:41,106 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.getShopById] - ==> Parameters: 1(Integer)
2018-12-28 17:10:41,296 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.getShopById] - <== Total: 1
Shop{id=1, ownerId=1, areaId=3, categoryId=14, name='new 正式店铺名称', desc='测试描述', addr='正式地址', phone='13810524086', image='/upload/item/shop/1/2017091621545314507.jpg', priority=10, createTime=2017-08-03, lastEditTime=2017-09-16, enableStatus=0, advice='审核中'}

2018-12-28 17:10:41,427 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.updateShopBySet] - ==> Preparing: UPDATE `tb_shop` SET `shop_name` = ?, `shop_desc` = ? WHERE `shop_id` = ? ; 
2018-12-28 17:10:41,435 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.updateShopBySet] - ==> Parameters: new new 正式店铺名称(String), 测试描述(String), 1(Integer)
2018-12-28 17:10:41,446 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.updateShopBySet] - <== Updates: 1
2018-12-28 17:10:41,447 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.getShopById] - ==> Preparing: select * from tb_shop where `shop_id` = ? 
2018-12-28 17:10:41,447 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.getShopById] - ==> Parameters: 1(Integer)
2018-12-28 17:10:41,454 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.getShopById] - <== Total: 1
Shop{id=1, ownerId=1, areaId=3, categoryId=14, name='new new 正式店铺名称', desc='测试描述', addr='正式地址', phone='13810524086', image='/upload/item/shop/1/2017091621545314507.jpg', priority=10, createTime=2017-08-03, lastEditTime=2017-09-16, enableStatus=0, advice='审核中'}
 
结论
虽然进行了更新, 但是没有提交, 但是缓存还是被flush了
posted @ 2019-03-17 10:46  不怕旅途多坎坷  阅读(287)  评论(0编辑  收藏  举报