Boost Java Development with MyBatis‑Plus Generator UI: A Complete Guide
This article introduces the MyBatis‑Plus Generator UI, a web‑based code generation tool for Spring Boot projects, explains its features, shows how to integrate it via Maven and a main class, demonstrates running and customizing the generator, and provides tips for extending templates and UI.
Preface
When developing with MyBatis, many developers use MyBatis‑Plus to improve efficiency. Although MyBatis provides code generators, MyBatis‑Plus introduces adjustments that make standard generators produce less‑than‑ideal code and offer limited multi‑database support.
Therefore, a highly customizable, UI‑driven, multi‑database compatible code generation framework is needed. This article introduces mybatis-plus-generator-ui , a self‑service generator based on MyBatis‑Plus.
The article demonstrates the tool through an integrated example that you can clone and extend.
1. What is mybatis-plus-generator-ui?
It wraps mybatis-plus-generator with a web UI to quickly generate code compatible with Spring Boot and MyBatis‑Plus, including Entity, Mapper, Mapper.xml, Service, and Controller. Templates and output parameters are customizable, and SQL queries can directly generate code.
Feature list:
Table query: List tables from the configured relational database.
Output configuration: Configure templates and parameters for Entity, Mapper, Service, Controller, etc., or upload custom templates.
Project import: Import configuration from other projects.
Template download: Share configured templates.
Strategy configuration: Define generation strategies such as file overwrite.
Template upload: Upload templates from other projects.
SQL input upload: Upload or paste SQL queries.
SQL code generation: Generate Mapper methods, DTOs, and ResultMaps from SQL.
2. How to use mybatis-plus-generator-ui?
The tool is provided as a JAR that reads database metadata and offers a web UI for developers. It supports PostgreSQL, Oracle, DB2, MySQL, SQL Server, and other common relational databases.
1) Maven pom dependency
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yelang</groupId>
<artifactId>mybatis-plus-generator-ui-case</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.github.davidfantasy</groupId>
<artifactId>mybatis-plus-generator-ui</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.25</version>
</dependency>
</dependencies>
</project>2) Create a main entry class
Since version 1.4.0, GeneratorUIServer can be deployed as an independent Spring Boot project. Example code:
package com.yelang;
import com.github.davidfantasy.mybatisplus.generatorui.GeneratorConfig;
import com.github.davidfantasy.mybatisplus.generatorui.MybatisPlusToolsApplication;
import com.github.davidfantasy.mybatisplus.generatorui.mbp.NameConverter;
public class GeneratorMain {
public static void main(String[] args) {
GeneratorConfig config = GeneratorConfig.builder()
.jdbcUrl("jdbc:postgresql://127.0.0.1:5432/ghyapp")
.userName("ghy01").password("ghy01")
.driverClassName("org.postgresql.Driver")
// .schemaName("myBusiness") // for PostgreSQL/Oracle/DB2
.nameConverter(new NameConverter() {
/** Custom Service class name */
public String serviceNameConvert(String tableName) {
return this.entityNameConvert(tableName) + "Service";
}
/** Custom Controller class name */
public String controllerNameConvert(String tableName) {
return this.entityNameConvert(tableName) + "Action";
}
})
.basePackage("com.github.davidfantasy.mybatisplustools.example")
.port(8068)
.build();
MybatisPlusToolsApplication.run(config);
}
}The configuration connects to a PostgreSQL database; ensure the driver is added to Maven and the port is set (8086 in the example).
3) Run the example
Execute the main method. The console will show the server port and default template directory. Open a browser at http://localhost:8068/ to access the UI.
3. Code Generation
1) Table browsing
Browse and query tables from the configured data source, then select templates to generate code.
2) Output configuration
Configure templates for Entity, Mapper, Service, Controller, etc., upload custom templates, and add additional output files. Settings are saved per project package.
3) Strategy configuration
Define generation strategies such as file overwrite, file types, etc.
4) SQL‑based generation
Enter a SQL query to automatically generate Mapper methods, DTOs, and ResultMaps.
5) Generate code
4. Custom Extensions
1) Template adjustments
Download the .btl templates from the UI, edit them with a text editor, and re‑upload to modify generated code.
2) Code‑level configuration
Implement NameConverter to customize naming rules for Service, Controller, Entity, etc.
/** Custom Service class name */
public String serviceNameConvert(String tableName) {
return this.entityNameConvert(tableName) + "Service";
}
/** Custom Controller class name */
public String controllerNameConvert(String tableName) {
return this.entityNameConvert(tableName) + "Action";
}The full NameConverter interface provides default methods for entity, property, mapper, service, and controller naming.
package com.github.davidfantasy.mybatisplus.generatorui.mbp;
import cn.hutool.core.util.StrUtil;
import com.github.davidfantasy.mybatisplus.generatorui.dto.Constant;
import com.google.common.base.Strings;
import static com.github.davidfantasy.mybatisplus.generatorui.dto.Constant.DOT_JAVA;
import static com.github.davidfantasy.mybatisplus.generatorui.dto.Constant.DOT_XML;
/** Custom naming rules */
public interface NameConverter {
default String entityNameConvert(String tableName) { /* ... */ }
default String propertyNameConvert(String fieldName) { /* ... */ }
default String mapperNameConvert(String tableName) { /* ... */ }
default String mapperXmlNameConvert(String tableName) { /* ... */ }
default String serviceNameConvert(String tableName) { /* ... */ }
default String serviceImplNameConvert(String tableName) { /* ... */ }
default String controllerNameConvert(String tableName) { /* ... */ }
default String outputFileNameConvert(String fileType, String tableName) { /* ... */ }
}To customize the UI, clone the project and modify the frontend code under the frontend directory.
yarn install
yarn run build5. Summary
This article presented a comprehensive overview of the MyBatis‑Plus Generator UI, covering its concepts, integration steps, and extension methods. The tool offers a rich set of features for generating Entity, Mapper, Service, and Controller code, and can be customized both at the template and UI levels.
Source repository: https://github.com/davidfantasy/mybatis-plus-generator-ui
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.
