方法一:

在application.properties文件增加以下配置,实现打印sql语句,推荐方法二

#是否显示sql
spring.jpa.show-sql=true
#是否格式化sql脚本
spring.jpa.properties.hibernate.format_sql=true
#是否在 SQL 语句中输出便于调试的注释信息
spring.jpa.properties.hibernate.use_sql_comments=true
#打印sql脚本的参数变量的值
logging.level.hibernate.type.descriptor.sql.BasicBinder=TRACE

方法二:

如果整合了阿里的druid,可以在application.properties文件增加以下配置,实现对sql语句的打印,一般用来打印慢查询语句

#起开sql统计
spring.datasource.druid.filter.stat.enabled=true
#使用的数据库类型
spring.datasource.druid.filter.stat.db-type=mysql
#是否打印慢查询sql脚本
spring.datasource.druid.filter.stat.log-slow-sql=true
#慢查询的时间,超过该时间才打印,单位毫秒
spring.datasource.druid.filter.stat.slow-sql-millis=1000

更多推荐

springboot配置日志打印sql语句