A small Java command-line tool that reads MySQL table metadata and generates a simple Java source skeleton:
- entity class
- mapper interface
- service interface
- service implementation
The project is intended for teams that want a lightweight starting point for CRUD-style Java modules without binding the generator itself to a specific web framework.
- Reads column names, types, comments, length, scale, and nullable flags from MySQL metadata.
- Converts snake_case table and column names to Java class and field names.
- Maps common MySQL types to Java types such as
String,Integer,Long,BigDecimal,LocalDate, andLocalDateTime. - Generates plain Java classes with fields, comments, getters, and setters.
- Keeps generated mapper and service classes framework-neutral so they can be adapted to MyBatis, Spring, or another stack.
- JDK 8 or later
- Maven 3.6 or later
- A reachable MySQL database
mvn clean packagejava -jar target/mysql-entity-generator-0.1.0.jar \
--url=jdbc:mysql://localhost:3306/demo \
--username=demo_user \
--password=demo_password \
--table=user_account \
--package=com.example.generated \
--output=generated-sourcesArguments:
| Argument | Required | Description |
|---|---|---|
--url |
Yes | MySQL JDBC connection URL. |
--username |
Yes | Database username. |
--password |
Yes | Database password. |
--table |
Yes | Table name to generate from. |
--package |
No | Base Java package. Default is com.example.generated. |
--output |
No | Output directory. Default is generated-sources. |
Generated files are written below the output directory using the selected base package:
generated-sources/
com/example/generated/
entity/UserAccount.java
mapper/UserAccountMapper.java
service/UserAccountService.java
service/impl/UserAccountServiceImpl.java
Do not commit real database addresses, usernames, passwords, or private generated code. Use local environment variables or CI secrets when running the tool in automated jobs.
- Optional Lombok output mode.
- Optional MyBatis mapper XML generation.
- Config-file based execution.
- Unit tests for name conversion and type mapping.
MIT