← 返回 Skills 市场
coder-myj

SQL-To-JAVA

作者 Coder-MYJ · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
133
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install sql-to-java
功能描述
Convert MySQL CREATE TABLE statements to Java entity classes following framework conventions. Use when converting SQL DDL to Java entity definitions, generat...
使用说明 (SKILL.md)

SQL to Java Entity

Quick Start

Convert a MySQL CREATE TABLE statement to a Java entity class:

  1. Parse the CREATE TABLE statement to extract table name, columns, and constraints
  2. Map each MySQL column type to corresponding Java type
  3. Convert snake_case column names to camelCase field names
  4. Generate entity class with @TableName, @TableId, and JPA annotations
  5. Generate getter/setter methods

Configuration

Before generating the entity class, determine the following:

  • Package name: Ask the user for the target 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 context.

Type Mapping

For complete MySQL to Java type mappings, see type_mappings.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
created_at   → createdAt
user_id      → userId
is_active    → isActive

Class name conversion (PascalCase):

user_info    → UserInfo
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 mapped @TableField(exist = false)

JPA Annotations (if needed)

Constraint Annotation
Primary key @Id
Auto increment @GeneratedValue(strategy = GenerationType.IDENTITY)
Column name @Column(name = "column_name")
Not null @Column(nullable = false)
Unique @Column(unique = true)
Length @Column(length = 50)

Example

Input

CREATE TABLE `user_info` (
    `id` bigint unsigned 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,
    `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
    `is_active` tinyint(1) DEFAULT '1',
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='User Table';

Output

package com.example.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@TableName("user_info")
public class UserInfo {

    @TableId(type = IdType.AUTO)
    private Long id;

    private String name;

    private Integer age;

    private String email;

    private BigDecimal salary;

    private String description;

    private LocalDateTime createdAt;

    private Integer isActive;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public BigDecimal getSalary() {
        return salary;
    }

    public void setSalary(BigDecimal salary) {
        this.salary = salary;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public Integer getIsActive() {
        return isActive;
    }

    public void setIsActive(Integer isActive) {
        this.isActive = isActive;
    }
}

Workflow

  1. Extract table info: Get table name, column definitions, constraints, comment
  2. Apply type mappings: See type_mappings.md for reference
  3. Generate class name: Convert snake_case table name to PascalCase
  4. Generate field names: Convert snake_case columns to camelCase
  5. Add annotations: Generate @TableName, @TableId, @TableField based on column attributes
  6. Generate getters/setters: Create standard getter and setter methods
  7. Add imports: Include necessary imports for types and annotations

Package Structure

Entity classes should be placed in a package specified by the user. Common conventions:

  • Generic project: com.{company}.{module}.entity or com.{company}.{module}.model

Class Comment

Use table comment as class comment:

/**
 * User Table
 */
@TableName("user_info")
public class UserInfo extends EntityBean {
}

Base Class

The entity may extend a framework base class if required:

  • Framework: May extend BaseEntity, AbstractEntity, or no base class

Primary Key Strategy

MySQL Column Definition IdType
AUTO_INCREMENT IdType.AUTO
Manual assignment IdType.INPUT
UUID IdType.ASSIGN_UUID
Snowflake algorithm IdType.ASSIGN_ID

Nullable Columns

For nullable columns (allows NULL), use wrapper types:

  • Integer instead of int
  • Long instead of long
  • Boolean instead of boolean

Important Notes

  1. Always use wrapper types (Integer, Long, Boolean) for nullable columns
  2. Use BigDecimal for DECIMAL/NUMERIC types to maintain precision
  3. Use LocalDateTime for DATETIME/TIMESTAMP types
  4. Table name in @TableName should match the actual database table name exactly
  5. The id field should use IdType.AUTO for auto-increment columns
  6. Generate complete getter/setter methods for all fields
  7. Follow framework conventions and package structure
安全使用建议
This skill is instruction-only and internally consistent with its purpose. Before using it: (1) avoid pasting sensitive or production-only DDL that contains secrets or connection snippets; (2) review generated classes for correctness (e.g., unsigned INT handling, DECIMAL -> BigDecimal, nullable vs primitive types, and annotation choices between MyBatis-Plus and JPA); (3) confirm package and base-class choices when prompted by the agent; and (4) run generated code through your project's build/tests and style checks before committing. No special environment credentials or installs are required.
功能分析
Type: OpenClaw Skill Name: sql-to-java Version: 1.0.0 The skill bundle is a standard code generation tool designed to convert MySQL CREATE TABLE statements into Java entity classes. The instructions in SKILL.md and the reference data in references/type_mappings.md are strictly focused on text transformation, naming conventions (snake_case to camelCase), and mapping database types to Java types. There is no evidence of malicious intent, data exfiltration, or unauthorized execution.
能力评估
Purpose & Capability
The name/description (SQL -> Java entities) matches the SKILL.md and reference material. There are no unrelated required env vars, binaries, or config paths. All declared requirements are proportionate to the stated purpose.
Instruction Scope
The instructions are limited to parsing DDL, mapping types, converting names, and emitting annotated Java classes. They do not instruct reading system files, accessing environment variables, calling external endpoints, or transmitting data. The only ambiguity is the guidance to use 'project context' and to 'ask the user' for package/base-class choices, which is normal for code-generation but means the agent should explicitly request user-provided context rather than searching the host.
Install Mechanism
No install spec or code files beyond documentation — this is instruction-only, so nothing is downloaded, written to disk, or executed by the skill itself.
Credentials
The skill requests no environment variables, credentials, or config paths. All operations described are local transformations of user-provided SQL text to Java code and don't require secrets or external service access.
Persistence & Privilege
always is false and there are no indications the skill requests persistent system privileges or modifies other skills. Autonomous invocation is allowed by platform default but is not combined with any broad privileges here.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install sql-to-java
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /sql-to-java 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of SQL to Java entity converter. - Converts MySQL CREATE TABLE statements to Java entity classes following MyBatis-Plus or JPA conventions. - Automatically maps MySQL types to Java types and converts snake_case to camelCase for fields and PascalCase for class names. - Generates framework-specific annotations, including @TableName, @TableId, and appropriate field annotations. - Supports customization of package name, base class, and annotation style. - Handles nullable columns, primary key strategies, and includes standard getter/setter generation. - Produces well-structured, ready-to-use entity classes with imports, comments, and accurate type handling.
元数据
Slug sql-to-java
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

SQL-To-JAVA 是什么?

Convert MySQL CREATE TABLE statements to Java entity classes following framework conventions. Use when converting SQL DDL to Java entity definitions, generat... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 133 次。

如何安装 SQL-To-JAVA?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install sql-to-java」即可一键安装,无需额外配置。

SQL-To-JAVA 是免费的吗?

是的,SQL-To-JAVA 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

SQL-To-JAVA 支持哪些平台?

SQL-To-JAVA 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 SQL-To-JAVA?

由 Coder-MYJ(@coder-myj)开发并维护,当前版本 v1.0.0。

💬 留言讨论