How to See the SQL MyBatis Actually Runs — by Scenario
"What SQL did MyBatis actually produce?" depends on where you are: before the code runs, while the app is running, or with nothing but a log in hand. Here is the right approach for each.
While coding: my Wrapper chain is long — what SQL will it produce?
No app launch needed. Click the preview icon on the Wrapper chain or Mapper method line — Wrapper → SQL preview statically resolves the call chain and renders the final SQL, with conditions toggleable and parameters fillable.
The log is full of ?: how do I get real parameters?
Runtime capture turns MyBatis logs into complete SQL: each ? is substituted with the actual value (LIKE gets its wildcards, quotes follow column types), and the same row carries duration, affected rows and jump-to-source. See turning question marks into real parameters for how it works.
Without p6spy
p6spy is not required. The no-p6spy guide compares the options; both SQL Visualizer routes (in-IDE capture and static preview) need no datasource changes or extra dependencies.
Legacy projects: iBatis 2.x or JPA / Hibernate
iBatis 2.x (sqlMap) preview renders #name# placeholders and 14 dynamic condition tags with official-engine semantics; JPA / Hibernate preview covers repository derived methods, JPQL / HQL, Criteria and .hbm.xml — the alternative when show_sql only prints question marks.
I have a SQL string: turn it into MyBatis-Plus code
The reverse works too: SQL to QueryWrapper converts a selected SQL into compilable Wrapper Java code, including joins, subqueries and aggregates.
Comparing all approaches
For a side-by-side of SQL Visualizer vs MyBatis-log-style plugins vs manual log reading, see the comparison page.