ruoyi-code-generator/SKILL.md
基于若依(RuoYi)框架规范生成 CRUD 代码。当用户需要为数据表生成后端Java代码(实体类、Mapper、Service、Controller)、 前端Vue代码(列表页、API封装)、MyBatis XML映射文件或菜单初始化SQL时使用此技能。 适用于: 创建新模块、添加业务功能、根据表结构生成代码等场景。
npx skillsauth add alffei/skill_share ruoyi-code-generatorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
根据用户提供的数据表信息(表名、字段定义),按照若依框架规范自动生成完整的 CRUD 代码,包括:
用户需要提供以下信息(可以通过对话澄清获取):
| 参数 | 必填 | 说明 | 示例 |
|------|------|------|------|
| tableName | ✅ | 数据库表名 | sys_product |
| tableComment | ✅ | 表注释/功能名称 | 产品管理 |
| columns | ✅ | 字段列表(含类型、注释) | 见下方示例 |
| packageName | ❌ | 包路径,默认 com.ruoyi.system | com.ruoyi.business |
| moduleName | ❌ | 模块名,默认取表前缀后的名称 | product |
| businessName | ❌ | 业务名称,默认取表名去前缀 | product |
| author | ❌ | 作者名,默认 ruoyi | zhangsan |
| tplCategory | ❌ | 模板类型: crud/tree/sub,默认 crud | crud |
{
"tableName": "sys_product",
"tableComment": "产品管理",
"columns": [
{"name": "product_id", "type": "bigint", "comment": "产品ID", "isPk": true, "isIncrement": true},
{"name": "product_name", "type": "varchar(100)", "comment": "产品名称", "isRequired": true, "isQuery": true},
{"name": "product_code", "type": "varchar(50)", "comment": "产品编码", "isRequired": true},
{"name": "category_id", "type": "bigint", "comment": "分类ID", "dictType": "product_category"},
{"name": "price", "type": "decimal(10,2)", "comment": "价格"},
{"name": "status", "type": "char(1)", "comment": "状态(0正常 1停用)", "dictType": "sys_normal_disable"},
{"name": "create_time", "type": "datetime", "comment": "创建时间"}
]
}
生成以下文件结构的代码:
输出文件清单:
├── java/
│ ├── domain/{ClassName}.java # 实体类
│ ├── mapper/{ClassName}Mapper.java # Mapper接口
│ ├── service/I{ClassName}Service.java # Service接口
│ ├── service/impl/{ClassName}ServiceImpl.java # Service实现
│ └── controller/{ClassName}Controller.java # REST控制器
├── xml/
│ └── {ClassName}Mapper.xml # MyBatis映射文件
├── vue/
│ ├── api/{businessName}.js # API封装
│ └── views/{moduleName}/{businessName}/index.vue # 页面组件
└── sql/
└── {businessName}Menu.sql # 菜单初始化SQL
className = 表名转大驼峰(去除表前缀如 sys_)moduleName = 表前缀后的模块名businessName = 表名去前缀后的小写形式isPk=true 的字段,默认为 {tableName}_id根据输入计算所有模板变量:
核心变量:
- ${tableName} 表名
- ${tableComment} 表注释
- ${ClassName} 类名(大驼峰)
- ${className} 类名(小驼峰)
- ${moduleName} 模块名
- ${businessName} 业务名
- ${BusinessName} 业务名(首字母大写)
- ${packageName} 包路径
- ${author} 作者
- ${datetime} 生成日期
- ${pkColumn} 主键字段信息
- ${columns} 所有字段列表
- ${permissionPrefix} 权限前缀 (格式: moduleName:businessName)
按顺序读取并填充模板:
templates/ 目录加载对应模板${变量名} 替换为实际值#if/#foreach 逻辑命名规范:
编码规范:
安全规范:
@PreAuthorize 权限注解@Log 日志注解禁止事项:
| 数据库类型 | Java类型 | 说明 |
|-----------|---------|------|
| bigint | Long | 长整型 |
| int/integer | Integer | 整型 |
| varchar/char/text | String | 字符串 |
| datetime/timestamp | Date | 日期时间 |
| date | Date | 日期 |
| decimal/numeric | BigDecimal | 高精度数值 |
| float/double | Double | 浮点数 |
| tinyint(1)/bit | Boolean | 布尔值 |
生成代码时,请参考以下模板文件:
templates/java/ 目录下的 .vm 文件templates/vue/ 目录下的 .vm 文件templates/xml/ 目录下的 .vm 文件templates/sql/ 目录下的 .vm 文件用户: 帮我生成一个产品管理模块的代码,表名是 sys_product
Agent 响应:
用户:
生成代码:
- 表名: biz_order
- 功能: 订单管理
- 包路径: com.ruoyi.business
- 字段: order_id(主键), order_no(订单号), customer_name(客户名), amount(金额), status(状态), create_time(创建时间)
Agent 响应:
已为您生成订单管理模块代码,包含以下文件:
Java后端:
- Order.java (实体类)
- OrderMapper.java (Mapper接口)
- IOrderService.java (Service接口)
- OrderServiceImpl.java (Service实现)
- OrderController.java (控制器)
MyBatis:
- OrderMapper.xml (映射文件)
Vue前端:
- order.js (API封装)
- index.vue (列表页面)
SQL脚本:
- orderMenu.sql (菜单初始化)
[具体代码内容...]
testing
Writes complete WeChat tech posts (hook, TOC, body, checklists, image placement, layout notes, summaries). Use when the user asks to draft a WeChat tech article, generate reusable prompts for writing, or turn a topic/outline into a publish-ready post.
tools
Crafts and rewrites WeChat tech post titles across multiple patterns (list, contrast, outcome, scenario, anti-myth, template). Use when the user needs headline brainstorming or “restrained but clickable” title rewrites for tech/engineering WeChat公众号.
content-media
Defines WeChat tech public-account positioning, audience segmentation, content pillars, and long-term columns. Use when the user asks about account positioning, reader personas, content strategy, or column planning for a tech/engineering WeChat公众号.
development
Builds WeChat-friendly outlines for tech posts, including multi-level TOC, reader-benefit lines per section, pitfalls and action checklists, and 30-second skim summaries. Use when the user asks for outlines, structures, or tutorial-style blueprints for tech/engineering WeChat公众号.