Boost Your Java Backend: Master MyBatisCodeHelper Pro for Rapid Code Generation
This guide walks you through installing the MyBatisCodeHelper‑Pro IntelliJ plugin, configuring it to generate Java entity, DAO, mapper and service code, customizing type mappings, creating SQL scripts, and using shortcuts to produce find, update, delete, and pagination methods efficiently for backend development.
Installation
Address: https://github.com/gejun123456/MyBatisCodeHelper-Pro
Installation
In IntelliJ install the latest plugin MybatisCodeHelper-2.8.1-191-201 and activate it via
Tools → MybatisCodeHelper → Activation → OfflineActivation, entering any string as the offline key.
Configuration
By default tinyInt/smallInt map to byte and short; you can configure the plugin to use Integer instead and to use Java 8 date‑time types.
Usage
Maven Dependencies
Add the following dependencies to ensure generated code compiles without errors:
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.4</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.11</version>
</dependency>
<!-- Guarantee proper Service annotations -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.1.RELEASE</version>
</dependency>Generate Table SQL from Entity
Press Alt+Insert on an entity class to generate the CREATE TABLE statement, then execute it in the database.
After the table exists, generate CRUD code from the database.
Steps: connect to MySQL in IntelliJ, right‑click the table, configure generation options (disable example files, avoid mapper inheritance, enable generated comments, etc.), then view the generated directories.
Generate Mapper Methods
Place the cursor on a mapper interface method name and press Alt+Enter → Generate mybatis mapper for current class to create the corresponding XML mapping. find (or select query get) supports orderBy, distinct, findFirst. update can be replaced by modify. delete can be replaced by remove. count supports distinct.
Generate Unit Tests (Non‑Spring)
Position the cursor on a mapper method declaration and press Alt+Enter to generate a test method.
public class DaShangMapperTest {
private static DaShangMapper mapper;
@BeforeEach
public static void setUpMybatisDatabase() {
SqlSessionFactory builder = new SqlSessionFactoryBuilder()
.build(DaShangMapperTest.class.getClassLoader()
.getResourceAsStream("mybatisTestConfiguration/DaShangMapperTestConfiguration.xml"));
mapper = builder.getConfiguration()
.getMapper(DaShangMapper.class, builder.openSession(true));
}
@Test
public void testInsertDaShang() throws FileNotFoundException {
mapper.insertDaShang();
}
}Tips
Ctrl‑click a field in mapper.xml to jump to the corresponding database column.
Right‑click an entity class and choose “generate mybatis files” to create the entity, mapper, mapper.xml, service and service implementation.
Unique: unique index, non‑repeatable.
Index: ordinary index, repeatable.
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.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
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.
