SQL to MyBatis Mapper Generator

Convert SQL CREATE TABLE statements to MyBatis XML mapper, Java Entity class, and Mapper interface with proper type mapping and dynamic SQL.

What is SQL to MyBatis Mapper Generator?

This tool converts SQL CREATE TABLE statements into MyBatis XML mapper files, Java Entity classes, and Mapper interfaces. MyBatis is a popular Java persistence framework that maps SQL statements to Java objects, providing fine-grained control over SQL while automating object-relational mapping.

How to Use

  1. Set the package name (e.g., com.example), author name, and database type
  2. Toggle options: Lombok annotations and comment generation
  3. Paste your SQL CREATE TABLE statements into the input area
  4. Click "Generate MyBatis" to create XML Mapper, Entity class, and Mapper interface
  5. Switch between tabs to view and copy each generated file

Why Use This Tool?

Automatically map SQL types to Java types (VARCHAR → String, INT → Integer, BIGINT → Long, DATETIME → LocalDateTime, DECIMAL → BigDecimal)
Generate complete MyBatis XML mapper with resultMap, CRUD operations, and dynamic SQL
Produce clean Java Entity classes with Lombok @Data or traditional getters/setters
Create Mapper interfaces with proper method signatures and @Mapper annotation

Tips & Best Practices

  • Lombok mode generates @Data, @NoArgsConstructor, @AllArgsConstructor, and @Builder annotations for concise code
  • The XML mapper uses <if> and <where> tags for dynamic SQL, allowing flexible query building
  • Auto-increment primary keys are handled with useGeneratedKeys in the insert statement
  • SQL COMMENT clauses are extracted and added as Javadoc comments in the Entity class

Frequently Asked Questions

What is MyBatis?

MyBatis is a popular Java persistence framework that provides a semi-automated ORM approach. Unlike full ORMs like Hibernate, MyBatis lets developers write SQL directly while handling the mapping between SQL results and Java objects. It supports XML-based or annotation-based configuration and is widely used in enterprise Java applications.

How are SQL types mapped to Java types?

SQL types are mapped to Java types based on JDBC conventions. For example, VARCHAR/CHAR/TEXT → String, INT/INTEGER → Integer, BIGINT → Long, DECIMAL/NUMERIC → BigDecimal, DATETIME/TIMESTAMP → LocalDateTime, DATE → LocalDate, BOOLEAN → Boolean, FLOAT → Float, DOUBLE → Double, BLOB → byte[]. Nullable fields use wrapper types rather than primitives.

What is Lombok and should I use it?

Project Lombok is a Java library that automatically generates boilerplate code like getters, setters, constructors, and builders at compile time using annotations. With Lombok enabled, the Entity class uses @Data, @Builder, @NoArgsConstructor, and @AllArgsConstructor annotations instead of explicit getter/setter methods, making the code much more concise and readable.

Is my SQL data sent to a server?

No, all processing happens entirely in your browser. Your SQL schema never leaves your device. The conversion is performed client-side using a regex-based parser.

Related Tools