Every Java codebase I have worked on that uses MyBatis-Plus has the same small loop in it. You change one condition, and then you need to know what the change actually produced.

LambdaQueryWrapper<User> qw = Wrappers.lambdaQuery(); qw.eq(StringUtils.isNotBlank(req.getUsername()), User::getUsername, req.getUsername()) .ge(req.getCreatedFrom() != null, User::getCreatedAt, req.getCreatedFrom()) .orderByDesc(User::getId); userMapper.selectPage(page, qw); 

Three things are uncertain here, and none of them are visible in the code:

  • whether the username condition is in the statement at all, since it depends on a runtime value;
  • whether the logical-delete column was appended, and where in the WHERE clause;
  • what the paging count query looks like next to the LIMIT query.

So you restart the app, send one request, scroll to the console, find Preparing: SELECT ... WHERE username = ?, then read the Parameters: line below it and match placeholders to values by position. With three parameters that is fine. With twelve it is a manual diff. Do it fifteen times a day and the edit-run-read loop starts to cost more than the edit.

The formatting is the easy part. What makes this hard is that the SQL doesn't exist until several layers have run: the Wrapper builder, the ORM's dialect handling, logical-delete injection, paging. By the time you can read the statement, you have already paid for a restart.

Three approaches show up in practice. They answer different questions rather than competing.

1. Restore the statement from logs

The oldest one. The app is already printing Preparing: and Parameters: lines; a tool joins them into one executable statement. You get exactly the SQL that ran, with the values that ran. It costs you a running app with SQL logging on, and it only works while those two lines keep being printed. Change the log level, hit a framework that logs at DEBUG, or use a driver that formats parameters differently, and the join falls apart. The plugin family around this — MyBatis Log and its free edition, and similar — has been doing that job for years and does it well.

2. Preview the statement while coding

This one parses your source and renders the statement without starting anything. Boolean first arguments like StringUtils.isNotBlank(...) become switches you can flip; parameters you type in are bound with their real types; conditions you leave empty stay as ?. All it needs is the IDE. What it cannot do is decide branches by data, know values that only exist at runtime, or show anything the parser cannot prove.

That distinction is easy to miss. A static preview is a claim about your code, not a measurement of your database. Constants get inlined in the preview while the ORM still binds them as placeholders at execution, so the text can differ from what actually runs even when the semantics match.

3. Capture at the JDBC layer while the app runs

The third one attaches a small agent to your application's JVM and records what actually crosses the JDBC boundary: real parameters, milliseconds, affected rows, the error if there was one, and the call stack that led there. You get measurements instead of predictions. The tradeoff is that it says nothing about code paths that never executed, and it needs a one-time authorization inside the IDE.

I use all three, depending on where I am in the loop. Reading a colleague's Wrapper in review: preview. Chasing a slow endpoint: capture. Reconstructing what a production log line meant: restore.

Where they meet

Full disclosure: I'm the author of the plugin I describe below, MyBatis SQL Visualizer. I built it because I kept switching between the three modes and wanted one place to do it.

The static side works from the gutter icon next to the statement, or Alt+Shift+Q. Dynamic conditions come in as checkboxes, so you can see the difference between "username present" and "username absent" without editing the code twice. Values are typed in per parameter, LIKE patterns get their %, and anything you leave blank stays a placeholder. Each statement keeps its own named presets, which is the part I use most: the same Wrapper with three different parameter sets is three saved states instead of three edits.

Wrapper preview: conditions as checkboxes, parameters filled in, SQL re-rendered on the right

It covers more than MyBatis-Plus Wrapper chains: MPJ joins, mapper XML with dynamic tags, annotation SQL, JdbcTemplate strings, iBatis 2.x sqlMap statements, and statically derivable JPA / Hibernate queries (derived methods, JPQL, Criteria, Specification, HQL) all render through the same panel.

The runtime side is where the interesting part is. The capture channel works at the JDBC layer rather than parsing console text, so durations and affected rows are measured, not regexed out of a log line. Entries can be filtered to slow queries only, and structurally identical statements are clustered, which is how a loop that queries one table per iteration becomes visible as one row with a count instead of two hundred rows you scroll past.

SQL log entry jumping back to the Java line that executed it, with the call stack expanded

From an entry you can jump to the Java line or the mapper XML, expand the call stack frame by frame, and focus the list by method or by request. The position comes from the captured stack, so there is nothing to configure.

The third piece is the one that surprised me in practice: once you can read the final SQL, you also want to go back. Select a statement, press Alt+Shift+J, and it generates a MyBatis-Plus Wrapper chain, choosing the calling class and return type. Joins, GROUP BY, HAVING, DISTINCT, FOR UPDATE and aggregate expressions are handled; structures that cannot map cleanly are passed through as apply() with a note explaining why, rather than silently producing something that looks right and is not.

SQL to Java: generating a Wrapper chain and picking the calling class

There is also an MCP surface: 11 read-only tools registered on IDEA's built-in MCP Server, so an AI client can ask the plugin to render a statement from source, fetch table and column metadata, run an EXPLAIN, or search local SQL history, instead of guessing column names. Tools that generate SQL never execute it, and the EXPLAIN tool validates its input as a read-only query.

Installing it

Marketplace: search for MyBatis SQL Visualizer, or use the plugin page. It is free, Apache-2.0, no ads, no account. The plugin does not send usage data anywhere; static preview, log restoration, code conversion and diagrams run locally.

Requirements:

  • IntelliJ IDEA 2024.3 or later.
  • Community Edition covers static preview, log capture and SQL-to-Java. Executing a statement and opening EXPLAIN go through IDEA's database console, which needs Ultimate with Database Tools.
  • The MCP tools need IDEA 2025.2 or later with a working MCP Server.

What it does not do

  • It is not an APM. No distributed tracing, no dashboards, no aggregation across machines. It watches the JVM you are running locally.
  • Kotlin Wrapper chains are not reliably reconstructable today. The plugin does not show a preview icon for them and does not invent SQL when you trigger the action directly; it tells you why.
  • A static preview is not a measurement. Runtime branches, database contents and values that cannot be evaluated need your input, and the text can differ from the executed statement in ways that do not change the semantics.
  • EXPLAIN coverage is 14 of the 15 supported dialects; GoldenDB has no plan entry yet. Verification depth differs per database and is documented per engine rather than averaged into one claim.
  • Restoring UPDATE / DELETE statements does not produce a rollback script out of thin air. The plugin cannot know pre-image values it never saw; it offers to query a snapshot first and fill the result in.

If any of that is a dealbreaker for your setup, it probably is. The docs say the same thing.

Links

If you try it and something breaks, the issue tracker and the feedback pool are where it gets fixed. The comparison page on the docs site also lists the other plugin families by what they are for, in case a different one fits your workflow better.

(I maintain this plugin. Capability and boundary statements above follow the project documentation.)