mybatis-plus-generator
npx skills add https://github.com/teachingai/full-stack-skills --skill mybatis-plus-generator
Agent 安装分布
Skill 文档
When to use this skill
CRITICAL: This skill should ONLY be triggered when the user explicitly mentions MyBatis-Plus or mybatis-plus-generator.
ALWAYS use this skill when the user mentions:
- MyBatis-Plus code generation (explicitly mentions “MyBatis-Plus” or “mybatis-plus”)
- Generating MyBatis-Plus code from database tables
- MyBatis-Plus generator or mybatis-plus-generator
- Creating MyBatis-Plus Entity, Mapper, Service, Controller code
- çæ MyBatis-Plus 代ç (explicitly mentions “MyBatis-Plus”)
- MyBatis-Plus 代ç çæå¨ (MyBatis-Plus code generator)
- ä½¿ç¨ MyBatis-Plus çæä»£ç (generate code using MyBatis-Plus)
Trigger phrases include:
- “çæ MyBatis-Plus ä»£ç ” (generate MyBatis-Plus code) – must include “MyBatis-Plus”
- “MyBatis-Plus 代ç çæ” (MyBatis-Plus code generation) – must include “MyBatis-Plus”
- “mybatis-plus-generator” (explicitly mentions the generator)
- “ä½¿ç¨ MyBatis-Plus æ ¹æ®è¡¨ç»æçæä»£ç ” (use MyBatis-Plus to generate code from table structure)
- “MyBatis-Plus çæ EntityãServiceãController” (MyBatis-Plus generate Entity, Service, Controller)
- “MyBatis-Plus 代ç çæå¨” (MyBatis-Plus code generator)
DO NOT trigger this skill for:
- Generic code generation without mentioning MyBatis-Plus
- JPA/Hibernate code generation
- Other ORM frameworks (TypeORM, Sequelize, etc.)
- Generic CRUD operations without MyBatis-Plus context
- “æ ¹æ®è¡¨ç»æçæä»£ç ” without “MyBatis-Plus” (too generic)
- “çæ CRUD ä»£ç ” without “MyBatis-Plus” (too generic)
- “代ç çæå¨” without “MyBatis-Plus” (too generic)
Supported architectures:
- Traditional MVC (Model-View-Controller)
- DDD (Domain-Driven Design)
- Layered Architecture
- Clean Architecture
Supported languages:
- Java
- Kotlin
Supported component types:
- Entity (å®ä½ç±»)
- Mapper (æ°æ®è®¿é®æ¥å£)
- Service (æå¡æ¥å£)
- ServiceImpl (æå¡å®ç°ç±»)
- Controller (æ§å¶å¨)
- DTO (Data Transfer Object)
- VO (Value Object / View Object)
- BO (Business Object)
- Model (æ°æ®æ¨¡å)
How to use this skill
CRITICAL: This skill should ONLY be triggered when the user explicitly mentions MyBatis-Plus or mybatis-plus-generator. Do NOT trigger for generic code generation requests without MyBatis-Plus context.
Workflow Overview
This skill follows a systematic 8-step workflow:
- Collect Configuration – Collect database information, global configuration, package configuration, strategy configuration
- Determine Architecture – Ask user about architecture type (MVC, DDD, etc.) to determine which objects to generate
- Collect Requirements – Ask user for functional requirements to analyze and determine methods to generate
- Determine Language – Ask user about programming language (Java or Kotlin)
- Create Todo List – Generate a detailed todo list with table names, object types, and method names
- Generate Code – Generate code files with intelligent comments based on table structure and requirements
- Progress Updates – Provide real-time progress updates during code generation
- Statistics – Output statistics after generation completes
Step-by-Step Process
Step 1: Collect Configuration
CRITICAL: Before generating any code, you MUST collect the following configuration:
-
Database Information:
- Database type (MySQL, PostgreSQL, Oracle, etc.)
- Database connection URL (or ask user to provide table structure)
- Database name
- Table names (one or multiple tables)
- If user cannot provide database connection, ask for table structure (CREATE TABLE statement or table schema)
-
Global Configuration:
- Author name
- Output directory (default:
src/main/java) - File override strategy (overwrite, skip, ask)
- Enable Lombok (yes/no)
- Enable API documentation (yes/no)
- API Documentation Type (if enabled):
- Swagger 2 (使ç¨
io.swagger.annotations.*) - OpenAPI 3 (使ç¨
io.swagger.v3.oas.annotations.*)
- Swagger 2 (使ç¨
- Enable validation annotations (yes/no)
-
Package Configuration:
- Parent package name (e.g.,
com.example.app) - Entity package (default:
entity) - Mapper package (default:
mapper) - Service package (default:
service) - ServiceImpl package (default:
service.impl) - Controller package (default:
controller) - DTO package (default:
dto) - VO package (default:
vo) - BO package (default:
bo)
- Parent package name (e.g.,
-
Strategy Configuration:
- Naming strategy (camelCase, PascalCase, etc.)
- Table prefix removal (yes/no, prefix name)
- Field naming strategy
- Primary key strategy (AUTO, UUID, etc.)
IMPORTANT: API Documentation Type Selection:
When user enables API documentation, you MUST ask:
è¯·éæ© API ææ¡£ç±»åï¼
- [ ] Swagger 2
- ä½¿ç¨æ³¨è§£ï¼@ApiModel, @ApiModelProperty, @Api, @ApiOperation
- ä¾èµï¼springfox-swagger2, springfox-swagger-ui
- éç¨äºï¼Spring Boot 2.x 项ç®
- [ ] OpenAPI 3
- ä½¿ç¨æ³¨è§£ï¼@Schema, @Tag, @Operation, @Parameter
- ä¾èµï¼springdoc-openapi-ui
- éç¨äºï¼Spring Boot 2.2+ å Spring Boot 3.x 项ç®
Wait for user confirmation before proceeding.
Output: A configuration summary showing all collected information, including API documentation type.
Step 2: Determine Architecture
CRITICAL: You MUST ask the user about the architecture type to determine which objects to generate.
Present architecture options:
è¯·éæ©é¡¹ç®æ¶æç±»åï¼
- [ ] ä¼ ç» MVC (Model-View-Controller)
- çæï¼Entity, Mapper, Service, ServiceImpl, Controller
- [ ] DDD (é¢å驱å¨è®¾è®¡)
- çæï¼Entity, Mapper, Service, ServiceImpl, Controller, DTO, VO, BO
- [ ] å屿¶æ (Layered Architecture)
- çæï¼Entity, Mapper, Service, ServiceImpl, Controller
- [ ] æ´æ´æ¶æ (Clean Architecture)
- çæï¼Entity, Repository, UseCase, Controller, DTO
- [ ] èªå®ä¹æ¶æ
- 请æå®éè¦çæç对象类å
Wait for user confirmation before proceeding.
IMPORTANT: Directory Mapping Based on Architecture
After determining the architecture type, you MUST identify the correct output directories for each generated object.
CRITICAL Steps:
- Ask user for base package path (e.g.,
com.example.order) - Use architecture directory mapping to determine correct paths:
- Quick Reference: See
reference/architecture-directory-quick-reference.mdfor lookup table - Detailed Guide: See
reference/architecture-directory-mapping-guide.mdfor complete mapping rules
- Quick Reference: See
- Verify directory exists or create it if needed
- Generate files in the correct location
Common Path Examples:
For user table with base package com.example.order:
- MVC: Entity â
com/example/order/entity/User.java, Controller âcom/example/order/controller/UserController.java - DDD: Entity â
com/example/order/domain/model/aggregate/user/User.java, Controller âcom/example/order/interfaces/web/controller/UserController.java - Hexagonal: Entity â
com/example/order/domain/model/entity/User.java, Controller âcom/example/order/infrastructure/adapter/inbound/web/controller/UserController.java - Clean: Entity â
com/example/order/domain/entity/User.java, Controller âcom/example/order/infrastructure/web/controller/UserController.java - COLA: Entity â
com/example/order/domain/model/entity/User.java, Controller âcom/example/order/adapter/web/controller/UserController.java
CRITICAL: Always confirm the exact directory structure with the user if the project structure is unclear. Ask: “请确认项ç®çç®å½ç»æï¼ä»¥ä¾¿æå°çæçä»£ç æ¾å¨æ£ç¡®çä½ç½®ã”
Step 3: Collect Requirements
CRITICAL: Ask user for functional requirements to understand what methods need to be generated.
Ask the user:
请æè¿°æ¤æ¬¡çæä»£ç çåè½éæ±ï¼
ä¾å¦ï¼
- ç¨æ·ç®¡çï¼éè¦æ ¹æ®é®ç®±æ¥è¯¢ç¨æ·ãæ ¹æ®ç¨æ·åæ¥è¯¢ç¨æ·ãç¨æ·ç»å½éªè¯
- 订å管çï¼éè¦è®¢åç»è®¡ã订åå页æ¥è¯¢ã订åç¶ææ´æ°
- åå管çï¼éè¦ååæç´¢ãåååç±»æ¥è¯¢ãåºå管ç
è¯·è¯¦ç»æè¿°æ¯ä¸ªè¡¨éè¦åªäºåè½ï¼æä¼æ ¹æ®éæ±èªå¨åæéè¦çæçæ¹æ³ã
After user provides requirements:
-
Analyze requirements to identify:
- Standard CRUD methods (create, read, update, delete)
- Custom query methods (findByEmail, findByUsername, etc.)
- Custom business methods (statistics, aggregation, etc.)
- Custom update methods (updateStatus, updatePassword, etc.)
-
For each table, identify:
- Standard methods needed
- Custom methods needed based on requirements
- Method parameters and return types
- Business logic hints (for method skeletons)
Output: A requirements analysis showing:
- Standard methods for each table
- Custom methods for each table
- Method signatures (parameters and return types)
Step 4: Determine Language
CRITICAL: Ask user about programming language.
è¯·éæ©ç¼ç¨è¯è¨ï¼
- [ ] Java
- [ ] Kotlin
Wait for user confirmation before proceeding.
Note: Templates in templates/ directory support both Java and Kotlin. Use appropriate templates based on user’s choice.
Step 5: Create Todo List
CRITICAL: After collecting all information, create a detailed todo list.
For each table, generate a structured todo list:
## Todo List: MyBatis-Plus Code Generation
### Table: user
#### Entity å±
- [ ] User.java - å®ä½ç±»
- [ ] 类注é
- [ ] åæ®µå®ä¹ï¼id, username, email, password, status, createTime, updateTimeï¼
- [ ] åæ®µæ³¨é
#### Mapper å±
- [ ] UserMapper.java - æ°æ®è®¿é®æ¥å£
- [ ] 类注é
- [ ] åºç¡ CRUD æ¹æ³ï¼ç»§æ¿ BaseMapperï¼
#### Service å±
- [ ] UserService.java - æå¡æ¥å£
- [ ] 类注é
- [ ] saveUser() - ä¿åç¨æ·
- [ ] findById() - æ ¹æ®IDæ¥è¯¢
- [ ] updateUser() - æ´æ°ç¨æ·
- [ ] deleteById() - å é¤ç¨æ·
- [ ] findByEmail() - æ ¹æ®é®ç®±æ¥è¯¢ï¼èªå®ä¹æ¹æ³ï¼
- [ ] findByUsername() - æ ¹æ®ç¨æ·åæ¥è¯¢ï¼èªå®ä¹æ¹æ³ï¼
#### ServiceImpl å±
- [ ] UserServiceImpl.java - æå¡å®ç°ç±»
- [ ] 类注é
- [ ] å®ç°ææ Service æ¥å£æ¹æ³
- [ ] æ¹æ³æ³¨éåå®ç°éª¨æ¶
#### Controller å±
- [ ] UserController.java - æ§å¶å¨
- [ ] 类注é
- [ ] createUser() - åå»ºç¨æ·
- [ ] getUserById() - æ¥è¯¢ç¨æ·
- [ ] updateUser() - æ´æ°ç¨æ·
- [ ] deleteUser() - å é¤ç¨æ·
- [ ] getUserByEmail() - æ ¹æ®é®ç®±æ¥è¯¢ï¼èªå®ä¹æ¥å£ï¼
#### DTO å±ï¼å¦ææ¶æéè¦ï¼
- [ ] UserCreateDTO.java - åå»ºç¨æ·DTO
- [ ] UserUpdateDTO.java - æ´æ°ç¨æ·DTO
- [ ] UserQueryDTO.java - æ¥è¯¢ç¨æ·DTO
#### VO å±ï¼å¦ææ¶æéè¦ï¼
- [ ] UserVO.java - ç¨æ·è§å¾å¯¹è±¡
### Table: order
...
Important:
- Organize by table
- List all objects that need to be generated
- Include all methods (standard + custom)
- Use checkboxes for tracking progress
Step 6: Generate Code
CRITICAL: Generate code files with intelligent comments based on table structure and requirements.
Order of generation:
- Entity – First (base for all other objects)
- Mapper – Second (data access layer)
- Service – Third (business interface)
- ServiceImpl – Fourth (business implementation)
- Controller – Fifth (API layer)
- DTO/VO/BO – Sixth (if needed by architecture)
For each object:
- Load appropriate template from
templates/directory based on object type and language - Analyze table structure: Read columns, types, constraints, primary keys, foreign keys, relationships
- Generate intelligent comments: Based on business context, not just technical names
- Class comments: Explain purpose, list main fields
- Method comments: Explain business logic, include all parameters and return types
- Field comments: Explain business meaning, not just column names
- Generate code: Replace template variables, add annotations, generate method skeletons
- For custom methods: Generate signatures, add business logic comments, add TODO hints
- Determine output directory: Use architecture directory mapping (see Step 2)
- Save files to correct location based on architecture and package configuration
After generating each object:
- Update the todo list: mark completed items with
[x] - Show progress to the user
- Continue to the next object
Code Generation Standards: See reference/code-generation-standards.md for detailed requirements on comments, templates, and code quality.
Step 7: Progress Updates
CRITICAL: Provide real-time progress updates during code generation.
Update progress after:
- Each table starts processing
- Each object is generated
- Each method is added
- Each table completes
Progress Format: See reference/progress-and-statistics-formats.md for detailed progress update format and examples.
Step 8: Statistics
CRITICAL: After all code generation completes, output comprehensive statistics.
Statistics Format: See reference/progress-and-statistics-formats.md for detailed statistics format including:
- Overall statistics (tables, objects, methods, files, lines)
- Per-table statistics
- Per-type statistics
- File locations
- Code quality checklist
Code Generation Standards
IMPORTANT: Generated code must include intelligent, context-aware comments, not just template placeholders.
Key Requirements:
- Class Comments: Explain purpose based on business context, include table mapping, list main fields
- Method Comments: Explain business logic, include all parameters with types, return value with type, exceptions
- Field Comments: Explain business meaning, include data type and constraints, not just column names
Detailed Standards: See reference/code-generation-standards.md for:
- Complete comment format requirements
- Template usage guidelines
- Template variables reference
- Swagger annotation selection
- Custom method generation standards
- Code quality requirements
Best Practices
- Intelligent Comments: Generate comments based on table structure analysis and business requirements, not just template placeholders
- Context Awareness: Understand table relationships and business context to generate meaningful comments
- Method Analysis: Analyze user requirements to determine what methods are needed
- Progress Tracking: Always update todo list and show progress
- Code Quality: Generate production-ready code with proper annotations and validation
- Template Enhancement: Use templates as base, but enhance with intelligent additions
- Language Support: Support both Java and Kotlin with appropriate templates
Reference Documentation
CRITICAL: Use these reference documents for detailed guidance:
Architecture & Directory Mapping
reference/architecture-directory-mapping-guide.md– Complete directory mapping guide for all architectures (CRITICAL)reference/architecture-directory-quick-reference.md– Quick lookup table for directory mappings
Code Generation Standards
reference/code-generation-standards.md– Detailed comment standards, template usage, and code quality requirementsreference/template-variables.md– Complete list of template variablesreference/swagger-annotations-guide.md– Swagger 2 vs OpenAPI 3 annotation comparison
Progress & Statistics
reference/progress-and-statistics-formats.md– Progress update and statistics output formats
MyBatis-Plus Reference
reference/mybatis-plus-generator-guide.md– MyBatis-Plus Generator usage guide
Examples
See the examples/ directory for complete examples:
examples/mvc-architecture-example.md– MVC architecture generation exampleexamples/ddd-architecture-example.md– DDD architecture generation exampleexamples/full-workflow-example.md– Complete workflow exampleexamples/architecture-directory-mapping.md– Directory mapping examples for different architecturesexamples/swagger-annotations-example.md– Swagger 2 vs OpenAPI 3 annotation examples
Templates
Templates are located in templates/ directory, using FreeMarker syntax (.ftl files), strictly following MyBatis-Plus official templates.
Standard Templates (MVC Architecture)
Java Templates:
entity.java.ftl– Entity class templatemapper.java.ftl– Mapper interface templateservice.java.ftl– Service interface templateserviceImpl.java.ftl– Service implementation templatecontroller.java.ftl– Controller templatedto.java.ftl– DTO templatevo.java.ftl– VO templatebo.java.ftl– BO template
Kotlin Templates:
entity.kt.ftl– Entity data class templatemapper.kt.ftl– Mapper interface templateservice.kt.ftl– Service interface templateserviceImpl.kt.ftl– Service implementation templatecontroller.kt.ftl– Controller templatedto.kt.ftl– DTO templatevo.kt.ftl– VO templatebo.kt.ftl– BO template
DDD Architecture Templates
All DDD templates are located in templates/ root directory, supporting both Java and Kotlin:
Domain Layer:
aggregate-root.java.ftl/aggregate-root.kt.ftl– Aggregate root templaterepository.java.ftl/repository.kt.ftl– Repository interface template (domain layer)domain-service.java.ftl/domain-service.kt.ftl– Domain service templatevalue-object.java.ftl/value-object.kt.ftl– Value object templatedomain-event.java.ftl/domain-event.kt.ftl– Domain event template
Application Layer:
application-service.java.ftl/application-service.kt.ftl– Application service template
Interface Layer:
assembler.java.ftl/assembler.kt.ftl– DTO assembler template
Template Features:
- Support for Swagger 2 and OpenAPI 3 annotations
- Intelligent comments based on table structure
- Custom method generation support
- Kotlin-specific features (data classes, null safety, etc.)
- DDD-specific patterns (aggregate root, value objects, domain events)
- FreeMarker syntax for template engine
Reference: See MyBatis-Plus official templates at:
Keywords
English keywords: mybatis-plus, mybatis-plus-generator, mybatis-plus code generator, mybatis-plus code generation, generate mybatis-plus code, mybatis-plus entity generator, mybatis-plus mapper generator, mybatis-plus service generator, mybatis-plus controller generator, mybatis-plus crud generation, mybatis-plus from table, mybatis-plus code from database
Chinese keywords (ä¸æå ³é®è¯): MyBatis-Plus, mybatis-plus-generator, MyBatis-Plus 代ç çæå¨, MyBatis-Plus 代ç çæ, çæ MyBatis-Plus 代ç , MyBatis-Plus å®ä½ç±»çæ, MyBatis-Plus Mapper çæ, MyBatis-Plus Service çæ, MyBatis-Plus Controller çæ, MyBatis-Plus CRUD çæ, MyBatis-Plus æ ¹æ®è¡¨çæä»£ç , MyBatis-Plus æ°æ®åºè½¬ä»£ç , MyBatis-Plus 表转 Java, ä½¿ç¨ MyBatis-Plus çæä»£ç
IMPORTANT: All keywords must include “MyBatis-Plus” or “mybatis-plus” to avoid false triggers. Generic terms like “代ç çæå¨” (code generator) or “æ ¹æ®è¡¨çæä»£ç ” (generate code from table) without “MyBatis-Plus” should NOT trigger this skill.