如果有异常则不打印SQL

只需要在yml 里配置了这些就可以了。记得 下面的包名 要正确才行,否则 无法打印日志

# 日志
logging:
  level:
    com:
      giant:
        mapper: DEBUG

Properties

# Mybatis配置
# 这个似乎导致报错 mybatis.mapper-locations=classpath*:com/aaaa/bbbb/mapper/*.xml
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
logging.level.com.aaaa.bbbb.mapper=error
完整样式
有效日志

发现上面日志 依旧看不清晰 那就以代码形式看吧 下面是我复制的日志案例

==>  Preparing: select id, nickname, telphone, email, `password`, viplevel, create_time, create_type, account_status, is_store, is_govbuyweb, unuse1, unuse2 from user_account WHERE telphone=? and `password`=? 
==> Parameters: 18094266339(String), 3ad7f76cafd518c0836fbb68bc7f9a45(String)
<==      Total: 1

================================================================

下面还有

================================================================

为了看到更全的日志,还是建议开启:下面yml 代码

#mybatis的配置
mybatis:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    mapper-locations: classpath*:com/giant/mapper/*.xml

记得包名要与你自己项目的包正确

然后 直接 请求一次 你就可以看到如下日志了

Creating a new SqlSession
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ae36eb8]
JDBC Connection [HikariProxyConnection@529357847 wrapping com.mysql.jdbc.JDBC4Connection@183fd1b] will be managed by Spring
2021-02-03 17:26:02.929 DEBUG 30464 --- [nio-8866-exec-1] c.g.mapper.UserAccountMapper.findByAll   : ==>  Preparing: select id, nickname, telphone, email, `password`, viplevel, create_time, create_type, account_status, is_store, is_govbuyweb, unuse1, unuse2 from user_account WHERE telphone=? and `password`=? 
2021-02-03 17:26:02.944 DEBUG 30464 --- [nio-8866-exec-1] c.g.mapper.UserAccountMapper.findByAll   : ==> Parameters: 18094266339(String), 3ad7f76cafd518c0836fbb68bc7f9a45(String)
2021-02-03 17:26:02.969 DEBUG 30464 --- [nio-8866-exec-1] c.g.mapper.UserAccountMapper.findByAll   : <==      Total: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ae36eb8]
Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ae36eb8]
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ae36eb8]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ae36eb8]

黄色 即开启 Mybatis配置 所看到的日志信息

特殊说明:
上述文章均是作者实际操作后产出。烦请各位,请勿直接盗用!转载记得标注原文链接:www.zanglikun.com
第三方平台不会及时更新本文最新内容。如果发现本文资料不全,可访问本人的Java博客搜索:标题关键字。以获取最新全部资料 ❤