Mybatis annotation development uses the second level cache

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
insert image description here

Enable L2 cache

insert image description here
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
insert image description here
to execute again
insert image description here
, and there are no two queries, which means that the second-level cache has been turned on

Guess you like

Origin blog.csdn.net/weixin_42727032/article/details/104548435