MyBatis Generator introspects database tables and emits Java or Kotlin model and mapper code for MyBatis. It reduces manual setup for repetitive CRUD access layers.
Overview
MyBatis Generator (MBG) connects to a JDBC database, reads table metadata, and produces artifacts aligned with a selected runtime style. Outputs can include Java or Kotlin types, mapper interfaces, and SQL maps depending on whether you use legacy XML-oriented runtimes or newer MyBatis Dynamic SQL-oriented runtimes.
Generated code covers insert, update, delete, select, and count operations for configured tables, with variations when keys or BLOB columns differ. Newer runtimes emphasize smaller, Dynamic SQL-based clients; legacy runtimes still emit compatible XML for older MyBatis projects.
MBG runs from the command line, Maven, Ant, or an Eclipse feature. Iterative generation can merge XML and, with JavaParser available, merge Java files so custom edits survive reruns. Kotlin output overwrites or uses new filenames instead of merging.
Teams adopting MyBatis use MBG to bootstrap persistence layers and then hand-author joins, stored procedures, and complex queries the generator does not cover.
Key features
- Table introspection via JDBC
- Java and Kotlin output
- Multiple target runtimes
- CRUD SQL generation
- Maven and Ant integration
- Eclipse tooling
- XML and Java merge
- Dynamic SQL runtime option
Use cases
- Bootstrapping MyBatis mappers
- Regenerating after schema changes
- Kotlin MyBatis projects
- Reducing CRUD boilerplate