mybatis增删改到底会不会刷新一级缓存?
测试代码:
public class MyTest {
private StudentDao studentDao;
private SqlSession sqlSession;
@Before
public void before(){
sqlSession = MyBatisUtils.getSqlSession();
studentDao = sqlSession.getMapper(StudentDao.class);//通过接口名 生成动态代理对象
/*将映射文件中<mapper/>标签的 namespace 属性设为 Dao 接口的全类名,则系统会根据方法所属 Dao 接口,
* 自动到相应 namespace 的映射文件中查找相关的 SQL 映射*/
}
@After
public void after(){
if(sqlSession!=null){
sqlSession.close();
}
}
@Test
public void testInsertStudent(){
Student student = studentDao.selectStudentById(5);
System.out.println(student);
Student student1 = new Student("小夏日", 14, 78.5);
studentDao.insertStudent(student1);
System.out.println("=============================");
Student student3 = studentDao.selectStudentById(5);
System.out.println(student3);
}
}
运行结果:[DEBUG] ==> Preparing: select id,name,age,score from student where id=?
[DEBUG] ==> Parameters: 5(Integer)
[TRACE] <== Columns: id, name, age, score
[TRACE] <== Row: 5, 张三, 23, 83.00
[DEBUG] <== Total: 1
Student [id=5, name=张三, age=23, score=83.0]
[DEBUG] ==> Preparing: insert into student(name,age,score) values(?,?,?)
[DEBUG] ==> Parameters: 小夏日(String), 14(Integer), 78.5(Double)
=============================
Student [id=5, name=张三, age=23, score=83.0]
这是我测试代码,如果增删改能刷新缓存,应该可以看到两个sql查询语句,为啥我只有一个
而且更匪夷所思的是我根本没有提交,插入的数据还能写入数据库,到底怎么回事,求大神解释
public class MyTest {
private StudentDao studentDao;
private SqlSession sqlSession;
@Before
public void before(){
sqlSession = MyBatisUtils.getSqlSession();
studentDao = sqlSession.getMapper(StudentDao.class);//通过接口名 生成动态代理对象
/*将映射文件中<mapper/>标签的 namespace 属性设为 Dao 接口的全类名,则系统会根据方法所属 Dao 接口,
* 自动到相应 namespace 的映射文件中查找相关的 SQL 映射*/
}
@After
public void after(){
if(sqlSession!=null){
sqlSession.close();
}
}
@Test
public void testInsertStudent(){
Student student = studentDao.selectStudentById(5);
System.out.println(student);
Student student1 = new Student("小夏日", 14, 78.5);
studentDao.insertStudent(student1);
System.out.println("=============================");
Student student3 = studentDao.selectStudentById(5);
System.out.println(student3);
}
}
运行结果:[DEBUG] ==> Preparing: select id,name,age,score from student where id=?
[DEBUG] ==> Parameters: 5(Integer)
[TRACE] <== Columns: id, name, age, score
[TRACE] <== Row: 5, 张三, 23, 83.00
[DEBUG] <== Total: 1
Student [id=5, name=张三, age=23, score=83.0]
[DEBUG] ==> Preparing: insert into student(name,age,score) values(?,?,?)
[DEBUG] ==> Parameters: 小夏日(String), 14(Integer), 78.5(Double)
=============================
Student [id=5, name=张三, age=23, score=83.0]
这是我测试代码,如果增删改能刷新缓存,应该可以看到两个sql查询语句,为啥我只有一个
而且更匪夷所思的是我根本没有提交,插入的数据还能写入数据库,到底怎么回事,求大神解释
...全文
相关推荐
mybatis一级缓存和二级缓存简单示例
配套博客内容,mybatis一级缓存和二级缓存简单示例,供初学童鞋予以参考。 博客地址 https://blog.csdn.net/magi1201/article/details/85524712
深入理解MyBatis中的一级缓存与二级缓存
主要给大家深入的介绍了关于MyBatis中一级缓存与二级缓存的相关资料,文中详细介绍MyBatis中一级缓存与二级缓存的工作原理及使用,对大家具有一定的参考性学习价值,需要的朋友们下面来一起看看吧。
MyBatis 二级缓存 关联刷新实现
MyBatis 二级缓存 关联刷新实现1、MyBatis缓存介绍2、二级缓存问题2.1、数据不一致问题验证2.2、问题处理思路3、关联缓存刷新实现 1、MyBatis缓存介绍 Mybatis提供对缓存的支持,但是在没有配置的默认情况下,它只开启一级缓存,二级缓存需要手动开启。 一级缓存只是相对于同一个SqlSession而言。也就是针对于同一事务,多次执行同一Mapper的相同查询方法,第一查询后,MyBatis会将查询结果放入缓存,在中间不涉及相应Mapper的数据更新(Insert,Update和Delete)操作的情况下,后续的查询将会从缓存中获取,而不会查询数据库。
MyBatis缓存(一级缓存、二级缓存)
MyBatis缓存(一级缓存、二级缓存)
MyBatis一级缓存避坑完全指南
主要给大家介绍了关于MyBatis一级缓存避坑的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧


