【发布时间】:2016-03-08 04:25:01
【问题描述】:
spring boot项目,使用JdbcTemplate,想显示执行的sql,配置如下
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
但是没有输出,上面的配置好像只支持spring data jpa,所以我想知道是否存在某种方式可以显示sql甚至直接使用JdbcTemplate?
【问题讨论】:
spring boot项目,使用JdbcTemplate,想显示执行的sql,配置如下
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
但是没有输出,上面的配置好像只支持spring data jpa,所以我想知道是否存在某种方式可以显示sql甚至直接使用JdbcTemplate?
【问题讨论】:
该属性被命名为spring.jpa something 是有原因的:这是为了表明它以某种形式与 JPA 相关。
如果您使用JdbcTemplate,则说明您没有使用 JPA,因此该属性不会产生任何影响。您可以为 org.springframework.jdbc.core.JdbcTemplate 类启用日志记录
logging.level.org.springframework.jdbc.core.JdbcTemplate=debug
【讨论】:
2016-03-11 18:57:00.168 DEBUG 19587 --- [ restartedMain] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL statement [select mobile, max(total_amount) total_amount from user_draw_log where total_amount > 0 group by mobile order by max(total_amount) desc limit ?, ?;]