Boost Your MyBatis CRUD Efficiency with the MyBatis‑SQL‑Viewer Plugin
This article introduces the MyBatis‑SQL‑Viewer plugin, which transforms MyBatis XML into executable SQL, offers parameter mocking, syntax and compliance checks, index analysis, stress testing, and scanning features, dramatically simplifying CRUD development and improving SQL quality without restarting the application.
Introduction
The MyBatis‑SQL‑Viewer plugin provides capabilities such as converting MyBatis XML to real SQL statements, mocking parameters, checking SQL compliance and indexes, executing SQL, performing stress tests, and scanning MyBatis SQL across files and projects.
Why It Matters
Developing CRUD operations often involves repetitive problems: tedious SQL writing, frequent restarts after changes, difficulty creating realistic test data, uncertainty about compliance with SQL standards, index usage, performance metrics, and identifying slow queries. MyBatis users also face mismatched mapper methods, XML errors, and difficulty locating corresponding files.
Typical Development Pain
Traditional development requires multiple application restarts, making the experience cumbersome.
Plugin Capabilities
The plugin addresses the above issues during the coding phase:
SQL syntax errors no longer require a restart – the plugin validates syntax.
Multiple data‑mocking options automatically generate realistic test data, handling table relationships.
SQL compliance checks ensure adherence to standards.
Index checks and execution plans reveal which indexes are used.
Large‑scale data mock supports production‑like simulations.
Stress testing shows maximum TPS, potential slow SQL, and performance metrics.
Improved Development Workflow
The workflow follows guidelines from the Alibaba Java Development Manual (MySQL chapter).
Installation
IDEA: Preferences/Settings → Plugins → Marketplace → Search "mybatis sql viewer" → Install.
Manual: Download the latest ZIP from the releases page, then Preferences/Settings → Plugins → ⚙️ → Install plugin from disk.
Usage
Configure a data source (supports multiple) via the "datasource" button to fetch metadata and execute SQL.
Modes
The plugin offers two modes:
MyBatis mode : supports mapper method parameter mocking, random/default/custom parameters, navigation between mapper interfaces and XML files, file‑level scanning, and generation of real SQL.
Non‑MyBatis mode : disable MyBatis mode and write raw SQL in the "statement" tab.
MyBatis SQL Scanning
Scanning can be performed at file or project level.
File‑level: click the "sql" icon next to a namespace or mapper interface.
Project‑level: click the "mybatis sql scan" button to scan the entire project.
Scanning results list namespaces and methods; selecting a method displays the generated SQL, compliance checks, index analysis, and execution plan.
SQL Execution
Click the "result" tab to run the SQL. The output includes execution info, the EXPLAIN plan, and result rows (up to 100 rows for SELECT).
SQL Stress Testing
Configure stress tests in the "stress" tab, specifying value sources (direct SQL or parameter configuration), traffic models (constant rate increase or fixed concurrency), ramp‑up time, concurrency, and test duration. After configuration, click "stress" to run and view the report.
The report shows metrics such as request success rate, TP99/TP90, max/average RT, max/average TPS, concurrency, errors, and total requests, along with charts for success rate, average RT, and TPS.
SQL Table & Schema
The "table" tab parses SQL to extract table names and opens a tab for each table, displaying field information and schema compliance checks.
Index Inspection
The "index" tab shows index details and compliance results.
Data Mocking
Mock data can be generated in bulk. The left pane configures mock types (random, lexicon, database, increment, fixed, regex, none) and values; the right pane previews results. Supported random types include string, name, datetime, integer, decimal, date, timestamp, time, year, city, URL, email, IP, university, phone.
After preview, click "mock" to insert data (default 100 rows, configurable). Inserting 100 k rows takes under 10 seconds, enabling large‑scale mock.
Mock data can be cleaned via the "Clean" button, which removes inserted rows based on stored primary‑key ranges.
Configuration
Access plugin settings via Preferences/Settings → Tools → Mybatis Sql Viewer.
Project Repository
The source code is available at https://github.com/linyimin0812/mybatis-sql-viewer .
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
