java 控制台展示带参数的完整SQL语句

tech2022-10-17  107

hibernate打印的sql默认是带占位符的,参数需要自己拼接 p6spy可以展示完整语句 pom:

<dependency> <groupId>p6spy</groupId> <artifactId>p6spy</artifactId> <version>3.7.0</version> </dependency>

新建spy.properties,放到resources目录下。 文件内容:

driverlist=com.mysql.jdbc.Driver module.log=com.p6spy.engine.logging.P6LogFactory appender=com.p6spy.engine.spy.appender.Slf4JLogger #自定义日志格式 logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat #格式:%(currentTime)|%(executionTime)|%(category)|connection%(connectionId)|%(sqlSingleLine) customLogMessageFormat=%(category)|conn%(connectionId)|%(sqlSingleLine) databaseDialectDateFormat=yyyy-MM-dd HH:mm:ss databaseDialectTimestampFormat=yyyy-MM-dd HH:mm:ss dateformat=yyyy-MM-dd HH:mm:ss

数据库连接池: application.yml文件

spring: datasource: driver-class-name: com.p6spy.engine.spy.P6SpyDriver url: jdbc:p6spy:mysql://192.168.0.0:3316/my_database?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=CTT

效果:

2019-09-26 17:04:26.042 [http-apr-8080-exec-6] INFO p6spy - statement|conn2| SELECT name,age,id FROM Xxx WHERE id=11
最新回复(0)