在MyBatis的Builder模式中,可以通过cacheEnabled()
方法来设置缓存。具体的代码示例如下:
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
Configuration configuration = sessionFactory.getConfiguration();
configuration.setCacheEnabled(true);
通过以上代码,可以在MyBatis中启用缓存。需要注意的是,需要在创建SqlSessionFactory实例之后,但在创建SqlSession实例之前调用setCacheEnabled(true)
方法来设置缓存。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:MyBatis的Builder模式中,如何设置插件