spring-boot-crud-patterns by giuseppe-trisciuoglio/developer-kit
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill spring-boot-crud-patterns提供功能对齐的 CRUD 服务,分离领域、应用、展示和基础设施层,同时遵循 Spring Boot 3.5+ 的约定。此技能提炼了核心工作流程,并将详细的代码清单推迟到参考文件中,以实现渐进式披露。
遵循以下步骤实现功能对齐的 CRUD 服务:
创建 feature/<name>/ 目录,并包含 domain、application、presentation 和 infrastructure 子包,以维护架构边界。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
创建实体类,并通过工厂方法(create、update)强制执行不变条件。保持领域逻辑无框架依赖,不使用 Spring 注解。
在 domain/repository 中定义领域仓储接口,描述持久化契约而不涉及实现细节。
在 infrastructure/persistence 中创建映射到领域模型的 JPA 实体。实现委托给领域接口的 Spring Data 仓储。
创建带有 @Transactional 方法的 @Service 类,用于编排领域操作、仓储访问和 DTO 映射。
使用 Java 记录或不可变类作为 API 契约。应用 jakarta.validation 注解进行输入验证。
创建映射到 /api 端点的 @RestController 类。返回带有适当状态码的 ResponseEntity(POST 返回 201,DELETE 返回 204)。
单独对领域逻辑进行单元测试。使用 @DataJpaTest 和 Testcontainers 对持久化层进行集成测试。
spring-boot-starter-web 和 spring-boot-starter-data-jpa。@RequiredArgsConstructor 或显式构造函数)。jakarta.validation)和错误处理(ResponseStatusException)。domain、application、presentation 和 infrastructure 创建 feature/<name>/ 目录。create 和 update 的方法中捕获不变条件。domain/repository 中声明描述持久化契约的仓储接口。infrastructure/persistence 中实现 Spring Data 适配器,将领域模型映射到 JPA 实体并委托给 JpaRepository。application/service 下创建事务性用例,用于编排聚合、仓储和映射逻辑。presentation/rest 下映射 DTO 记录,使用适当的状态码暴露端点,并连接验证注解。请查阅 references/examples-product-feature.md 以获取与每个步骤对应的完整代码清单。
Product.create)定义不可变聚合,以集中不变条件。Money、Stock)来强制类型安全并封装验证。@Entity 注解。@Transactional 将用例包装在 @Service 类中。JpaRepository<ProductEntity, String>)和用于分页或批量更新的自定义查询来配置仓储。application.yml 外部化持久化属性(命名策略、DDL 模式);参见 references/spring-official-docs.md。ProductController)构建控制器,并暴露 REST 路径(/api/products)。ResponseEntity:POST 返回 201 Created,GET/PUT/PATCH 返回 200 OK,DELETE 返回 204 No Content。@Valid,并使用 @ControllerAdvice 或 ResponseStatusException 处理错误。references/examples-product-feature.md 中的集成测试片段。@DataJpaTest 和 Testcontainers 来验证持久化映射、分页和批量操作。info 级别记录关键操作,并使用结构化日志记录进行审计追踪。{
"name": "Wireless Keyboard",
"description": "Ergonomic wireless keyboard with backlight",
"price": 79.99,
"stock": 50
}
{
"id": "prod-123",
"name": "Wireless Keyboard",
"description": "Ergonomic wireless keyboard with backlight",
"price": 79.99,
"stock": 50,
"createdAt": "2024-01-15T10:30:00Z",
"_links": {
"self": "/api/products/prod-123",
"update": "/api/products/prod-123",
"delete": "/api/products/prod-123"
}
}
{
"price": 69.99,
"stock": 45
}
{
"id": "prod-123",
"name": "Wireless Keyboard",
"description": "Ergonomic wireless keyboard with backlight",
"price": 69.99,
"stock": 45,
"updatedAt": "2024-01-15T11:45:00Z",
"_links": {
"self": "/api/products/prod-123"
}
}
curl -X DELETE http://localhost:8080/api/products/prod-123
HTTP/1.1 204 No Content
curl "http://localhost:8080/api/products?page=0&size=10&sort=name,asc"
{
"content": [
{
"id": "prod-123",
"name": "Wireless Keyboard",
"price": 69.99,
"stock": 45
},
{
"id": "prod-456",
"name": "Wireless Mouse",
"price": 29.99,
"stock": 100
}
],
"pageable": {
"page": 0,
"size": 10,
"total": 2,
"totalPages": 1
},
"_links": {
"self": "/api/products?page=0&size=10",
"next": null,
"last": "/api/products?page=0&size=10"
}
}
python skills/spring-boot-crud-patterns/scripts/generate_crud_boilerplate.py --spec entity.json --package com.example.product --output ./generatedskills/spring-boot-crud-patterns/references/ 中,或传递 --templates-dir <path>;不提供内置回退。参见 references/README.md。skills/spring-boot-crud-patterns/assets/specs/product.jsonskills/spring-boot-crud-patterns/assets/specs/product_with_rel.json每周安装次数
376
代码仓库
GitHub 星标数
173
首次出现时间
2026年2月3日
安全审计
安装于
opencode288
claude-code287
gemini-cli284
codex281
cursor273
github-copilot264
Deliver feature-aligned CRUD services that separate domain, application, presentation, and infrastructure layers while preserving Spring Boot 3.5+ conventions. This skill distills the essential workflow and defers detailed code listings to reference files for progressive disclosure.
Follow these steps to implement feature-aligned CRUD services:
Create feature// directories with domain, application, presentation, and infrastructure subpackages to maintain architectural boundaries.
Create entity classes with invariants enforced through factory methods (create, update). Keep domain logic framework-free without Spring annotations.
Define domain repository interfaces in domain/repository that describe persistence contracts without implementation details.
Create JPA entities in infrastructure/persistence that map to domain models. Implement Spring Data repositories that delegate to domain interfaces.
Create @Service classes with @Transactional methods that orchestrate domain operations, repository access, and DTO mapping.
Use Java records or immutable classes for API contracts. Apply jakarta.validation annotations for input validation.
Create @RestController classes mapped to /api endpoints. Return ResponseEntity with appropriate status codes (201 for POST, 204 for DELETE).
Unit test domain logic in isolation. Use @DataJpaTest and Testcontainers for integration testing of persistence layer.
spring-boot-starter-web and spring-boot-starter-data-jpa.@RequiredArgsConstructor or explicit constructors).jakarta.validation) and error handling (ResponseStatusException).feature/<name>/ directories for domain, application, presentation, and infrastructure.create and update.domain/repository describing persistence contracts.infrastructure/persistence that map domain models to JPA entities and delegate to .Consult references/examples-product-feature.md for complete code listings that align with each step.
Product.create) to centralize invariants.Money, Stock) to enforce type safety and encapsulate validation.@Entity annotations in the domain package when using adapters.@Service classes using constructor injection and @Transactional.JpaRepository<ProductEntity, String>) and custom queries for pagination or batch updates.application.yml; see references/spring-official-docs.md.ProductController) and expose REST paths (/api/products).ResponseEntity with appropriate codes: 201 Created on POST, 200 OK on GET/PUT/PATCH, 204 No Content on DELETE.@Valid on request DTOs and handle errors with @ControllerAdvice or ResponseStatusException.references/examples-product-feature.md integration test snippets.@DataJpaTest and Testcontainers to validate persistence mapping, pagination, and batch operations.info for lifecycle events (create, update, delete) and use structured logging for audit trails.{
"name": "Wireless Keyboard",
"description": "Ergonomic wireless keyboard with backlight",
"price": 79.99,
"stock": 50
}
{
"id": "prod-123",
"name": "Wireless Keyboard",
"description": "Ergonomic wireless keyboard with backlight",
"price": 79.99,
"stock": 50,
"createdAt": "2024-01-15T10:30:00Z",
"_links": {
"self": "/api/products/prod-123",
"update": "/api/products/prod-123",
"delete": "/api/products/prod-123"
}
}
{
"price": 69.99,
"stock": 45
}
{
"id": "prod-123",
"name": "Wireless Keyboard",
"description": "Ergonomic wireless keyboard with backlight",
"price": 69.99,
"stock": 45,
"updatedAt": "2024-01-15T11:45:00Z",
"_links": {
"self": "/api/products/prod-123"
}
}
curl -X DELETE http://localhost:8080/api/products/prod-123
HTTP/1.1 204 No Content
curl "http://localhost:8080/api/products?page=0&size=10&sort=name,asc"
{
"content": [
{
"id": "prod-123",
"name": "Wireless Keyboard",
"price": 69.99,
"stock": 45
},
{
"id": "prod-456",
"name": "Wireless Mouse",
"price": 29.99,
"stock": 100
}
],
"pageable": {
"page": 0,
"size": 10,
"total": 2,
"totalPages": 1
},
"_links": {
"self": "/api/products?page=0&size=10",
"next": null,
"last": "/api/products?page=0&size=10"
}
}
python skills/spring-boot-crud-patterns/scripts/generate_crud_boilerplate.py --spec entity.json --package com.example.product --output ./generatedskills/spring-boot-crud-patterns/references/ or pass --templates-dir <path>; no fallback to built-ins. See references/README.md.Weekly Installs
376
Repository
GitHub Stars
173
First Seen
Feb 3, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode288
claude-code287
gemini-cli284
codex281
cursor273
github-copilot264
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
106,200 周安装
JpaRepositoryapplication/service that orchestrate aggregates, repositories, and mapping logic.presentation/rest, expose endpoints with proper status codes, and wire validation annotations.skills/spring-boot-crud-patterns/assets/specs/product.jsonskills/spring-boot-crud-patterns/assets/specs/product_with_rel.json