Boost Java Backend Productivity with MyBatis-Plus Generator UI
This article introduces the MyBatis-Plus Generator UI, a web‑based tool that wraps MyBatis‑Plus code generation to quickly produce Spring Boot compatible entities, mappers, services and controllers, explains how to integrate it via Maven and a main class, and demonstrates its rich customization and UI features.
What is mybatis-plus-generator-ui?
It is a web UI wrapper for mybatis-plus-generator that quickly generates Spring Boot compatible code such as Entity, Mapper, Mapper.xml, Service, and Controller, with customizable templates and output parameters.
How to use mybatis-plus-generator-ui
The tool is packaged as a JAR that reads database metadata and provides a web UI for developers. It supports PostgreSQL, Oracle, DB2, MySQL, and SQL Server.
1. Add Maven 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 program entry (main method)
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);
}
}The configuration connects to a PostgreSQL database, sets the base package, custom naming rules, and the server port, then starts the generator application.
3. Run the application
After launching, the console shows the listening port and template directory. Open http://localhost:8068/ in a browser to configure and generate code.
Features
Table query: browse and query tables from the configured datasource.
Output configuration: customize templates for Entity, Mapper, Service, Controller, etc., and upload custom templates.
Project import, template download, strategy configuration, SQL input upload, and SQL‑based code generation.
Custom extensions
Templates can be edited in the frontend directory. The NameConverter interface allows custom naming for Service, Controller, Entity, Mapper, and other generated files.
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;
if (fileType.equals(Constant.FILE_TYPE_MAPPER)) return mapperNameConvert(tableName) + DOT_JAVA;
if (fileType.equals(Constant.FILE_TYPE_MAPPER_XML)) return mapperXmlNameConvert(tableName) + DOT_XML;
if (fileType.equals(Constant.FILE_TYPE_SERVICE)) return serviceNameConvert(tableName) + DOT_JAVA;
if (fileType.equals(Constant.FILE_TYPE_SERVICEIMPL)) return serviceImplNameConvert(tableName) + DOT_JAVA;
if (fileType.equals(Constant.FILE_TYPE_CONTROLLER)) return controllerNameConvert(tableName) + DOT_JAVA;
return entityNameConvert(tableName) + fileType;
}
}After modifying the frontend, compile the static resources with:
yarn install
yarn run buildConclusion
mybatis-plus-generator-ui offers a highly customizable, UI‑driven code generation framework for Java backend projects, supporting multiple databases and extensible naming rules, making rapid development of Spring Boot applications more efficient.
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.
