SpringBoot+JPA打印sql日志和sql参数
pom.xml 添加lombox依赖:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
application.yml 配置:
jpa:
show-sql: true #打印执行的sql语句,false则不打印sql
database-platform: org.hibernate.dialect.MySQL5Dialect
在原logback.xml 配置上新增以下配置:
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" />
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor" level="DEBUG" />
<logger name="org.hibernate.SQL" level="DEBUG" />
<logger name="org.hibernate.type" level="info" />
<logger name="org.hibernate.engine.spi.QueryParameters" level="DEBUG" />
<logger name="org.hibernate.engine.query.spi.HQLQueryPlan" level="DEBUG" />