springbootjpa实现sql拦截的方式很简单,只要实现 StatementInspector 接口既可以。
package com
.zsh
.masterdata
.config
;
import org
.hibernate
.resource
.jdbc
.spi
.StatementInspector
;
public class JpaStatementInspector implements StatementInspector {
@Override
public String
inspect(String s
) {
System
.out
.println("sql拦截器:-------------");
System
.out
.println(s
);
return s
;
}
}
application.yml中加入配置
spring:
jpa:
properties:
hibernate:
session_factory:
statement_inspector: com.zsh.masterdata.config.JpaStatementInspector