Mybatis annotation development
L1 cache
@Test
public void testFindOne() {
SqlSession session = factory.openSession();
IUserDao userDao = session.getMapper(IUserDao.class);
User user = userDao.findById(55);
System.out.println(user);
session.close();//释放一级缓存
SqlSession session1=factory.openSession();//再次打开session(不同的了)
IUserDao userDao1=session1.getMapper(IUserDao.class);
User user1=userDao1.findById(55);
System.out.println(user1);
session1.close();
}
did it twice
Enable L2 cache
open by default
The original xml configuration requires the configuration file to be supported (the current dao, the operation must be supported
Now with the annotation, only one step
@CacheNamespace(blocking = true) is needed
to execute again
, and there are no two queries, which means that the second-level cache has been turned on