RuoYi AI 代码生成器
Overview
This skill enables AI-driven code generation for RuoYi-Vue-Plus framework, providing intelligent code generation that understands business context from table names, comments, and column definitions. It can generate production-ready Java backend code and Vue3 frontend code with minimal manual adjustments.
Key Capabilities:
- Parse database table structures (GenTable/GenTableColumn)
- Generate intelligent Java backend code (Controller, Service, Mapper, Domain, VO, BO)
- Generate Vue3 frontend code (Pages, TypeScript API, Type definitions)
- Generate SQL menu scripts
- Understand business semantics from table comments
When to Use
Use this skill when:
- User requests AI-powered code generation for RuoYi projects
- User wants to generate code from database tables with intelligent business logic
- User needs to customize or replace Velocity templates
- User asks about "AI code generation", "smart code generator", or "intelligent CRUD generation"
- Working with
ruoyi-generatormodule files
Workflow Decision Tree
User Request
│
├──► "生成XX表的代码" / "Generate code for table"
│ └──► Analyze table structure → Generate complete code → Output files
│
├──► "优化模板" / "Improve templates"
│ └──► Load references/ruoyi-architecture.md → Analyze → Suggest improvements
│
├──► "添加AI生成功能" / "Add AI generation"
│ └──► Read GenTableServiceImpl → Create AiCodeGenerator → Integrate
│
└──► "对比AI和Velocity" / "Compare AI vs Velocity"
└──► Load references/comparison.md → Analyze trade-offs → Recommend
Core Capabilities
1. Intelligent Code Analysis
Before generating code, analyze:
- Table name patterns (e.g.,
sys_user= system user management) - Column comments for business semantics
- Field types and constraints
- Relationships between tables
Load reference: references/ruoyi-architecture.md for framework conventions
2. Java Backend Code Generation
Generate these components with intelligent defaults:
| Component | Location Pattern | AI Enhancement |
|---|---|---|
| Domain | domain/{ClassName}.java |
Smart field validation, comments |
| VO | domain/vo/{ClassName}Vo.java |
View-oriented field selection |
| BO | domain/bo/{ClassName}Bo.java |
Business operation fields |
| Mapper | mapper/{ClassName}Mapper.java |
Custom SQL for complex queries |
| Service | service/I{ClassName}Service.java |
Business method signatures |
| ServiceImpl | service/impl/{ClassName}ServiceImpl.java |
Implementation with validation |
| Controller | controller/{ClassName}Controller.java |
REST API with permissions |
3. Vue3 Frontend Code Generation
Generate modern Vue3 + TypeScript code:
| Component | Location Pattern | Features |
|---|---|---|
| API | api/{module}/{business}/index.ts |
Axios calls, error handling |
| Types | api/{module}/{business}/types.ts |
TypeScript interfaces |
| Vue Page | views/{module}/{business}/index.vue |
CRUD table, forms, dialogs |
4. Code Quality Guidelines
Generated code should follow RuoYi conventions:
- Use Lombok annotations (
@Data,@RequiredArgsConstructor) - Include Bean Validation (
@NotBlank,@Size) - Add Swagger annotations (
@Schema) - Follow RESTful API design
- Include proper exception handling
- Generate meaningful comments from table metadata
Generation Strategies
Strategy 1: Full AI Generation (High Flexibility)
Table Structure → AI Analysis → Direct Code Output
Best for: Complex business logic, custom requirements
Strategy 2: Template Enhancement (Balanced)
Table Structure → AI Enhance → Velocity Template → Code Output
Best for: Consistent structure with intelligent content
Strategy 3: Hybrid (Recommended)
Simple CRUD → Velocity Template
Complex Logic → AI Generation
Best for: Production use, optimal speed and quality
Implementation Guide
Adding AI Generation to RuoYi
Create AiCodeGenerator Service
Path: ruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/service/AiCodeGenerator.javaModify GenTableServiceImpl
- Add AI generation branch in
previewCode()method - Add configuration flag for AI mode
- Add AI generation branch in
Create AI Prompt Builder
- Convert GenTable/GenTableColumn to structured prompt
- Include framework conventions
Reference: references/gen-table-schema.md for data structure details
Prompt Engineering Template
String buildGenerationPrompt(GenTable table, String codeType) {
return """
Generate %s code for RuoYi-Vue-Plus framework.
Table Information:
- Name: %s
- Comment: %s
- Class Name: %s
- Module: %s
- Business: %s
Columns:
%s
Requirements:
1. Follow RuoYi naming conventions
2. Use proper validation annotations
3. Include Swagger documentation
4. Handle relationships if any
5. Return only the code, no explanations
""".formatted(
codeType,
table.getTableName(),
table.getTableComment(),
table.getClassName(),
table.getModuleName(),
table.getBusinessName(),
formatColumns(table.getColumns())
);
}
Resources
references/
ruoyi-architecture.md- Framework architecture and conventionsgen-table-schema.md- GenTable/GenTableColumn data structuresvelocity-templates.md- Existing Velocity template referencecode-examples.md- High-quality code examples for AI training
assets/
java-templates/- Java code templatesvue-templates/- Vue3 code templates
Best Practices
- Always validate AI-generated code before using in production
- Cache AI responses for identical table structures to save costs
- Use hybrid approach - Velocity for structure, AI for content
- Maintain fallback - Always have Velocity as backup
- Version control generated code for auditing
Integration Points
Key files to integrate with:
ruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/service/GenTableServiceImpl.javaruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/util/VelocityUtils.javaruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/domain/GenTable.javaruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/domain/GenTableColumn.java
Converted and distributed by TomeVault — claim your Tome and manage your conversions.