1.开启二级缓存
config/SqlMapConfig.xml
<span style="white-space:pre"> </span><settings>
<setting name="lazyLoadingEnabled" value="true" />
<setting name="aggressiveLazyLoading" value="false" />
<strong><!-- 开启二级缓存 -->
<setting name="cacheEnabled" value="true" /></strong>
</settings>
test单元测试
// 二级缓存测试
@Test
public void testCache1() throws Exception{
SqlSession sqlSession1 = sqlSessionFactory.openSession();
SqlSession sqlSession2 = sqlSessionFactory.openSession();
SqlSession sqlSession3 = sqlSessionFactory.openSession();
UserMapper userMapper1 = sqlSession1.getMapper(UserMapper.class);
// 第一次发起请求
User user1 = userMapper1.findUserById(1);
System.out.println