MyBatisPlus--性能分析插件

SpringMVC配置

mybatis-config.xml

<configuration>
    
    <plugins>
        <plugin interceptor="com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor">
            
            <property name="maxTime" value="100"/>
            
            <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)

你可能感兴趣的:(MyBatisPlus)