Boost Spring Boot Productivity with MyBatis‑Plus Generator UI

This article introduces the MyBatis‑Plus Generator UI, a highly customizable web‑based code generator for Spring Boot projects, explains how to integrate it via Maven, run it, use its rich features for entity, mapper, service and controller generation, and extend it with custom templates and name‑conversion rules.

macrozheng
macrozheng
macrozheng
Boost Spring Boot Productivity with MyBatis‑Plus Generator UI

In MyBatis‑Plus development, many developers use MyBatis‑Plus to speed up coding, but the default generators lack deep customization and multi‑database support. A highly customizable, UI‑driven generator is needed; this article introduces mybatis-plus-generator-ui , a web UI wrapper around MyBatis‑Plus‑Generator that can generate code compatible with Spring Boot and MyBatis‑Plus.

What is mybatis-plus-generator-ui?

It packages mybatis-plus-generator with a web UI, allowing quick generation of Entity, Mapper, Mapper.xml, Service, and Controller code for Spring Boot projects. Users can customize templates, output parameters, and even generate code directly from SQL queries.

Key features include:

Table query: List tables from the configured relational database.

Output configuration: Configure templates and parameters for Entity, Mapper, Service, Controller, etc.

Project import: Import settings 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: Paste SQL to generate corresponding code.

SQL code generation: Generate code based on SQL scripts.

How to use mybatis-plus-generator-ui?

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 a main entry to launch the UI

From version 1.4.0 onward, GeneratorUIServer can be deployed as a standalone Spring Boot application. 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 POSTGRE_SQL, 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);
    }
}

Running the main method starts the UI on port 8068; visiting http://localhost:8068/ opens the configuration page.

3. Run the application

After launching, the console shows the listening port and template directory. Access the URL in a browser to begin generating code.

Code generation workflow

1. Table query and browsing

Browse tables from the connected data source and select templates for code generation.

2. Output configuration

Configure built‑in templates for Entity, Mapper, Service, Controller, etc., or upload custom templates. Settings are saved per project package.

3. Strategy configuration

Define generation strategies such as file overwrite, file types to generate, etc.

4. SQL‑based generation

Enter a SELECT statement to automatically generate Mapper methods, DTOs, and ResultMap entries.

5. Generated code preview

Custom extensions

1. Template adjustments

Download the BTL template files, edit the source code, and re‑upload to customize UI output.

2. Code‑level configuration (NameConverter)

Override naming rules for Entity, Mapper, Service, Controller, etc., by implementing the NameConverter interface.

/** 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, XML, 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) {
        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;
    }
}

3. Frontend build

After modifying UI resources in the frontend directory, compile them with Yarn:

yarn install
yarn run build

Conclusion

The MyBatis‑Plus Generator UI offers a powerful, extensible way to generate backend code for Spring Boot projects, supporting multiple databases, custom templates, naming strategies, and UI customization, greatly improving development efficiency.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaCode GenerationBackend DevelopmentSpring BootMyBatis-Plusgenerator UI
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.