- Common ways to obtain PerformanceInterceptor
private void myMethod () {}
/** * mybatis-plus SQL执行效率插件【生产环境可以关闭】 */ @Bean public PerformanceInterceptor performanceInterceptor() { return new PerformanceInterceptor(); }
/** * mybatis-plus 性能分析拦截器<br> * 文档:http://mp.baomidou.com<br> */ @Bean public PerformanceInterceptor performanceInterceptor () { return new PerformanceInterceptor(); }
/** * mybatis-plus SQL执行效率插件【生产环境可以关闭】 */ @Bean @ConditionalOnProperty(name = "PROFILE", havingValue = "dev", matchIfMissing = true) public PerformanceInterceptor performanceInterceptor() { return new PerformanceInterceptor(); } }
/** * SQL执行效率插件 <br> * <p> * 参数:maxTime SQL 执行最大时长,超过自动停止运行,有助于发现问题。 * 参数:format SQL SQL是否格式化,默认false。 * <p> */ @Bean @Profile({"dev", "test"})// 设置 dev test 环境开启 public PerformanceInterceptor performanceInterceptor() { PerformanceInterceptor per = new PerformanceInterceptor(); per.setFormat(true); per.setMaxTime(10000);//10秒 return per; } }
@Bean("mybatisSqlSession") public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ResourceLoader resourceLoader, GlobalConfiguration globalConfiguration) throws Exception { MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean(); sqlSessionFactory.setDataSource(dataSource); MybatisConfiguration configuration = new MybatisConfiguration(); configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class); configuration.setJdbcTypeForNull(JdbcType.NULL); sqlSessionFactory.setConfiguration(configuration); sqlSessionFactory.setPlugins(new Interceptor[]{ new PaginationInterceptor(), new PerformanceInterceptor(), new OptimisticLockerInterceptor() }); sqlSessionFactory.setGlobalConfig(globalConfiguration); return sqlSessionFactory.getObject(); }