Databases 13 min read

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.

macrozheng
macrozheng
macrozheng
Boost Your MyBatis CRUD Efficiency with the MyBatis‑SQL‑Viewer Plugin

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.

mybatis-sql-viewer能力
mybatis-sql-viewer能力

Improved Development Workflow

基于mybatis-sql-viewer插件的开发流程
基于mybatis-sql-viewer插件的开发流程

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.

Data source configuration
Data source configuration

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.

Mode selection
Mode selection

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.

File dimension scanning
File dimension scanning
Project dimension scanning
Project dimension scanning

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).

Result tab
Result tab

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.

Stress configuration
Stress configuration
Stress report
Stress 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.

Specify table tab
Specify table tab

Index Inspection

The "index" tab shows index details and compliance results.

Index tab
Index tab

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.

Mock preview
Mock preview

After preview, click "mock" to insert data (default 100 rows, configurable). Inserting 100 k rows takes under 10 seconds, enabling large‑scale mock.

Mock result
Mock result

Mock data can be cleaned via the "Clean" button, which removes inserted rows based on stored primary‑key ranges.

Mock clean
Mock clean

Configuration

Access plugin settings via Preferences/Settings → Tools → Mybatis Sql Viewer.

Configuration
Configuration

Project Repository

The source code is available at https://github.com/linyimin0812/mybatis-sql-viewer .

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Performance TestingMyBatismock dataSQL ViewerDatabase Tool
macrozheng
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.