mybatisplus----性能分析插件

性能分析插件


我们在平时的开发中,会遇到一些慢sql。测试!druid,..

 

作用:性能分析拦截器,用于输出每条SQL语句及其执行时间


MP也提供性能分析插件,如果超过这个时间就停止运行!

 

 

 

步骤:
1、导入插件

    @Bean//性能分析插件
    @Profile({"dev", "test"})
    public PerformanceInterceptor performanceInterceptor() {

        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        performanceInterceptor.setMaxTime(100);//设置最大执行时间是1毫秒,超过1毫秒则sql语句不执行
        performanceInterceptor.setFormat(true);//开启格式化支持(输出的sql更加清楚)

        return performanceInterceptor;
    }

 

配置文件中配置环境:

#配置性能分析插件(显示每一条sql语句,和他的执行时间)
spring.profiles.active=dev

 

 

 

 

 

 


2、测试使用!!

 

    @Test
    void contextLoads() {
        //继承了BaseMapper所有的方法都来自于父类,当然我们也可以定义自己的方法

        //参数wrapper是一个条件构造器
        List<User> users = userMapper.selectList(null);
        users.forEach(System.out::println);
    }

 

 

 测试结果:

 

posted @ 2020-11-13 17:14  Joker-0927  阅读(253)  评论(0编辑  收藏  举报
// 侧边栏目录