mybatis plus sql性能分析插件

在MybatisPlusConfig 加入sql性能分析插件

一、 mybatis-plus自带的性能分析

/**

  • SQL执行效率插件 性能分析插件

*/

@Bean

@Profile({“dev”,“test”})// 设置 dev test 环境开启

public PerformanceInterceptor performanceInterceptor() {

PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();

performanceInterceptor.setFormat(true);//格式化语句

//performanceInterceptor.setMaxTime(5);//执行时间超过多少秒会抛出异常

return performanceInterceptor;

}

执行sql打印

/**

  • 插入一行user

  • 执行时间50毫秒

  • Time:50 ms - ID:com.hlvy.mybatis_plus.mapper.UserMapper.selectById

  • Execute SQL:SELECT id,name,age,email,manager_id,created_time,update_time,version FROM User WHERE id=5 AND deleted=0

*/

@Test

public void insertUser() {

System.out.println((“----- insertUser method test ------”));

User user = new User();

user.setName(“恒果果”);

user.setAge(19);

user.setEmail(“[email protected]”);

int row = userMapper.insert(user);

System.out.println(“插入成功”+row+“行”);

}

二、p6spy性能分析插件 该功能依赖 p6spy 组件,完美的输出打印 SQL 及执行时长 3.1.0 以上版本

  • p6spy 依赖引入

你可能感兴趣的:(程序员,mybatis,sql,android)