Guide to Using mybatis-plus-generator-ui for Java Code Generation

This guide explains how to integrate the mybatis-plus-generator-ui library into a Spring Boot project, configure database connections, launch the web UI, and use its customizable templates and naming converters to generate Entity, Mapper, Service, and Controller classes for multiple databases with a single click.

Java Tech Enthusiast
Java Tech Enthusiast
Java Tech Enthusiast
Guide to Using mybatis-plus-generator-ui for Java Code Generation

In the MyBatis‑Plus ecosystem many developers need a more flexible code generator. The mybatis-plus-generator-ui project provides a web UI that can generate Entity, Mapper, Mapper.xml, Service and Controller classes for Spring Boot projects, supporting multiple databases such as PostgreSQL, Oracle, DB2, MySQL and SQL Server.

How to add the 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>

Running the generator as a standalone Spring Boot application

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 name */
                public String serviceNameConvert(String tableName) {
                    return entityNameConvert(tableName) + "Service";
                }
                /** custom Controller name */
                public String controllerNameConvert(String tableName) {
                    return entityNameConvert(tableName) + "Action";
                }
            })
            .basePackage("com.github.davidfantasy.mybatisplustools.example")
            .port(8068)
            .build();
        MybatisPlusToolsApplication.run(config);
    }
}

After starting the application, open http://localhost:8068/ in a browser to access the UI.

Key features

Table query and browsing

Output configuration for Entity, Mapper, Service, Controller, etc.

Project import and template download

Strategy configuration (overwrite, file types, etc.)

SQL input to generate Mapper methods and ResultMap

Full code generation with one click

Custom extensions

Templates can be edited in the frontend directory. The NameConverter interface allows you to customize naming rules for generated files. Example implementation:

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.*;

/** 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;
    }
    // other conversion methods omitted for brevity
}

To rebuild the UI after modifying templates, run the following commands in src/frontend:

yarn install
yarn run build

Conclusion

The mybatis-plus-generator-ui tool offers a highly customizable, UI‑driven way to generate boilerplate code for MyBatis‑Plus projects. The source code and documentation are available at https://github.com/davidfantasy/mybatis-plus-generator-ui . It is suitable for developers who want to accelerate backend development while keeping the generation process flexible.

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-plusTutorial
Java Tech Enthusiast
Written by

Java Tech Enthusiast

Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!

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.