Databases 11 min read

Boost MyBatis Development: Convert XML to Real SQL, Mock Data & Stress Test

The MyBatis‑SQL‑Viewer plugin transforms MyBatis XML into executable SQL, offers mock data generation, SQL syntax and compliance checks, index analysis, performance stress testing, and seamless navigation between mapper interfaces and XML files, all without restarting the application.

Java Interview Crash Guide
Java Interview Crash Guide
Java Interview Crash Guide
Boost MyBatis Development: Convert XML to Real SQL, Mock Data & Stress Test

mybatis-sql-viewer plugin provides the following capabilities:

Convert MyBatis XML to real SQL statements, mock parameters, perform SQL compliance checks, index checks, execute SQL, conduct stress testing, and scan MyBatis SQL statements.

1. Introduction

Writing CRUD code is often tedious and error‑prone. Common problems include incorrect field or table names requiring application restarts, cumbersome data mocking for tests, uncertainty about SQL compliance, index usage, realistic production‑like data volumes, and performance metrics such as TPS, latency, and slow queries.

For MyBatis users, additional issues arise: mismatched mapper methods and XML tags, missing error feedback for syntax mistakes, difficulty locating the corresponding XML file for a mapper method, and uncertainty about the number of XML files, SQL statements, or potential slow queries in a project.

2. Installation

IDEA plugin installation:

Preferences (Settings) → Plugins → Marketplace → Search "mybatis sql viewer" → Install

Manual installation:

Download the latest zip from the releases page. Preferences (Settings) → Plugins → ⚙️ → Install plugin from disk... → Select the downloaded file.

3. Usage

Configure a data source to fetch metadata and execute SQL.

Click the datasource button to create, select, delete, or test data sources.

1. Modes

The plugin offers two modes: MyBatis mode and non‑MyBatis mode.

Non‑MyBatis mode: disable the MyBatis mode checkbox and write SQL directly in the statement tab.

MyBatis mode: enable the checkbox to gain mapper method parameter mocking, file navigation, and MyBatis XML scanning.

2. MyBatis SQL Scan

Supports both file‑level and project‑level scanning.

File‑level scan

Click the "sql" icon next to a mapper interface or namespace to scan that file.

Project‑level scan

Click the mybatis sql scan button to scan the entire project. Results show namespaces and methods on the left; selecting a method displays the generated SQL, compliance checks, index analysis, and execution plan on the right.

3. SQL Features

Syntax validation and compliance checking.

Index analysis and execution plan display.

SQL execution with result, plan, and data output.

Stress testing configuration (value source, traffic model, concurrency, duration) and automatic report generation.

4. SQL Table View

The "table" tab parses the SQL to extract table names and creates a tab for each table, showing field information, index details, and mock data configuration.

SELECT    state FROM    CITY WHERE    country_name IN (        SELECT            name FROM            COUNTRY WHERE            id IN (1, 2, 3)    )

5. Mock Data

Supports various mock rules such as random values (string, name, datetime, integer, decimal, date, timestamp, time, year, city, url, email, ip, university, phone), lexicon, database reference, increment, fixed, regex, and none.

Create custom lexicons via the "lexicon" button, preview mock data (default 50 rows), and insert mock records (default 100 rows, configurable). After stress testing, clean up mock data using the "Clean" button.

4. Configuration

Preferences (Settings) → Tools → MyBatis Sql Viewer

5. References

Implementation referenced several excellent projects and code bases.

JDBC stress testing – Alibaba Cloud Help Center

SQL Father – Mock data generator (backend)

GitHub – q258523454/Java-Mybatis-SQL-Scanner

Programmer Shunzai – Building an SQL compliance tool

pojo2json

mybatis‑3

Open‑source repository:

https://github.com/linyimin0812/mybatis-sql-viewer
Performance TestingMyBatisIDE pluginDatabase ToolsSQL MockSQL Viewer
Java Interview Crash Guide
Written by

Java Interview Crash Guide

Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.

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.