springboot+mybatisplus打印xml中的sql
时间: 2023-12-11 08:03:52 浏览: 129
在使用 Spring Boot 和 Mybatis-Plus 进行开发时,可以通过配置 Mybatis-Plus 打印 SQL 语句的日志来查看 SQL 语句。具体步骤如下:
1. 在 application.properties 或 application.yml 中配置日志输出级别为 debug:
```
logging.level.com.baomidou.mybatisplus.mapper=debug
```
2. 在 Mybatis-Plus 中配置 SQL 输出日志的格式:
```
@Configuration
public class MybatisPlusConfig {
@Bean
public ConfigurationCustomizer configurationCustomizer() {
return configuration -> {
configuration.setLogImpl(StdOutImpl.class);
configuration.setLogFormat((sql, time) -> {
return "SQL: " + sql + "\n耗时:" + time + "ms";
});
};
}
}
```
在上面的配置中,我们将 SQL 的输出日志格式设置为 "SQL: " + sql + "\n耗时:" + time + "ms",其中 sql 表示 SQL 语句,time 表示 SQL 执行时间。我们还将日志输出的实现类设置为 StdOutImpl,表示将 SQL 输出到控制台中。
以上就是 Spring Boot 和 Mybatis-Plus 打印 SQL 语句的日志的配置方法。