Boost Java Development with MyBatisX: Full Guide to Code Generation and JPA Features
This article introduces MyBatisX, an IDEA plugin that streamlines MyBatis development with navigation, GUI‑based code generation, customizable templates, JPA‑style method hints, and icon settings, providing step‑by‑step instructions and visual examples to enhance backend productivity.
MyBatisX Overview
MyBatisX is a fast‑development plugin for IntelliJ IDEA, maintained by the MyBatis‑Plus team, designed to improve efficiency.
Key features include:
Bidirectional navigation between mapper.xml and Mapper interfaces.
Built‑in GUI code generator that creates Domain, mapper.xml, Mapper, Service and Service implementation classes based on the database.
Customizable code generation templates.
JPA‑style method name support that automatically generates SQL implementations with full suggestions.
Usage
Installation
Search for and install the MyBatisX plugin from the marketplace.
After installation, Mapper interfaces and mapper.xml files display the MyBatis bird icon.
XML and Interface Navigation
Click the icon beside a Mapper interface method to jump to the corresponding SQL in mapper.xml, and vice versa.
Automatic Code Generation
Select tables, right‑click, and generate CRUD code for one or multiple tables.
Modify options via the GUI, such as base package paths and entity package paths.
Select annotation and template type as MyBatis‑Plus 3, optionally enable Lombok and adjust mapper.xml file path.
After confirming, generated files appear, eliminating the need for manual code writing.
Custom Templates
You can modify the default generation templates, for example to add Swagger annotations to entity classes.
The template files are located under
extensions->MyBatisX. Edit
domain.ftlto customize the generated code.
<code>package ${domain.packageName};
import java.io.Serializable;
<#list tableClass.importList as fieldType>
import ${fieldType};
</#list>
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.baomidou.mybatisplus.annotation.TableName;
/**
* ${tableClass.remark!}
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("${tableClass.tableName}")
@ApiModel(value="${tableClass.shortClassName}对象", description="${tableClass.remark!}")
public class ${tableClass.shortClassName} implements Serializable {
private static final long serialVersionUID = 1L;
<#list tableClass.allFields as field>
@ApiModelProperty("${field.remark!}")
private ${field.shortTypeName} ${field.fieldName};
</#list>
}
</code>After running the generator with the custom template, entity classes will include Swagger annotations.
JPA Hints
MyBatisX can generate SQL implementations from JPA‑style method names without writing SQL manually.
Batch insert method generation.
Automatic field suggestions for queries like findByName.
Update and delete methods generated from method names.
Icon Settings
You can change the default bird icons for Mapper interfaces and mapper.xml files in MyBatisX settings.
Conclusion
MyBatisX is a powerful IDEA plugin offering comprehensive suggestions, a graphical code generator, and JPA‑style method hints that significantly boost development efficiency for Java backend projects.
References
Official documentation: https://baomidou.com/pages/ba5b24/
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.