[Java] 纯文本查看 复制代码
@Test
public void testCache2() throws Exception {
SqlSession sqlSession1 = sqlSessionFactory.openSession();
SqlSession sqlSession2 = sqlSessionFactory.openSession();
// 创建代理对象
UserMapper userMapper1 = sqlSession1.getMapper(UserMapper.class);
// 第一次发起请求,查询id为1的用户 从数据库中查询
User user1 = userMapper1.findUserById(1);
System.out.println(user1);
sqlSession1.close();
// 创建代理对象
UserMapper userMapper2 = sqlSession2.getMapper(UserMapper.class);
// 第二次发起请求,查询id为1的用户 从二级缓存中查询
User user2 = userMapper2.findUserById(1);
System.out.println(user2);
sqlSession2.close();
}