crud-rest-controller
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePreflight: Spring MCP
前置检查:Spring MCP
This skill is part of the Spring Agent Toolkit and is designed to work with the Spring MCP server (provided by the Amplicode IntelliJ plugin). Before doing anything else, check your tool list for any Spring MCP tool — they are exposed under the MCP server (e.g. , , ); harnesses that flatten MCP tools into the tool list use the prefix on the same names.
amplicodeget_project_summarylist_module_dependenciesget_entity_detailsmcp__amplicode__- If at least one Amplicode tool is available — MCP is connected. Proceed with the skill below.
- If none are available — stop and invoke the skill (bundled with the Spring Agent Toolkit). It installs the Amplicode plugin and walks the user through the «Настроить Spring Agent» welcome-screen button + MCP-client restart. After it completes, the MCP tools become available — resume this skill.
amplicode-install - If is not registered in your skill list, tell the user (in their language): "This skill needs the Amplicode IntelliJ plugin and its MCP server. Install it from https://amplicode.ru/marketplace into IntelliJ IDEA Ultimate/Community or GigaIDE, open any project, click «Настроить Spring Agent» on the Amplicode welcome screen, then restart your MCP client."
amplicode-install
此技能是Spring Agent Toolkit的一部分,旨在与Spring MCP server(由Amplicode IntelliJ插件提供)配合使用。在进行任何操作之前,请检查你的工具列表中是否有Spring MCP工具——它们在 MCP服务器下暴露(例如、、);将MCP工具扁平化到工具列表的工具会在相同名称前添加前缀。
amplicodeget_project_summarylist_module_dependenciesget_entity_detailsmcp__amplicode__- 如果至少有一个Amplicode工具可用——MCP已连接。继续使用下方的技能。
- 如果没有可用的Amplicode工具——停止操作并调用****技能(随Spring Agent Toolkit捆绑提供)。它会安装Amplicode插件,并引导用户完成«Настроить Spring Agent»欢迎屏幕按钮 + MCP客户端重启的流程。完成后,MCP工具将可用——恢复此技能的使用。
amplicode-install - 如果你的技能列表中未注册,请用用户的语言告知:"此技能需要Amplicode IntelliJ插件及其MCP服务器。请从https://amplicode.ru/marketplace安装到IntelliJ IDEA Ultimate/Community或GigaIDE中,打开任意项目,点击Amplicode欢迎屏幕上的«Настроить Spring Agent»,然后重启你的MCP客户端。"
amplicode-install
CRUD REST Controller
CRUD REST控制器
Generates a class with standard CRUD endpoints for an entity,
using a Spring Data repository, optional DTO mapping, pagination, filtering, and patch support.
@RestControllerCRITICAL: Code ONLY from examples/ files. If no matching example -- STOP and ask user. CRITICAL: For questions with a fixed set of choices, prefer> its analogue > plain text list. Plain numbered text lists are the last resort when no interactive tool is available. CRITICAL: Read the conversation context BEFORE running Step 1. Half the questions in Steps 2–4 may already be answered by the user's prompt and prior turns. Re-asking what was already said is the #1 reason this skill feels slow.AskUserQuestion
生成一个类,为实体提供标准CRUD接口,使用Spring Data仓库、可选的DTO映射、分页、过滤和补丁支持。
@RestController重要提示:仅从examples/文件中生成代码。如果没有匹配的示例——停止操作并询问用户。 重要提示:对于有固定选项的问题,优先使用工具 > 类似工具 > 纯文本列表。只有在没有交互式工具可用时,才将纯编号文本列表作为最后手段。 重要提示:在运行步骤1之前,请阅读对话上下文。步骤2-4中的一半问题可能已经由用户的提示和之前的对话回合回答过。重复询问已回答的问题是此技能显得缓慢的首要原因。AskUserQuestion
Defaults
默认设置
The options below are grouped by topic. and are
auto-detected; all other options are resolved via the Decision-making
principle (derive from context → confirm → ask).
languagebootVersion以下选项按主题分组。和会自动检测;所有其他选项通过决策原则解决(从上下文推导 → 确认 → 询问)。
languagebootVersionBlock 1 — Entity & repository
模块1 — 实体与仓库
| Option | Default | Notes |
|---|---|---|
| entity | -- | which entity to create controller for |
| repository | first existing for entity | which repository to use |
| 选项 | 默认值 | 说明 |
|---|---|---|
| entity | -- | 要为其创建控制器的实体 |
| repository | 实体对应的第一个现有仓库 | 使用哪个仓库 |
Block 2 — DTO mode
模块2 — DTO模式
| Option | Default | Notes |
|---|---|---|
| DTO mode | DTO (recommended) | if no existing DTO for entity, delegate to |
| 选项 | 默认值 | 说明 |
|---|---|---|
| DTO模式 | DTO(推荐) | 如果实体没有现有DTO,委托给 |
Block 3 — Controller naming & paths
模块3 — 控制器命名与路径
| Option | Default | Notes |
|---|---|---|
| controllerName | | suggest based on project naming convention |
| controllerPackage | same as existing controllers or mainPackage | auto-detected from project |
| basePath | | persistent base path |
| resourcePath | | auto from entity name |
| 选项 | 默认值 | 说明 |
|---|---|---|
| controllerName | | 根据项目命名约定建议 |
| controllerPackage | 与现有控制器相同或主包 | 从项目中自动检测 |
| basePath | | 持久化基础路径 |
| resourcePath | | 从实体名称自动生成 |
Block 4 — Pagination & filtering
模块4 — 分页与过滤
| Option | Default | Notes |
|---|---|---|
| pagination | true | enable pagination for GET_LIST |
| paginationType | PAGE | PAGE or WINDOW (WINDOW requires filter to be selected; avoids count query overhead) |
| filter | None | JPA Specification filter for GET_LIST |
| 选项 | 默认值 | 说明 |
|---|---|---|
| pagination | true | 为GET_LIST启用分页 |
| paginationType | PAGE | PAGE或WINDOW(WINDOW需要选择过滤器;避免计数查询开销) |
| filter | None | 用于GET_LIST的JPA Specification过滤器 |
Auto-detected (no questions)
自动检测(无需询问)
| Option | Source |
|---|---|
| patchStrategy | ObjectMapper |
| language | |
| bootVersion | |
Smart defaults: If user says "use defaults", "all defaults", "default settings",
or similar -- skip ALL questions where "Always ask?" = NO. Only ask mandatory questions.
Smart answer recognition: When user provides a value instead of choosing from a numbered
list, accept it directly. Examples:
- Question "Which entity?" --> user answers "Product" --> this IS the entity, don't re-ask
- Question "Repository?" --> user answers "ProductRepository" --> this IS the choice
- If user provides multiple answers in one message --> accept all, skip answered questions
- NEVER ask a question that the user already answered (even implicitly)
Batch questions: When multiple questions must be asked (i.e. cannot be
resolved by principles 1–2 of the Decision-making principle), group them
into a single call (up to 4 questions per call) when they:
AskUserQuestion- Belong to the same logical section
- Don't depend on each other's answers
Rules:
- Maximum 3-4 questions per call
AskUserQuestion - Mark the recommended option with and place it first
(Recommended) - Never batch questions from DIFFERENT decision branches
- The primary branching question (entity selection) is always asked ALONE
- Prefer for choices; fall back to plain text lists only if the tool is unavailable
AskUserQuestion
| 选项 | 来源 |
|---|---|
| patchStrategy | ObjectMapper |
| language | |
| bootVersion | |
智能默认值: 如果用户说"使用默认值"、"全部默认"、"默认设置"或类似表述——跳过所有"是否始终询问?"为NO的问题。仅询问必填问题。
智能答案识别: 当用户提供一个值而不是从编号列表中选择时,直接接受该值。示例:
- 问题"选择哪个实体?" → 用户回答"Product" → 这就是实体,不要再询问
- 问题"选择哪个仓库?" → 用户回答"ProductRepository" → 这就是选择项
- 如果用户在一条消息中提供多个答案 → 全部接受,跳过已回答的问题
- 永远不要询问用户已经回答过的问题(即使是隐含回答)
批量问题: 当必须询问多个问题(即无法通过决策原则1-2解决)时,将它们分组到一个调用中(每次调用最多4个问题),前提是:
AskUserQuestion- 属于同一逻辑部分
- 彼此的答案不依赖
规则:
- 每次调用最多包含3-4个问题
AskUserQuestion - 用标记推荐选项,并将其放在首位
(推荐) - 永远不要批量处理不同决策分支的问题
- 主要分支问题(实体选择)始终单独询问
- 优先使用进行选择;只有在工具不可用时才回退到纯文本列表
AskUserQuestion
Decision-making principle — context first, then ask
决策原则 — 优先上下文,再询问
Before asking the user any question, attempt to derive the answer from
the context already gathered: project summary, module dependencies, entity
details, existing files in the package, prior turns of this conversation,
and the user's original prompt. Only ask when the context yields no
clear default or when the choice is genuinely user-specific (e.g. which
entity, which repository).
Hierarchy of decisions:
-
Context is unambiguous → decide silently, do NOT ask. Examples: language and JDK from; repository when there is exactly one for the entity; controller package from existing controllers; basePath from existing endpoints; Jackson version from
get_project_summary; pagination type when project already uses one consistently.list_module_dependencies -
Context gives a strong signal → state the decision + alternatives in one line, let the user override or stay silent. Format:
Will create `ProductController` at `/rest/products` with Page pagination, no DTO. Alternatives: use DTO, Window pagination, custom paths. OK?The user can answer "ok" / "yes" / silence → accept; or name an alternative → switch. This is not the same as the numbered question format — it is a single confirmation line. -
Context yields no clear default → ask with(preferred) or its analogue, with the recommended option first. When
AskUserQuestionis available, use it with the recommended option markedAskUserQuestionand placed first. If no interactive choice tool is available, fall back to a plain text list. Never ask iteratively ("which entity?" → user picks → "repository?" → …) when one batched call would do.(Recommended) -
Context is fully empty for a critical input → ask plainly. This applies to: which entity (when not mentioned), the user's intent itself.
在向用户询问任何问题之前,尝试从已收集的上下文(项目摘要、模块依赖、实体详情、包中的现有文件、本次对话的先前回合以及用户的原始提示)中推导答案。只有当上下文没有明确默认值或选择确实由用户决定(例如选择哪个实体、哪个仓库)时,才进行询问。
决策层级:
-
上下文明确 → 静默决定,不询问。 示例:来自的语言和JDK;实体只有一个仓库时的仓库选择;从现有控制器获取的控制器包;从现有端点获取的basePath;从
get_project_summary获取的Jackson版本;项目已一致使用的分页类型。list_module_dependencies -
上下文给出强烈信号 → 陈述决定 + 替代方案,让用户覆盖或保持沉默。 格式:
将创建`ProductController`,路径为`/rest/products`,使用Page分页,不使用DTO。 替代方案:使用DTO、Window分页、自定义路径。是否确认?用户可以回答"ok" / "yes" / 保持沉默 → 接受;或指定替代方案 → 切换。这与编号问题格式不同——它是单行确认语句。 -
上下文没有明确默认值 → 使用(优先)或类似工具询问,推荐选项放在首位。 当
AskUserQuestion可用时,使用该工具,推荐选项标记为AskUserQuestion并放在首位。如果没有交互式选择工具可用,回退到纯文本列表。 永远不要在一次批量调用可以完成的情况下迭代询问("哪个实体?" → 用户选择 → "哪个仓库?" → …)(推荐) -
关键输入的上下文完全为空 → 直接询问。 适用于:未提及的实体选择、用户本身的意图。
How to ask — prefer AskUserQuestion
AskUserQuestion询问方式 — 优先使用AskUserQuestion
AskUserQuestionWhen a question must be asked, prefer the tool (or
its analogue) over writing a numbered list in the response body. Fall back
to plain text only if no interactive choice tool is available.
AskUserQuestionRules for calls in this skill:
AskUserQuestion- Each call may contain up to 4 questions that are independent of each other (the tool will render them together). Use this to batch related decisions in one round-trip.
- Each question has 2–4 options. The tool auto-adds an "Other" choice for free-form input — never include it manually.
- Mark the recommended option by putting it first with appended to the label.
(Recommended) - is a 12-char chip label (e.g. "Entity", "DTO mode", "Paths").
header - Each option has a explaining what the choice means.
description
When is not the right tool:
AskUserQuestion- Free-form input where there is no enumerable set of options (e.g. arbitrary class name, arbitrary path) — ask in plain text.
- The "single confirmation line" form from principle 2 — that is a plain question with an obvious yes/no, not an enumerated choice.
The screen-driven question lists in Steps 2–4 below are a fallback for
case 4. They are NOT a script to execute top-to-bottom. If a question's
answer is already determined by principles 1–3, skip the question.
当必须询问问题时,优先使用****工具(或类似工具),而不是在响应正文中编写编号列表。只有在没有交互式选择工具可用时才回退到纯文本。
AskUserQuestion此技能中调用的规则:
AskUserQuestion- 每次调用可包含最多4个相互独立的问题(工具会将它们一起呈现)。用此将相关决策批量处理在一次往返中。
- 每个问题有2-4个选项。工具会自动添加"其他"选项用于自由输入——不要手动添加。
- 通过将推荐选项放在首位并在标签后附加来标记它。
(推荐) - 是12字符以内的标签(例如"实体"、"DTO模式"、"路径")。
header - 每个选项都有解释选择的含义。
description
当不是合适工具的情况:
AskUserQuestion- 没有可枚举选项的自由输入(例如任意类名、任意路径)→ 用纯文本询问。
- 原则2中的"单行确认语句"形式——这是带有明显是/否的简单问题,不是枚举选择。
以下步骤2-4中的屏幕驱动问题列表是回退方案,适用于情况4。它们不是从上到下执行的脚本。如果问题的答案已通过原则1-3确定,跳过该问题。
Step 0 -- Conversation context first (REQUIRED, no tool calls)
步骤0 -- 先查看对话上下文(必填,无需调用工具)
Before any MCP call, before any question, re-read the user's prompt and
the prior turns of this conversation and extract whatever is already
stated. This step costs nothing and prevents the most common failure mode
of this skill — asking the user something they already said.
Build a mental checklist of inputs and tick off everything the user has
already provided, explicitly or implicitly:
| Input | Look for in the prompt / context |
|---|---|
| entity | a class name ( |
| repository | "use |
| DTO mode | "with DTO", "without DTO", "use entity directly", "map to |
| controller name | "name it |
| paths | "at |
| pagination | "with pagination", "no pagination", "use Window", "use Page" |
| filter | "with filter", "no filter", "use JPA Specification" |
| methods | "all CRUD", "only read", "read-only", "without delete", "GET + CREATE", "full CRUD" |
| smart defaults | "use defaults", "all defaults", "default settings", "as usual" |
| prior project facts | language, JDK, dependencies — already known if discussed earlier in this conversation; do not re-fetch |
For every input that is explicitly or strongly implicitly answered:
mark it as decided and skip the corresponding question in Steps 2–4. Do
NOT ask "which entity?" if the user wrote "create CRUD controller for
Product" — is the answer. Do NOT ask "which repository?" if
there is exactly one repository for the entity.
ProductFor every input that is not answered: defer to the Decision-making
principle above — try to derive it from project context first (Step 1),
and only then ask.
Step 0 is mental, not a tool call. Do not announce it to the user. Do not
write "Step 0 done". Just internalize what the user already said before
proceeding to Step 1.
在调用任何MCP工具、询问任何问题之前,重新阅读用户的提示和本次对话的先前回合,提取已陈述的所有信息。此步骤没有成本,可避免此技能最常见的失败模式——询问用户已经说过的内容。
构建输入清单,勾选用户已明确或隐含提供的所有内容:
| 输入 | 在提示/上下文中查找 |
|---|---|
| entity | 类名( |
| repository | "使用 |
| DTO mode | "使用DTO"、"不使用DTO"、"直接使用实体"、"映射到 |
| controller name | "命名为 |
| paths | "路径为 |
| pagination | "带分页"、"无分页"、"使用Window"、"使用Page" |
| filter | "带过滤器"、"无过滤器"、"使用JPA Specification" |
| methods | "完整CRUD"、"仅只读"、"只读"、"不带删除"、"GET + CREATE"、"全CRUD" |
| smart defaults | "使用默认值"、"全部默认"、"默认设置"、"照常" |
| prior project facts | 语言、JDK、依赖——如果在本次对话之前讨论过则已了解;不要重新获取 |
对于每个明确或强烈隐含回答的输入:标记为已决定,跳过步骤2-4中对应的问题。如果用户写了"为Product创建CRUD控制器",不要询问"哪个实体?"——就是答案。如果实体只有一个仓库,不要询问"哪个仓库?"。
Product对于每个未回答的输入:遵循上述决策原则——先尝试从项目上下文推导(步骤1),然后再询问。
步骤0是心理步骤,不是工具调用。不要向用户宣布。不要写"步骤0完成"。只需在继续步骤1之前内化用户已经说过的内容。
Step 1 -- Gather minimal project context (automatic, no questions)
步骤1 -- 收集最少的项目上下文(自动,无需询问)
Call only the MCP tools whose result is actually consumed by a later
step. Do not pre-fetch "in case we need it" — every variable here must
have a concrete downstream user.
| Tool | Variable | Used for |
|---|---|---|
| | language → reference file selection (java vs kotlin); bootMajor → jakarta vs javax, Jackson version; moduleName → multi-module disambiguation; buildFile → Step 6 dependency injection; mainPackage → controller package fallback |
| | derived flags below — SpringDoc/Validation/Jackson feature gates, Step 6 dependency check |
| | Step 4 path conflict detection, existing basePath/naming convention detection |
That is the entire Step 1. Do NOT fetch:
- — needed only if the user did not name an entity in their prompt. Defer to Step 2 as a lazy fallback.
list_all_domain_entities - — depends on knowing the entity, which happens in Step 2. Defer to Step 3 as a lazy fallback.
list_entity_repositories - — depends on knowing the entity. Defer to Step 2.
get_entity_details - /
list_entity_dtos— depend on knowing the entity AND the DTO decision. Defer to Step 4.list_entity_mappers
After calling , determine:
get_project_summary- : Java or Kotlin
language - : 2, 3 or 4 (for jakarta vs javax, Jackson version)
bootMajor - Check if is in
org.springdoc:springdoc-openapi-->presentDepshasSpringDoc - Check if or
org.hibernate.validator:hibernate-validatoris inorg.springframework.boot:spring-boot-starter-validation-->presentDepshasValidation - Jackson version detection: Check for
presentDepsortools.jackson:jackson-databind-->tools.jackson:jackson-core. Otherwise ifjacksonMajor = 3-->com.fasterxml.jackson:jackson-databind. Spring Boot 4.x uses Jackson 3.x (jacksonMajor = 2package), Spring Boot 2.x/3.x use Jackson 2.x (tools.jacksonpackage).com.fasterxml.jackson- If :
jacksonMajor = 3=JsonNodeFqn,tools.jackson.databind.JsonNode=ObjectMapperFqntools.jackson.databind.ObjectMapper - If :
jacksonMajor = 2=JsonNodeFqn,com.fasterxml.jackson.databind.JsonNode=ObjectMapperFqncom.fasterxml.jackson.databind.ObjectMapper
- If
- PagedModel detection: (
PagedModel) is available in Spring Data 3.2+. Iforg.springframework.data.web.PagedModel(Spring Boot 3.2+) orbootMajor >= 3, usebootMajor = 4wrapper for GET_LIST with Page pagination. Otherwise returnPagedModeldirectly.Page<Entity>
If multi-module project (multiple modules in ):
Ask which module to use. Then re-call module-specific MCP tools with that module.
get_project_summary仅调用结果会在后续步骤中实际使用的MCP工具。不要提前获取"以防需要"——此处的每个变量必须有明确的下游用途。
| 工具 | 变量 | 用途 |
|---|---|---|
| | language → 参考文件选择(java vs kotlin);bootMajor → jakarta vs javax、Jackson版本;moduleName → 多模块区分;buildFile → 步骤6依赖注入;mainPackage → 控制器包回退 |
| | 派生以下标志——SpringDoc/Validation/Jackson功能开关,步骤6依赖检查 |
| | 步骤4路径冲突检测、现有basePath/命名约定检测 |
这就是步骤1的全部内容。不要获取:
- ——仅当用户在提示中未指定实体时才需要。推迟到步骤2作为惰性回退。
list_all_domain_entities - ——依赖于实体的确定,这发生在步骤2。推迟到步骤3作为惰性回退。
list_entity_repositories - ——依赖于实体的确定。推迟到步骤2。
get_entity_details - /
list_entity_dtos——依赖于实体的确定和DTO决策。推迟到步骤4。list_entity_mappers
调用后,确定:
get_project_summary- : Java或Kotlin
language - : 2、3或4(用于区分jakarta vs javax、Jackson版本)
bootMajor - 检查中是否有
presentDeps→org.springdoc:springdoc-openapihasSpringDoc - 检查中是否有
presentDeps或org.hibernate.validator:hibernate-validator→org.springframework.boot:spring-boot-starter-validationhasValidation - Jackson版本检测: 检查中是否有
presentDeps或tools.jackson:jackson-databind→tools.jackson:jackson-core。否则如果有jacksonMajor = 3→com.fasterxml.jackson:jackson-databind。Spring Boot 4.x使用Jackson 3.x(jacksonMajor = 2包),Spring Boot 2.x/3.x使用Jackson 2.x(tools.jackson包)。com.fasterxml.jackson- 如果:
jacksonMajor = 3=JsonNodeFqn,tools.jackson.databind.JsonNode=ObjectMapperFqntools.jackson.databind.ObjectMapper - 如果:
jacksonMajor = 2=JsonNodeFqn,com.fasterxml.jackson.databind.JsonNode=ObjectMapperFqncom.fasterxml.jackson.databind.ObjectMapper
- 如果
- PagedModel检测: (
PagedModel)在Spring Data 3.2+中可用。如果org.springframework.data.web.PagedModel(Spring Boot 3.2+)或bootMajor >= 3,对使用Page分页的GET_LIST使用bootMajor = 4包装器。否则直接返回PagedModel。Page<Entity>
如果是多模块项目(中有多个模块):询问使用哪个模块。然后使用该模块重新调用特定模块的MCP工具。
get_project_summaryStep 2 -- Select entity
步骤2 -- 选择实体
By Step 0 you should already know the entity if the user mentioned it.
Most common case: the user wrote "create CRUD controller for Product" →
entity is , skip the question, go straight to the fetch below.
ProductLazy fallback — only when entity is unknown: call
→ , then ask via
(options = entity names from the list, max 4; if more
than 4 entities, use the 4 most likely candidates based on context and
add a note that the user can type a different name via "Other").
list_all_domain_entities(moduleName)entitiesAskUserQuestionThis is the only place should be called. If
the user named the entity in their prompt, do NOT call it.
list_all_domain_entitiesAfter the entity FQN is known, call to get:
get_entity_details(entityFqn)- -- entity ID field type (e.g.
IdType,java.lang.Long)java.util.UUID - -- decapitalized entity name (e.g.
entityVar)product - -- pluralized decapitalized name (e.g.
entityVarPlural)products - -- simple class name (e.g.
EntityName)Product - -- pluralized simple name (e.g.
EntityNamePlural)Products - Whether entity has validation annotations -->
entityHasValidation
通过步骤0,如果用户提到了实体,你应该已经知道它。最常见的情况:用户写了"为Product创建CRUD控制器" → 实体是,跳过问题,直接进行下方的获取操作。
Product惰性回退 — 仅当实体未知时: 调用 → ,然后通过询问(选项 = 列表中的实体名称,最多4个;如果实体超过4个,根据上下文选择4个最可能的候选者,并添加注释说明用户可以通过"其他"输入不同名称)。
list_all_domain_entities(moduleName)entitiesAskUserQuestion这是唯一应该调用的地方。如果用户在提示中指定了实体,不要调用它。
list_all_domain_entities确定实体FQN后,调用获取:
get_entity_details(entityFqn)- -- 实体ID字段类型(例如
IdType、java.lang.Long)java.util.UUID - -- 小写开头的实体名称(例如
entityVar)product - -- 小写开头的复数名称(例如
entityVarPlural)products - -- 简单类名(例如
EntityName)Product - -- 复数化的简单名称(例如
EntityNamePlural)Products - 实体是否有验证注解 →
entityHasValidation
Step 3 -- Select repository
步骤3 -- 选择仓库
By Step 0 you may already know the repository if the user mentioned it.
Call → . Then apply the
Decision-making principle:
list_entity_repositories(entityFqn)repos- If exactly one repository exists → select it silently (principle 1).
- If the user named a specific repository → use it directly, skip the question.
- If multiple repositories exist → ask via with the options from
AskUserQuestion.repos - If no repository exists → inform the user and suggest creating one manually or using a separate skill.
After selection:
- -- decapitalized repository class name (e.g.
repoFieldName)productRepository - -- FQN of repository class
RepoFqn
通过步骤0,如果用户提到了仓库,你可能已经知道它。
调用 → 。然后应用决策原则:
list_entity_repositories(entityFqn)repos- 如果只有一个仓库存在 → 静默选择它(原则1)。
- 如果用户指定了特定仓库 → 直接使用它,跳过问题。
- 如果有多个仓库存在 → 通过询问,选项来自
AskUserQuestion。repos - 如果没有仓库存在 → 告知用户,并建议手动创建或使用单独的技能。
选择后:
- -- 小写开头的仓库类名(例如
repoFieldName)productRepository - -- 仓库类的FQN
RepoFqn
Step 4 -- DTO and customization questions
步骤4 -- DTO和自定义问题
By Step 0 you may already know the DTO mode if the user mentioned it
(e.g. "with DTO", "without DTO", "use entity directly", "map to ProductDto").
If so, skip the question and proceed.
If unknown, ask via :
AskUserQuestion| Question | Header | Options (first = recommended) |
|---|---|---|
| Use DTO for mapping? | DTO mode | Yes, use DTO (Recommended): select existing or create new via |
通过步骤0,如果用户提到了DTO模式(例如"使用DTO"、"不使用DTO"、"直接使用实体"、"映射到ProductDto"),你可能已经知道它。如果是这样,跳过问题继续。
如果未知,通过询问:
AskUserQuestion| 问题 | 标题 | 选项(首位为推荐) |
|---|---|---|
| 是否使用DTO进行映射? | DTO模式 | 是,使用DTO(推荐):选择现有DTO或通过 |
If DTO selected:
如果选择DTO:
Call and .
list_entity_dtos(entityFqn)list_entity_mappers(entityFqn)If existing DTO + mapper found: ask user to select them. Extract:
- -- DTO class FQN
DtoFqn - -- decapitalized DTO name
dtoVar - -- decapitalized mapper class name
mapperFieldName - -- mapper method entity-->DTO (e.g.
toDtoMethodName)toDto - -- mapper method DTO-->entity (e.g.
toEntityMethodName)toEntity - -- mapper method for update (e.g.
updateMethodName)updateWithNullValues
Warn: CREATE and PATCH operations require the mapper to have and methods.
toEntityupdateWithNullIf no DTO exists for the entity: delegate to to create
one. The skill will handle DTO generation and will
automatically delegate to for the mapper (since the
DTO is for a REST controller — conversion is inevitable). After both
are created, return here and continue with Step 4 path settings.
dto-creatordto-creatormapper-creatorIf DTO exists but no mapper: delegate to to create
one. After the mapper is created, return here and continue.
mapper-creator调用和。
list_entity_dtos(entityFqn)list_entity_mappers(entityFqn)如果找到现有DTO + 映射器: 请用户选择它们。提取:
- -- DTO类的FQN
DtoFqn - -- 小写开头的DTO名称
dtoVar - -- 小写开头的映射器类名
mapperFieldName - -- 映射器的实体转DTO方法(例如
toDtoMethodName)toDto - -- 映射器的DTO转实体方法(例如
toEntityMethodName)toEntity - -- 映射器的更新方法(例如
updateMethodName)updateWithNullValues
警告:CREATE和PATCH操作要求映射器具有和方法。
toEntityupdateWithNull如果实体没有现有DTO: 委托给技能创建一个。技能将处理DTO生成,并自动委托给技能创建映射器(因为DTO用于REST控制器——转换是不可避免的)。两者创建完成后,返回此处继续步骤4的路径设置。
dto-creatordto-creatormapper-creator如果DTO存在但没有映射器: 委托给技能创建一个。映射器创建完成后,返回此处继续。
mapper-creatorPath, pagination & filter settings
路径、分页与过滤设置
Apply the Decision-making principle. These settings almost always have
good defaults derivable from context — use principle 2 (one-line
confirmation) unless the user explicitly asked for customization:
Will create `{EntityName}Controller` in `{controllerPackage}` at `{basePath}/{entityVarPlural}`, Page pagination, no filter. OK?The user can answer "ok" / "yes" / silence → accept all defaults; or
override specific values → apply only those overrides.
Only fall back to individual questions when the user explicitly asked for
fine-grained control ("custom paths", "configure pagination") or when
context yields no clear defaults.
If the user selects a filter: ask to select existing filter class. Extract
and . If the repository does not
extend , add it (WA-repo-enhance).
FilterFqntoSpecificationMethodNameJpaSpecificationExecutor应用决策原则。这些设置几乎总是可以从上下文推导到合适的默认值——除非用户明确要求自定义,否则使用原则2(单行确认):
将在`{controllerPackage}`中创建`{EntityName}Controller`,路径为`{basePath}/{entityVarPlural}`,使用Page分页,无过滤器。是否确认?用户可以回答"ok" / "yes" / 保持沉默 → 接受所有默认值;或覆盖特定值 → 仅应用这些覆盖。
只有当用户明确要求细粒度控制("自定义路径"、"配置分页")或上下文没有明确默认值时,才回退到单独的问题。
如果用户选择过滤器:请选择现有过滤器类。提取和。如果仓库未扩展,添加该接口(WA-repo-enhance)。
FilterFqntoSpecificationMethodNameJpaSpecificationExecutorMethod selection
方法选择
By Step 0 you may already know which methods the user wants (e.g. "read-only",
"only GET and CREATE", "full CRUD"). If so, skip the question.
If unknown, ask via :
AskUserQuestion| Question | Header | Options (first = recommended) |
|---|---|---|
| Which CRUD methods to generate? | Methods | Full CRUD (Recommended): GET_LIST, GET_ONE, GET_MANY, CREATE, PATCH, PATCH_MANY, DELETE, DELETE_MANY / Standard CRUD: GET_LIST, GET_ONE, CREATE, PATCH, DELETE / Read-only: GET_LIST, GET_ONE / Custom: select individual methods |
Store the selected method set as . Step 5.3 generates only
these methods, skipping the rest.
selectedMethods通过步骤0,如果用户提到了想要的方法(例如"只读"、"仅GET和CREATE"、"完整CRUD"),你可能已经知道。如果是这样,跳过问题。
如果未知,通过询问:
AskUserQuestion| 问题 | 标题 | 选项(首位为推荐) |
|---|---|---|
| 要生成哪些CRUD方法? | 方法 | 完整CRUD(推荐):GET_LIST、GET_ONE、GET_MANY、CREATE、PATCH、PATCH_MANY、DELETE、DELETE_MANY / 标准CRUD:GET_LIST、GET_ONE、CREATE、PATCH、DELETE / 只读:GET_LIST、GET_ONE / 自定义:选择单个方法 |
将所选方法集存储为。步骤5.3仅生成这些方法,跳过其余方法。
selectedMethodsStep 5 -- Generate code
步骤5 -- 生成代码
5.1 Create controller class (WA1)
5.1 创建控制器类(WA1)
Read or based on .
examples/_skeletons/java.mdexamples/_skeletons/kotlin.mdlanguageApply variable substitutions:
- --> controllerPackage
{packageName} - --> controllerName
{className} - --> basePath + resourcePath
{requestPath}
Use Write tool to create .
src/main/{java,kotlin}/{package-path}/{controllerName}.{java,kt}根据读取或。
languageexamples/_skeletons/java.mdexamples/_skeletons/kotlin.md应用变量替换:
- → controllerPackage
{packageName} - → controllerName
{className} - → basePath + resourcePath
{requestPath}
使用Write工具创建。
src/main/{java,kotlin}/{package-path}/{controllerName}.{java,kt}5.2 Add bean injection (WA2)
5.2 添加Bean注入(WA2)
Read or .
examples/_beans/injection/java.mdkotlin.mdAdd constructor parameter for repository. If DTO with mapper: also inject mapper bean.
Inject field (resolved in Step 1: for Jackson 3.x, for Jackson 2.x).
${ObjectMapperFqn}tools.jackson.databind.ObjectMappercom.fasterxml.jackson.databind.ObjectMapperUse Edit tool to modify the controller class.
读取或。
examples/_beans/injection/java.mdkotlin.md添加仓库的构造函数参数。如果使用带映射器的DTO:同时注入映射器Bean。注入字段(在步骤1中解析:Jackson 3.x使用,Jackson 2.x使用)。
${ObjectMapperFqn}tools.jackson.databind.ObjectMappercom.fasterxml.jackson.databind.ObjectMapper使用Edit工具修改控制器类。
5.3 Add CRUD methods (WA3-WA11)
5.3 添加CRUD方法(WA3-WA11)
For each method in (from Step 4 method selection):
selectedMethods-
Determine the example file path:
examples/_methods/{method-name}/{language}.md -
Read the example file
-
Select the correct code variant based on:
- DTO mode (no DTO vs with DTO)
- For GET_LIST: pagination (PAGE / WINDOW / none) and filter (with/without)
- For PATCH/PATCH_MANY: ObjectMapper vs ObjectPatcher, and DTO vs no-DTO (4 combinations)
- For CREATE: with/without @Valid
-
Apply variable substitutions (ONLY variables declared in the Variables section)
-
FQN handling (CRITICAL): examples contain FQNs (e.g.,
org.springframework.web.bind.annotation.GetMapping, entity/DTO/repository FQNs). When writing the final file, you MUST:org.springframework.data.domain.Pageable- Replace every FQN in the body with its short name
- Collect every FQN you shortened and emit a corresponding line right after the
importstatement, sorted, no duplicatespackage - Classes from the same package as the controller must NOT be imported
- Types from must NOT be imported
java.lang - Kotlin: same rules — shorten in the body and add lines at the top
import
-
Use Edit tool to insert the method into the controller class body
对于中的每个方法(来自步骤4的方法选择):
selectedMethods-
确定示例文件路径:
examples/_methods/{method-name}/{language}.md -
读取示例文件
-
根据以下条件选择正确的代码变体:
- DTO模式(无DTO vs 使用DTO)
- 对于GET_LIST:分页(PAGE / WINDOW / 无)和过滤器(有/无)
- 对于PATCH/PATCH_MANY:ObjectMapper vs ObjectPatcher,以及DTO vs 无DTO(4种组合)
- 对于CREATE:带/不带@Valid
-
应用变量替换(仅替换变量部分声明的变量)
-
FQN处理(重要): 示例中包含FQN(例如、
org.springframework.web.bind.annotation.GetMapping、实体/DTO/仓库FQN)。在编写最终文件时,你必须:org.springframework.data.domain.Pageable- 将正文中的每个FQN替换为其短名称
- 收集所有缩短的FQN,并在语句后添加相应的
package行,排序,无重复import - 与控制器同包的类不要导入
- 中的类型不要导入
java.lang - Kotlin:规则相同——在正文中缩短并在顶部添加行
import
-
使用Edit工具将方法插入控制器类体中
5.4 Add JpaSpecificationExecutor if needed (WA-repo-enhance)
5.4 按需添加JpaSpecificationExecutor(WA-repo-enhance)
If filter is selected and repository does not already extend :
JpaSpecificationExecutorRead or .
Use Edit tool to add to the repository's extends list.
examples/_beans/repo-enhance/java.mdkotlin.mdorg.springframework.data.jpa.repository.JpaSpecificationExecutor<{EntityFqn}>如果选择了过滤器且仓库尚未扩展:
JpaSpecificationExecutor读取或。使用Edit工具将添加到仓库的extends列表中。
examples/_beans/repo-enhance/java.mdkotlin.mdorg.springframework.data.jpa.repository.JpaSpecificationExecutor<{EntityFqn}>Step 6 -- Dependencies & properties (automatic)
步骤6 -- 依赖与属性(自动)
- Read
examples/_dependencies/dependencies.md - For each artifact NOT in :
presentDeps- Use from Step 1
buildFile - Edit the build file to add the dependency
- Use
- Call
refresh_build_system_model - No properties are written for this skill (controller has no application.properties entries)
- Report: "Created controller {controllerName} with CRUD endpoints for {EntityName}. Added dependencies: [list]."
- 读取
examples/_dependencies/dependencies.md - 对于每个不在中的工件:
presentDeps- 使用步骤1中的
buildFile - 编辑构建文件以添加依赖
- 使用步骤1中的
- 调用
refresh_build_system_model - 此技能无需写入属性(控制器没有application.properties条目)
- 报告:"已为{EntityName}创建带有CRUD接口的控制器{controllerName}。已添加依赖:[列表]。"
Anti-hallucination checklist
防幻觉检查清单
Before writing ANY code, verify:
- The code comes from an examples/ file (cite which one)
- Only declared variables were substituted
- No framework API calls were added "from knowledge"
- Import list covers all FQNs shortened in the body (no missing imports, no extras)
- Method signatures match the example exactly
- No comments or convenience methods were added
- FQNs from examples are shortened in the body AND corresponding lines were added after
import(IDE will NOT do this for you)package - annotation is only added when
@ParameterObjecthasSpringDoc = true - annotation is only added when
@ValidAND entity has validation annotationshasValidation = true - PATCH and PATCH_MANY methods use ObjectMapper (fallback) or ObjectPatcher depending on project dependencies
- getId() in PATCH_MANY matches entity's actual ID accessor
- Jackson FQNs use for Jackson 3.x (Spring Boot 4.x) and
tools.jackson.databind.*for Jackson 2.x (Spring Boot 2.x/3.x). NEVER hardcode one or the other — always resolvecom.fasterxml.jackson.databind.*and${JsonNodeFqn}from Step 1.${ObjectMapperFqn} - GET_LIST with Page pagination uses wrapper (Spring Data 3.2+ / Boot 3.2+/4.x) or returns
PagedModel<Entity>directly (older versions). Select the correct example variant.Page<Entity>
在编写任何代码之前,验证:
- 代码来自examples/文件(注明来自哪个文件)
- 仅替换了声明的变量
- 没有添加"凭知识"的框架API调用
- 导入列表涵盖了正文中所有缩短的FQN(无缺失导入,无多余导入)
- 方法签名与示例完全匹配
- 没有添加注释或便利方法
- 示例中的FQN在正文中被缩短,并且在语句后添加了相应的
package行(IDE不会自动完成此操作)import - 注解仅在
@ParameterObject时添加hasSpringDoc = true - 注解仅在
@Valid且实体有验证注解时添加hasValidation = true - PATCH和PATCH_MANY方法根据项目依赖使用ObjectMapper(回退)或ObjectPatcher
- PATCH_MANY中的getId()与实体实际的ID访问器匹配
- Jackson FQN对Jackson 3.x(Spring Boot 4.x)使用,对Jackson 2.x(Spring Boot 2.x/3.x)使用
tools.jackson.databind.*。永远不要硬编码其中一种——始终从步骤1解析com.fasterxml.jackson.databind.*和${JsonNodeFqn}。${ObjectMapperFqn} - 使用Page分页的GET_LIST使用包装器(Spring Data 3.2+ / Boot 3.2+/4.x)或直接返回
PagedModel<Entity>(旧版本)。选择正确的示例变体。Page<Entity>