-
pom.xml:
<dependency> <groupId>p6spy</groupId> <artifactId>p6spy</artifactId> <version>3.8.0</version> </dependency>
spring: datasource: driver-class-name: org.h2.Driver url: jdbc:h2:tcp://192.168.180.115:19200/~/mem/test username: root password: test mybatis-plus: global-config: db-config: id-type: id_worker capital-mode: true configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
-
spy.properties 配置:
module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory # 自定义日志打印 logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger #日志输出到控制台 appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger # 使用日志系统记录 sql #appender=com.p6spy.engine.spy.appender.Slf4JLogger # 设置 p6spy driver 代理 deregisterdrivers=true # 取消JDBC URL前缀 useprefix=true # 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset. excludecategories=info,debug,result,batch,resultset # 日期格式 dateformat=yyyy-MM-dd HH:mm:ss # 实际驱动可多个 #driverlist=org.h2.Driver # 是否开启慢SQL记录 outagedetection=true # 慢SQL记录标准 2 秒 outagedetectioninterval=2
-
配置类,官网已经弃用了插件,推荐使用P6spy
@Configuration public class MybatisPlusConfig { // 该插件 3.1.2 后版本废弃,推荐使用 // @Bean // public PerformanceInterceptor performanceInterceptor(){ // //启用性能分析插件 // return new PerformanceInterceptor(); // } }
-
实体类
@Data @TableName(value = "student") public class Student { private Long id; private String name; private Integer age; } @Mapper public interface StudentMapper extends BaseMapper<Student> { }
-
测试类
@SpringBootTest class EanalysisApplicationTests { @Autowired private StudentMapper studentMapper; @Test public void test(){ studentMapper.selectList(new QueryWrapper<>()); } }
-
测试结果
2019-10-30 16:15:22.235 INFO 11508 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. Consume Time:7 ms 2019-10-30 16:15:22 Execute SQL:SELECT id,name,age FROM student 2019-10-30 16:15:22.328 INFO 11508 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource