springboot+mybatis-plus在log控制台输出sql语句的方法

时间:2025-04-28 07:25:20

有两种方法可以实现

1.第一种将log-impl 配置到原有的mybatis-plus的configuration下(格式为yml的规范),该方法会将sql语句和查询的结果都打印到控制台

mybatis-plus:

    configuration: 

       # 是否将sql打印到控制面板(该配置会将sql语句和查询的结果都打印到控制台)

       log-impl:

 

2.第二种为只打印sql语句和入参数据的配置

  2.1 yml规范的写法(其中 cn:shangze:boot:modules:oa:mapper为MyBatis接口 interface包的路径)

# 日志
logging:
  file: logs/
  level:
    cn:
      shangze:
        boot:
          modules:
            oa:
              mapper: debug

2.2 如果使用 规范的写法为

    =debug   #其中 为MyBatis接口interface包的路径