MyBatis-Plus Code Generator
Current Version
The MyBatis-Plus code generator is currently in version 3.5.7-1. It follows a versioning pattern where the numbers before the last indicate the version of the MyBatis-Plus generator itself, and the final digit represents iteration counts for that version.
Overview
Code generators, also known as reverse engineering tools, are designed to ease software development by automatically creating parts of an application's codebase. The concept gained traction with MyBatis, a popular data mapper framework for Java, which included its own code generator. However, configuring it effectively posed challenges for some users. This led to helpful resources, including comprehensive documentation in Chinese and specialized plugins.
The MyBatis-Plus Code Generator simplifies the automation process of generating code for data-access layers. It’s designed to be user-friendly, supporting a wide range of customization options without overwhelming the user.
Features
The MyBatis-Plus Code Generator offers a robust set of features including:
- Automatic creation of model classes
- Automated generation of DAO interfaces
- Production of XML configuration files
- Generation of service interfaces and their implementations
- Builder pattern support for model classes
- Swagger2 support for API documentation
- Generation of constants representing database fields
- Kotlin code generation
- And much more…
Usage Guide
Starting the Project
Option 1: Using a JAR File
Download the mybatis-plus-code-generator-3.5.7-1.jar and execute the command:
java -jar mybatis-plus-code-generator-3.5.7-1.jar
Option 2: Using Docker
For a Docker-based setup, perform the following steps:
-
Pull the Docker image:
docker pull fengwenyi/mybatis-plus-code-generator
-
Deploy the service:
docker run -d -p 8899:8899 --name code-generator -v ~/temp:/temp fengwenyi/mybatis-plus-code-generator
-
Observe the logs:
docker logs -f code-generator
-
Access the container if needed:
docker exec -it code-generator sh
Customizations can be made to the file system mount by specifying a preferred local directory to map to the container's /temp
.
Option 3: Using Git
Clone the repository to your local machine and run the project.
Accessing the Interface
Visit [http://localhost:8899](http://localhost:8899)
to interact with the code generator’s interface. The interface is designed to be intuitive and provides a high-quality user experience.
Code Generation
Users will need to complete a form with essential details. Primarily, this includes specifying the package name where the generated code will reside and configuring the database connection details.
Upon submission, the code generator creates several types of files that collectively facilitate database interactions.
The following files are generated:
- Model classes
- DAO interfaces
- XML mapper files
- Service interfaces and implementations
Additional Information
Ignored Fields
The generator is configured to ignore certain fields, which typically include system-specific or meta information such as:
id
create_date_time
update_date_time
status
create_user_id
create_user_name
update_user_id
update_user_name
enabled_state
deleted_state
Challenges
One common issue is related to Docker deployments. If both the generator and database are hosted locally, the database connection should not use localhost
or 127.0.0.1
. Instead, it should utilize the host's IP address.
The MyBatis-Plus Code Generator effectively automates numerous aspects of the code creation process, making it a valuable tool for developers looking to streamline project setup.