springboot下mybatisplus开启打印sql日志怎么配置

作者:有用网 阅读量:375 发布时间:2023-07-07
关键字 mybatis springboot

本文小编为大家详细介绍“springboot下mybatisplus开启打印sql日志怎么配置”,内容详细,步骤清晰,细节处理妥当,希望这篇“springboot下mybatisplus开启打印sql日志怎么配置”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

需要以下三个配置

1:设置mybatisplus包下的日志级别为DEBUG;

logging:
  level:
    com:
      baomidou:
        mybatisplus: DEBUG

2:设置项目mapper目录(dao包路径)的日志级别为DEBUG;

logging:
  level:
    com:
      xxx: 
        xxx
         xxx: DEBUG

3:设置mybatis-plus的日志输出方式为slf4j。

mybatis-plus:
  #mapper-locations: classpath*:/mappings/**/*.xml
  configuration:
    log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl

附:关闭打印

在生产环境,不想打印 SQL 日志,可以通过下面的配置关闭。

mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl

对于 application.properties 文件

mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.nologging.NoLoggingImpl

有时候,这个 log-impl 的值是通过外界传入的,通过配置的形式控制 SQL 打印效果,则可以:

mybatis-plus:
  configuration:
    log-impl: ${mybatis-plus-log-impl}

${mybatis-plus-log-impl} 不同的值就能实现。


#发表评论
提交评论