Boost Java Development with MyBatis-Plus Generator UI: A Complete Guide

This article introduces the MyBatis‑Plus Generator UI, a highly customizable web‑based code generation framework that supports multiple databases, explains its core features, provides step‑by‑step integration with Spring Boot, and demonstrates how to extend templates and configure naming conventions for efficient backend development.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Boost Java Development with MyBatis-Plus Generator UI: A Complete Guide

In MyBatis‑based development, many developers use MyBatis‑Plus to improve efficiency. However, existing code generators may not meet expectations, especially for multi‑database support. This article presents a highly customizable, UI‑driven code generation framework based on MyBatis‑Plus, available at GitHub: mybatis-plus-generator-ui.

The article demonstrates the integration of mybatis-plus-generator-ui through examples; interested readers can clone the repository and extend it.

1. What is mybatis-plus-generator-ui?

It wraps mybatis‑plus‑generator and provides a web UI to quickly generate code compatible with Spring Boot and MyBatis‑Plus, including Entity, Mapper, Mapper.xml, Service, Controller, etc. Templates and output parameters are customizable, and SQL queries can be used to generate code directly.

Features

Table query: Query list of tables from configured relational databases.

Output configuration: Configure templates for Entity, Mapper, Service, Controller and other code files.

Project import: Import configuration from other projects.

Template download: Download shared template information.

Strategy configuration: Define generation strategies for files.

Template upload: Upload templates from other projects.

SQL input upload: Upload or paste SQL queries.

SQL code generation: Generate code based on SQL scripts.

2. How to use mybatis-plus-generator-ui?

2.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.2 Create program entry

From version 1.4.0, GeneratorUIServer can be deployed as an independent Spring Boot project. Example main class:

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 rule */
                public String serviceNameConvert(String tableName) {
                    return this.entityNameConvert(tableName) + "Service";
                }
                /** custom Controller name rule */
                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, and runs the generator on port 8068, similar to a Spring Boot application.

2.3 Run example

Running the main method displays logs with the port and template directory. Open http://localhost:8068/ in a browser to configure and generate code.

3. Code generation

3.1 Table query and browsing

You can browse and query tables from the data source, then select one or more templates to generate code.

3.2 Output configuration

Built‑in templates for Entity, Mapper, Service, Controller, etc., can be uploaded, replaced, and their parameters adjusted. Settings are saved per project.

3.3 Strategy configuration

Define generation strategies such as file overwrite, file types, etc., to control each generation run.

3.4 SQL configuration generation

Enter a SQL query to automatically generate corresponding Mapper methods, DTO objects, and ResultMap configurations.

3.5 Generate code

After configuration, click generate to produce the code files.

4. Custom extensions

4.1 Template adjustments

Edit the .btl template files to modify generated code. After editing, recompile the frontend resources.

4.2 Code‑level configuration

Rename Mapper to Dao, Controller to Action, etc., by customizing NameConverter implementations.

/** custom Service name rule */
public String serviceNameConvert(String tableName) {
    return this.entityNameConvert(tableName) + "Service";
}

/** custom Controller name rule */
public String controllerNameConvert(String tableName) {
    return this.entityNameConvert(tableName) + "Action";
}

The NameConverter interface defines default methods for entity, property, mapper, XML, service, controller naming, and generic output file naming.

public interface NameConverter {
    default String entityNameConvert(String tableName) { /* ... */ }
    default String propertyNameConvert(String 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) { /* ... */ }
}

To customize the UI, modify the source in the frontend directory and rebuild:

yarn install
yarn run build

5. Summary

The article provides a concise introduction to a MyBatis‑Plus based code generator, its rich features, integration steps with Spring Boot, and extension points, offering developers a practical solution for automated backend code generation.

https://github.com/davidfantasy/mybatis-plus-generator-ui
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.

Code GenerationSpring BootMyBatis-Plustemplate customization
Java High-Performance Architecture
Written by

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.

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.