如何在SpringBoot 中启用JPA和jdbcTemplate SQL日志

1. The purpose of this post

This demo show how to print SQL logs of your dao when using springboot apps.

2. Environments

  • SpringBoot 1.x and 2.x
  • Java 1.8+

3. JPA solution

Just add this to your application.properties

spring.jpa.show-sql=true

Then you would get this:

Hibernate: select student0_.id as id1_0_, student0_.branch as branch2_0_, student0_.email as email3_0_, student0_.name as name4_0_, student0_.percentage as percenta5_0_, student0_.phone as phone6_0_ from tbl_student student0_ limit ?

You can find detail document of this settings in Data Access of SpringBoot Reference.

4. JdbcTemplate solution

Just add this to your application.properties

logging.level.=ERROR
#or
logging.level.org.springframework.jdbc.core = TRACE
#or
logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG

Then you would get this:

2019-05-11 12:11:10.708 DEBUG 8852 --- [nio-8080-exec-1] o.s.jdbc.core.JdbcTemplate         
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值