Introducing mybatis-plus-generator-ui: A Web UI Code Generator for MyBatis-Plus
This article introduces mybatis-plus-generator-ui, a highly customizable web‑based code generator built on MyBatis‑Plus that supports multiple databases, offers interactive UI for generating Entity, Mapper, Service, Controller and other layers, and provides detailed usage, configuration, and extension instructions for Java backend developers.
In MyBatis development, many developers use MyBatis‑Plus to improve productivity, but existing code generators often produce code that does not meet expectations and have limited multi‑database support.
To address this, a highly customizable, UI‑driven code generation framework called mybatis-plus-generator-ui is introduced. The project is hosted on GitHub at mybatis-plus-generator-ui.
1. What is mybatis-plus-generator-ui?
It wraps mybatis-plus-generator and provides a web UI for quickly generating code compatible with Spring Boot and MyBatis‑Plus. The UI can generate Entity, Mapper, Mapper.xml, Service, Controller and other files, with support for custom templates, output parameters, and direct SQL‑based generation.
Features include table query, output configuration, project import, template download, strategy configuration, template upload, SQL input, and SQL‑based code generation.
2. How to use mybatis-plus-generator-ui?
The tool is distributed as a JAR and can be added to a Maven project. Example pom.xml snippet:
<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>A main class can start the UI server:
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 POSTGRE_SQL, ORACLE, DB2
.nameConverter(new NameConverter() {
/** custom Service name */
public String serviceNameConvert(String tableName) {
return this.entityNameConvert(tableName) + "Service";
}
/** custom Controller name */
public String controllerNameConvert(String tableName) {
return this.entityNameConvert(tableName) + "Action";
}
})
.basePackage("com.github.davidfantasy.mybatisplustools.example")
.port(8068)
.build();
MybatisPlusToolsApplication.run(config);
}
}Running the main method starts the server on port 8068. Access http://localhost:8068/ in a browser to configure and generate code.
3. Code Generation Features
3.1 Table Query and Browsing
The UI allows browsing and querying tables from the configured data source, and selecting one or more templates for generation.
3.2 Output Configuration
Built‑in templates for Entity, Mapper, Service, Controller and others can be uploaded, edited, or extended. All configuration is saved per project package.
3.3 Strategy Configuration
Options such as file overwrite, file type selection, and other generation strategies can be set.
3.4 SQL‑Based Generation
Enter a SELECT statement to automatically generate corresponding Mapper methods, DTOs, and ResultMap entries.
3.5 Generated Code Preview
After generation, the UI shows the created files.
4. Custom Extensions
4.1 Template Adjustment
Download the .btl template files from the frontend directory, edit them with a text editor, and re‑compile the frontend resources.
4.2 NameConverter Customization
Implement custom naming rules for Service, Controller, Entity, etc., by providing a NameConverter implementation.
/** custom Service name */
public String serviceNameConvert(String tableName) {
return this.entityNameConvert(tableName) + "Service";
}
/** custom Controller name */
public String controllerNameConvert(String tableName) {
return this.entityNameConvert(tableName) + "Action";
}The full NameConverter interface contains default methods for entity, property, mapper, XML, service, and controller naming, as well as a generic outputFileNameConvert method.
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) {
if (Strings.isNullOrEmpty(tableName)) return "";
tableName = tableName.substring(tableName.indexOf(StrUtil.UNDERLINE) + 1);
return StrUtil.upperFirst(StrUtil.toCamelCase(tableName.toLowerCase()));
}
default String propertyNameConvert(String fieldName) {
if (Strings.isNullOrEmpty(fieldName)) return "";
if (fieldName.contains("_")) return StrUtil.toCamelCase(fieldName.toLowerCase());
return fieldName;
}
default String mapperNameConvert(String tableName) { return entityNameConvert(tableName) + "Mapper"; }
default String mapperXmlNameConvert(String tableName) { return entityNameConvert(tableName) + "Mapper"; }
default String serviceNameConvert(String tableName) { return "I" + entityNameConvert(tableName) + "Service"; }
default String serviceImplNameConvert(String tableName) { return entityNameConvert(tableName) + "ServiceImpl"; }
default String controllerNameConvert(String tableName) { return entityNameConvert(tableName) + "Controller"; }
default String outputFileNameConvert(String fileType, String tableName) {
if (fileType.equals(Constant.FILE_TYPE_ENTITY)) return entityNameConvert(tableName) + DOT_JAVA;
else if (fileType.equals(Constant.FILE_TYPE_MAPPER)) return mapperNameConvert(tableName) + DOT_JAVA;
else if (fileType.equals(Constant.FILE_TYPE_MAPPER_XML)) return mapperXmlNameConvert(tableName) + DOT_XML;
else if (fileType.equals(Constant.FILE_TYPE_SERVICE)) return serviceNameConvert(tableName) + DOT_JAVA;
else if (fileType.equals(Constant.FILE_TYPE_SERVICEIMPL)) return serviceImplNameConvert(tableName) + DOT_JAVA;
else if (fileType.equals(Constant.FILE_TYPE_CONTROLLER)) return controllerNameConvert(tableName) + DOT_JAVA;
return entityNameConvert(tableName) + fileType;
}
}4.3 Frontend Build
After modifying UI resources, compile them with Yarn:
yarn install
yarn run build5. Conclusion
The article presented a feature‑rich, UI‑driven code generator based on MyBatis‑Plus, demonstrated how to integrate it via Maven, configure it programmatically, run the server, and extend both templates and naming conventions to fit various backend development needs.
GitHub 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.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
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.
