MyBatis X Plugin
MyBatisX is a rapid development plugin designed specifically for IntelliJ IDEA, aimed at enhancing development efficiency with the MyBatis and MyBatis-Plus frameworks.
Installation Guide
- Open IntelliJ IDEA.
- Go to
File -> Settings -> Plugins -> Browse Repositories
. - Enter
mybatisx
in the search box. - Find the MyBatisX plugin and click Install.
Core Features
XML Mapping Navigation
MyBatisX provides convenient navigation between XML mapping files and Java interfaces, allowing developers to quickly switch between them and improve development efficiency.
Code Generation
With MyBatisX, you can easily generate corresponding Java entity classes, Mapper interfaces, and XML mapping files based on your database table structure.
Template Reset
MyBatisX allows you to reset code generation templates to restore default settings or customize template content.
JPA-Style Hints
MyBatisX supports JPA-style code hints, including automatic code generation for insert, select, update, and delete operations.
- Generate Insert Operation
- Generate Select Operation
- Generate Update Operation
- Generate Delete Operation
Frequently Asked Questions
JPA Hint Feature Not Working?
The JPA hint feature relies on the association between Mapper interfaces and entity classes. Ensure your Mapper meets any of the following conditions:
- Extends mybatis-plus’s BaseMapper.
- Contains a resultMap tag in the Mapper.xml file.
- Specifies the entity class via annotation on the Mapper class, e.g.,
@Entity com.xx.xx.UserModel
.
Generated Table Name Doesn’t Match Expectations?
MyBatisX determines the table name based on the following rules:
- JPA annotation on the entity class, e.g.,
@Table(name="t_user")
. - mybatis-plus annotation on the entity class, e.g.,
@TableName("t_user")
. - Comment on the entity class, e.g.,
@TableName com.xx.xx.UserModel
. - If none of the above rules apply, the camel-case class name is converted to snake case, e.g.,
UserModel
corresponds to table nameuser_model
.
Code Generation Template Configuration
MyBatisX provides flexible template configuration options, allowing developers to customize code generation templates according to their needs.
Default Templates
You can find the default provided templates in the Scratches and Consoles -> Extensions -> MyBatisX
directory, such as default-all
, default
, mybatis-plus2
, mybatis-plus3
, etc.
Reset Default Templates
To reset templates to default settings, right-click the MyBatisX directory and select Restore Default Extensions
.
Custom Template Content
MyBatisX allows you to customize template content according to project requirements, including entity classes, table names, field information, etc.
Entity Class Information
tableClass.fullClassName
: Fully qualified class name.tableClass.shortClassName
: Short class name.tableClass.tableName
: Table name.tableClass.pkFields
: Primary key fields of the table.tableClass.allFields
: All fields of the table.tableClass.baseFields
: All fields excluding primary keys and blobs.tableClass.baseBlobFields
: All fields excluding primary keys.tableClass.remark
: Table comment.
Field Information
field.fieldName
: Field name.field.columnName
: Column name.field.jdbcType
: JDBC type.field.columnLength
: Column length.field.columnScale
: Column scale.field.columnIsArray
: Whether the field type is an array.field.shortTypeName
: Short Java type name.field.fullTypeName
: Fully qualified Java type name.field.remark
: Field comment.field.autoIncrement
: Whether it’s auto-increment.field.nullable
: Whether it’s nullable.
Configuration Information
baseInfo.shortClassName
: Configuration name.baseInfo.tableName
: Configuration file name.baseInfo.pkFields
: Configuration name.baseInfo.allFields
: Suffix.baseInfo.baseFields
: Package name.baseInfo.baseBlobFields
: Template content.baseInfo.remark
: Relative module resource file path.
With the MyBatisX plugin, you can significantly improve development efficiency with MyBatis and MyBatis-Plus frameworks, while enjoying convenient code generation and template customization features.