Skip to content

xujunfeng1/mysql-entity-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mysql-entity-generator

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.

Features

  • 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, and LocalDateTime.
  • 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.

Requirements

  • JDK 8 or later
  • Maven 3.6 or later
  • A reachable MySQL database

Build

mvn clean package

Usage

java -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-sources

Arguments:

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

Security Notes

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.

Roadmap

  • Optional Lombok output mode.
  • Optional MyBatis mapper XML generation.
  • Config-file based execution.
  • Unit tests for name conversion and type mapping.

License

MIT

About

A lightweight MySQL metadata based Java code generator.

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages