🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
**1.测试代码** ~~~ @Test public void testCache(){ UserMapper mapper = session.getMapper(UserMapper.class); User u1 = mapper.findById(15); User u2 = mapper.findById(15); System.out.println(u1); System.out.println(u2); } ~~~ 返回结果 com.nobb.domain.User@70e8f8e com.nobb.domain.User@70e8f8e **2.测试代码** ~~~ @Test public void fun2(){ UserMapper mapper = session.getMapper(UserMapper.class); User u1 = mapper.findById(15); //关闭session 缓存清空 session.close(); session = SqlSessionUtils.openSession(); mapper = session.getMapper(UserMapper.class); User u2 = mapper.findById(15); System.out.println(u1); System.out.println(u2); } ~~~ 运行结果 com.nobb.domain.User@17046283 com.nobb.domain.User@5bd03f44 **3.测试代码** ~~~ @Test public void fun3(){ UserMapper mapper = session.getMapper(UserMapper.class); User u1 = mapper.findById(15); User u = new User(); u.setId(15); u.setName("test"); u.setPassword("111"); //执行了更新,清空了缓存 mapper.update(u); User u2 = mapper.findById(15); System.out.println(u1); System.out.println(u2); } ~~~