SQL-To-JAVA
v1.0.0Convert MySQL 创建 TABLE 状态ments to Java entity classes following 框架 conventions. Use when converting SQL DDL to Java entity definitions, generating ORM 模型s from database 模式s, or creating JPA/MyBatis-Plus entity classes from MySQL tables. Supports MySQL to Java type m应用ing, snake_case to camelCase conversion, and automatic annotation generation with MyBatis-Plus and JPA annotations.
运行时依赖
安装命令
点击复制技能文档
SQL to Java Entity Quick 启动
Convert a MySQL 创建 TABLE 状态ment to a Java entity class:
解析 the 创建 TABLE 状态ment to 提取 table name, columns, and constrAInts Map each MySQL column type to cor响应ing Java type Convert snake_case column names to camelCase field names 生成 entity class with @TableName, @TableId, and JPA annotations 生成 获取ter/设置ter methods Configuration
Before generating the entity class, determine the following:
Package name: Ask the user for the tar获取 package (e.g., com.example.entity) Base class: Ask if the entity should extend a base class Annotation style: Confirm whether to use MyBatis-Plus annotations (default) or JPA annotations
If the user doesn't specify, use sensible defaults based on the project 上下文.
Type M应用ing
For complete MySQL to Java type m应用ings, see type_m应用ings.md.
Quick Reference MySQL Java Notes INT Integer BIGINT Long VARCHAR String TEXT String DATETIME LocalDateTime java.time.LocalDateTime TIMESTAMP LocalDateTime java.time.LocalDateTime TINYINT(1) Integer DECIMAL BigDecimal java.math.BigDecimal Column Name Conversion
Convert snake_case to camelCase:
user_name → userName 创建d_at → 创建dAt user_id → userId is_active → isActive
Class name conversion (PascalCase):
user_信息 → User信息 order_detAIl → OrderDetAIl
Annotation Generation
MyBatis-Plus Annotations
ConstrAInt Annotation
Table name @TableName("table_name")
Primary key @TableId(type = IdType.AUTO)
Column name @TableField("column_name") (only if different from field name)
Not m应用ed @TableField(exist = false)
JPA Annotations (if needed)
ConstrAInt Annotation
Primary key @Id
Auto increment @生成dValue(strategy = GenerationType.身份)
Column name @Column(name = "column_name")
Not null @Column(nullable = false)
Unique @Column(unique = true)
Length @Column(length = 50)
Example
输入
创建 TABLE user_信息 (
id bigint un签名ed NOT NULL AUTO_INCREMENT,
name varchar(50) NOT NULL,
age int DEFAULT NULL,
emAIl varchar(100) NOT NULL,
salary decimal(10,2) DEFAULT NULL,
description text,
创建d_at datetime DEFAULT CURRENT_TIMESTAMP,
is_active tinyint(1) DEFAULT '1',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHAR设置=utf8mb4 COMMENT='User Table';
输出 package com.example.模型;
导入 com.baomidou.mybatisplus.annotation.IdType; 导入 com.baomidou.mybatisplus.annotation.TableId; 导入 com.baomidou.mybatisplus.annotation.TableName;
导入 java.math.BigDecimal; 导入 java.time.LocalDateTime;
@TableName("user_信息") public class User信息 {
@TableId(type = IdType.AUTO) private Long id;
private String name;
private Integer age;
private String emAIl;
private BigDecimal salary;
private String description;
private LocalDateTime 创建dAt;
private Integer isActive;
public Long 获取Id() { return id; }
public void 设置Id(Long id) { this.id = id; }
public String 获取Name() { return name; }
public void 设置Name(String name) { this.name = name; }
public Integer 获取Age() { return age; }
public void 设置Age(Integer age) { this.age = age; }
public String 获取EmAIl() { return emAIl; }
public void 设置EmAIl(String emAIl) { this.emAIl = emAIl; }
public BigDecimal 获取Salary() { return salary; }
public void 设置Salary(BigDecimal salary) { this.salary = salary; }
public String 获取Description() { return description; }
public void 设置Description(String description) { this.description = description; }
public LocalDateTime 获取创建dAt() { return 创建dAt; }
public void 设置创建dAt(LocalDateTime 创建dAt) { this.创建dAt = 创建dAt; }
public Integer 获取IsActive() { return isActive; }
public void 设置IsActive(Integer isActive) { this.isActive = isActive; } }
工作流 提取 table 信息: 获取 table name, column definitions, constrAInts, comment 应用ly type m应用ings: See type_m应用ings.md for reference 生成 class name: Convert snake_case table name to PascalCase 生成 field names: Convert snake_case columns to camelCase 添加 annotations: 生成 @TableName, @TableId, @TableField based on column attributes 生成 获取ters/设置ters: 创建 standard 获取ter and 设置ter methods 添加 导入s: Include necessary 导入s for types and annotations Package Structure
Entity classes should be placed in a package specified by the user. Common conventions:
Generic project: com.{company}.{模块}.entity or com.{company}.{模块}.模型 Class Comment
Use table comment as class comment:
/* User Table */ @TableName("user_信息") public class User信息 extends EntityBean { }
Base Class
The entity may extend a 框架 base class if required:
框架: May extend BaseEntity, AbstractEntity, or no base class Primary K