Boost Java Backend Productivity with MyBatis‑Plus Generator UI
This article introduces the MyBatis‑Plus Generator UI, a web‑based code generation framework that supports multiple databases, offers highly customizable templates, and integrates seamlessly with Spring Boot to accelerate backend development through automated creation of entities, mappers, services, controllers, and SQL‑based code.
1. What is mybatis-plus-generator-ui?
It is a web UI wrapper around mybatis-plus-generator that quickly creates Spring Boot‑compatible business code such as Entity, Mapper, Mapper.xml, Service, and Controller. 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 : Upload or paste SQL statements.
SQL code generation : Generate code based on SQL scripts.
2. How to use mybatis-plus-generator-ui?
The tool is provided as a JAR that runs as a standalone Spring Boot service. It supports PostgreSQL, Oracle, DB2, MySQL, SQL Server and other common relational databases.
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
From version 1.4.0 onward the GeneratorUIServer can be deployed as an independent Spring Boot application, allowing multiple projects to share the same code generation service.
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 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);
}
}The example connects to a PostgreSQL database; the appropriate driver must be added to Maven and the connection details configured. The service runs on port 8068, similar to a typical Spring Boot application.
3) Run the program
Execute the main method; the console will display the service port and template directory. Open http://localhost:8068/ in a browser to start configuring code generation.
3. Code generation workflow
1) Table query and browsing
Browse and query tables from the configured data source, then select one or more templates for code generation.
2) Output configuration
The UI provides built‑in templates for Entity, Mapper, Service, Controller, etc. Users can upload custom templates, adjust parameters, and add new output file types. All settings are saved per project package.
3) Strategy configuration
Define generation strategies such as whether to overwrite existing files, which file types to generate, etc.
4) SQL‑based generation
Enter a SQL query to automatically generate corresponding Mapper methods, DTOs, and ResultMap configurations.
5) Generated code preview
4. Custom extensions
1) Template adjustments
Download the BTL template files from the UI, edit them with a text editor, and re‑upload to modify generated code.
2) Code‑level configuration
For teams that prefer different naming conventions (e.g., Mapper as Dao, Controller as Action), modify the NameConverter implementation to customize class names.
public interface NameConverter {
default String entityNameConvert(String tableName) { ... }
default String propertyNameConvert(String fieldName) { ... }
default String mapperNameConvert(String tableName) { return entityNameConvert(tableName) + "Mapper"; }
// other conversion methods ...
}3) Front‑end UI customization
If UI changes are required, clone the repository, edit the source under the frontend directory, and rebuild the static assets.
Rebuild with:
yarn install
yarn run build5. Summary
The article presented MyBatis‑Plus Generator UI, a highly extensible code generation framework that supports multiple databases, customizable templates, SQL‑driven generation, and UI extensions, making it a valuable tool for accelerating Java backend development.
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 Interview Crash Guide
Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.
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.
