MyBatisPlus--性能分析插件

SpringMVC配置

mybatis-config.xml

<configuration>
    <!-- 性能分析插件 -->
    <plugins>
        <plugin interceptor="com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor">
            <!-- 最大的执行时间,单位为毫秒 -->
            <property name="maxTime" value="100"/>
            <!--SQL是否格式化 默认false-->
            <property name="format" value="true"/>
        </plugin>
    </plugins>
</configuration>

SpringBoot配置

/**
     * SQL执行效率插件
     */
    @Bean
    public PerformanceInterceptor performanceInterceptor() {
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        performanceInterceptor.setMaxTime(100);
        performanceInterceptor.setFormat(true);
        return performanceInterceptor;
    }

测试

	@Test
   public void testSelectList(){
      User user = new User();
      QueryWrapper<User> wrapper = new QueryWrapper<>();
      wrapper.gt("age", "1");//查询条件:age大于1
      List<User> users = user.selectList(wrapper);
      for (User u : users)
         System.out.println(u);
   }

控制台打印:

 Time:8 ms - ID:psers.zhang.demo.mapper.UserMapper.selectList
Execute SQL:
    SELECT
        id,
        user_name,
        password,
        name,
        age,
        email 
    FROM
        tb_user 
    WHERE
        age > '1'

User(id=2, userName=三狗, password=123456, name=李四, age=88, email=test2@qq.com, address=null)
User(id=4, userName=zhaoliu, password=123456, name=赵六, age=48, email=test4@qq.com, address=null)

发布了750 篇原创文章 · 获赞 2115 · 访问量 26万+

猜你喜欢

转载自blog.csdn.net/cold___play/article/details/104275864