SoFunction
Updated on 2025-03-03

Two implementation methods for printing SQL statements on Mybatis console

Problem description

When using mybatis for development, it is very convenient for us to dynamically splice SQL.

But there are also certain problems. When we have a lot of dynamic SQL splicing blocks, it will be very difficult for us to directly find the complete SQL from *. At this time, it is often better to debug the complete SQL after the combination.

Here are two ways to debug SQL

Solution

Plan 1

1: First, adjust the ibatis log4j run level to DEBUG, and print out the sql statements running on the console.

2: Add the following statement:

###Show SQL statement part=DEBUG
=DEBUG
=DEBUG
=DEBUG
=DEBUG
=DEBUG
=DEBUG

Plan 2

Add the following configurations:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-////DTD SQL Map Config 3.0//EN"
"/dtd/">
 
<configuration>
    <settings>
<setting name="logImpl" value="STDOUT_LOGGING" />
  </settings>
</configuration>

The above two ways to debug SQL from mybatis.

In SpringBoot, modify the file

mybatis:
configuration:
log-impl: 

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.