赞
踩
- @Test
- public void getEmpByEmpIdTest(){
- SqlSession sqlSession1 = SqlSessionUtil.getSqlSession();
- CacheMapper mapper1 = sqlSession1.getMapper(CacheMapper.class);
- //此处用的是同一个Sqlsession
- Emp emp1 = mapper1.getEmpByEmpId(1);//第一条emp1
- System.out.println(emp1);
- Emp emp2 = mapper1.getEmpByEmpId(1);//第二条emp2
- System.out.println(emp2);
- }
一级缓存失效情况
- @Test
- public void testgetEmpByEid2(){
- SqlSession sqlsession1 = SQLsession.getSqlsession();
- CacheMapper mapper1 = sqlsession1.getMapper(CacheMapper.class);
- Emp empByEid1 = mapper1.getEmpByEid(1);
- System.out.println(empByEid1);
- SqlSession sqlsession2 = SQLsession.getSqlsession();
- CacheMapper mapper2 = sqlsession2.getMapper(CacheMapper.class);
- Emp empByEid2 = mapper2.getEmpByEid(1);
- System.out.println(empByEid2);
- }
- @Test
- public void testgetEmpByEid3(){
- SqlSession sqlsession = SQLsession.getSqlsession();
- CacheMapper mapper = sqlsession.getMapper(CacheMapper.class);
- Emp empByEid1 = mapper.getEmpByEid(1);
- System.out.println(empByEid1);
- mapper.insertEmp(new Emp(null,"sdd",12,"1","1",null));
- Emp empByEid2 = mapper.getEmpByEid(1);
- System.out.println(empByEid2);
- }
- @Test
- public void testTwoCache(){
- //不能使用工具类的形式创建SQLsession
- try {
- InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
- SqlSessionFactory builder = new SqlSessionFactoryBuilder().build(in);
- SqlSession sqlSession1 = builder.openSession(true);
- CacheMapper mapper1 = sqlSession1.getMapper(CacheMapper.class);
- System.out.println(mapper1.getEmpByEid(1));
- sqlSession1.close();
- SqlSession sqlSession2 = builder.openSession(true);
- CacheMapper mapper2 = sqlSession2.getMapper(CacheMapper.class);
- System.out.println(mapper2.getEmpByEid(1));
- sqlSession2.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。