hu112224 hu112224
关注数: 25 粉丝数: 61 发帖数: 1,196 关注贴吧数: 39
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语句,为啥我只有一个 而且更匪夷所思的是我根本没有提交,插入的数据还能写入数据库,到底怎么回事,求大神解释
1 下一页