Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

spring-boot-crud-patterns春季靴子粗鲁模式

Agent Skill

用于辅助 Java 项目开发、面向对象设计、Spring 生态、Maven 或 Gradle 依赖和后端工程实践。它适合让 Agent 分析类结构、设计接口、整理服务分层、生成测试或检查常见代码坏味道。使用时需要结合项目已有架构、包结构和依赖版本,不应只按通用教程改代码;涉及数据库、事务、并发或框架配置时,应先确认运行环境和回归测试范围。

总安装

17,919

周安装

732

GitHub Stars

229

下载量

5,739
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:spring-boot-crud-patterns(春季靴子粗鲁模式)
来源仓库:https://github.com/giuseppe-trisciuoglio/developer-kit
仓库路径:skills/spring-boot-crud-patterns
安装命令:
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill spring-boot-crud-patterns
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill spring-boot-crud-patterns

简介

适用于 Spring Boot 3 的功能一致的 CRUD 服务,具有分层架构和 Spring Data JPA。

  • 建立具有领域、应用程序、表示和基础设施层的功能包,以维护架构边界和 DDD 原则。
  • 涵盖完整的 CRUD 工作流程:具有不变量的实体建模、存储库接口、JPA 适配器、事务服务、DTO 记录和具有适当 HTTP 状态代码的 REST 控制器。
  • 包括使用 jakarta.validation 的验证模式、分页支持以及通过 ResponseStatusException 或 ControllerAdvice 进行错误处理。
  • 提供 Python 生成器以根据实体规范构建样板,以及产品功能和与 Testcontainers 的集成测试的参考示例。

SKILL.md

Spring Boot CRUD Patterns

Overview

Provides complete CRUD workflows for Spring Boot 3.5+ services using feature-focused architecture. Creates and validates domain aggregates, JPA repositories, application services, and REST controllers with proper separation of concerns. Defer detailed code listings to reference files for progressive disclosure.

When to Use

  • Create REST endpoints for create/read/update/delete workflows backed by Spring Data JPA.
  • Implement feature packages following DDD-inspired architecture with aggregates, repositories, and application services.
  • Define DTO records, request validation, and controller mappings for external clients.
  • Diagnose CRUD regressions, repository contracts, or transaction boundaries in existing Spring Boot services.
  • Trigger phrases: "implement Spring CRUD controller", "create an endpoint", "add database entity", "refine feature-based repository", "map DTOs for JPA aggregate", "add pagination to REST list endpoint".

Instructions

Follow this streamlined workflow to deliver feature-aligned CRUD services with explicit validation gates:

1. Establish Feature Structure

Create feature/<name>/ directories with domain, application, presentation, and infrastructure subpackages. Validate: Verify directory structure matches the feature boundary before proceeding.

2. Define Domain Model

Create entity classes with invariants enforced through factory methods (create, update). Keep domain logic framework-free. Validate: Assert all invariants are covered by unit tests before advancing.

3. Expose Domain Ports

Declare repository interfaces in domain/repository describing persistence contracts without implementation details. Validate: Confirm interface signatures match domain operations.

4. Provide Infrastructure Adapter

Create JPA entities in infrastructure/persistence that map to domain models. Implement Spring Data repositories. Validate: Run @DataJpaTest to verify entity mapping and repository integration.

5. Implement Application Services

Create @Transactional service classes that orchestrate domain operations and DTO mapping. Validate: Ensure transaction boundaries are correct and optimistic locking is applied where needed.

6. Define DTOs and Controllers

Use Java records for API contracts with jakarta.validation annotations. Map REST endpoints with proper status codes. Validate: Test validation constraints and verify HTTP status codes (201 POST, 200 GET, 204 DELETE).

7. Validate and Deploy

Run integration tests with Testcontainers. Verify migrations (Liquibase/Flyway) mirror the aggregate schema. Validate: Execute full test suite before deployment; confirm schema migration scripts are applied.

See references/examples-product-feature.md for complete code aligned with each step.

Examples

Java Code Example: Product Feature

// feature/product/domain/Product.java
package com.example.product.domain;

import java.math.BigDecimal;
import java.time.Instant;

public record Product(
    String id,
    String name,
    String description,
    BigDecimal price,
    int stock,
    Instant createdAt,
    Instant updatedAt
) {
    public static Product create(String name, String desc, BigDecimal price, int stock) {
        if (name == null || name.isBlank()) throw new IllegalArgumentException("Name required");
        if (price == null || price.compareTo(BigDecimal.ZERO) < 0) throw new IllegalArgumentException("Invalid price");
        return new Product(null, name.trim(), desc, price, stock, Instant.now(), null);
    }

    public Product withPrice(BigDecimal newPrice) {
        return new Product(id, name, description, newPrice, stock, createdAt, Instant.now());
    }
}
// feature/product/domain/repository/ProductRepository.java
package com.example.product.domain.repository;

import com.example.product.domain.Product;
import java.util.Optional;

public interface ProductRepository {
    Product save(Product product);
    Optional<Product> findById(String id);
    void deleteById(String id);
}
// feature/product/infrastructure/persistence/ProductJpaEntity.java
package com.example.product.infrastructure.persistence;

import jakarta.persistence.*;
import java.math.BigDecimal;
import java.time.Instant;

@Entity @Table(name = "products")
public class ProductJpaEntity {
    @Id @GeneratedValue(strategy = GenerationType.UUID)
    private String id;
    private String name;
    private String description;
    private BigDecimal price;
    private int stock;
    private Instant createdAt;
    private Instant updatedAt;

    // getters, setters, constructor from domain (omitted for brevity)
}
// feature/product/infrastructure/persistence/JpaProductRepository.java
package com.example.product.infrastructure.persistence;

import com.example.product.domain.Product;
import com.example.product.domain.repository.ProductRepository;
import org.springframework.stereotype.Repository;

@Repository
public class JpaProductRepository implements ProductRepository {
    private final SpringDataProductRepository springData;

    public JpaProductRepository(SpringDataProductRepository springData) {
        this.springData = springData;
    }

    @Override
    public Product save(Product product) {
        ProductJpaEntity entity = toEntity(product);
        ProductJpaEntity saved = springData.save(entity);
        return toDomain(saved);
    }

    // findById, deleteById implementations...
}
// feature/product/presentation/rest/ProductController.java
package com.example.product.presentation.rest;

import com.example.product.domain.Product;
import com.example.product.domain.repository.ProductRepository;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController @RequestMapping("/api/products")
public class ProductController {
    private final ProductService service;

    public ProductController(ProductService service) { this.service = service; }

    @PostMapping
    public ResponseEntity<ProductResponse> create(@Valid @RequestBody CreateProductRequest req) {
        Product product = service.create(req.toDomain());
        return ResponseEntity.status(201).body(ProductResponse.from(product));
    }

    @GetMapping("/{id}")
    public ResponseEntity<ProductResponse> getById(@PathVariable String id) {
        return service.findById(id)
            .map(p -> ResponseEntity.ok(ProductResponse.from(p)))
            .orElse(ResponseEntity.notFound().build());
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> delete(@PathVariable String id) {
        service.deleteById(id);
        return ResponseEntity.noContent().build();
    }

    // record DTOs
    public record CreateProductRequest(
        @NotBlank String name,
        String description,
        @NotNull @DecimalMin("0.01") java.math.BigDecimal price,
        @Min(0) int stock
    ) {
        Product toDomain() { return Product.create(name, description, price, stock); }
    }

    public record ProductResponse(String id, String name, java.math.BigDecimal price) {
        static ProductResponse from(Product p) { return new ProductResponse(p.id(), p.name(), p.price()); }
    }
}

JSON Input/Output Examples

Create Request:

{
  "name": "Wireless Keyboard",
  "description": "Ergonomic keyboard",
  "price": 79.99,
  "stock": 50
}

Created Response (201):

{
  "id": "prod-123",
  "name": "Wireless Keyboard",
  "price": 79.99,
  "_links": { "self": "/api/products/prod-123" }
}

Paginated List Request:

curl "http://localhost:8080/api/products?page=0&size=10&sort=name,asc"

Best Practices

  • Co-locate domain, application, and presentation code per aggregate within feature packages.
  • Use Java records for immutable DTOs; convert domain types at the service boundary.
  • Apply transactions and optimistic locking for write operations.
  • Normalize pagination defaults (page, size, sort) and document query parameters.
  • Log CRUD lifecycle events (create, update, delete) at info level with structured audit trails.
  • Surface health and metrics through Spring Boot Actuator; monitor throughput and error rates.

Constraints and Warnings

  • Never expose JPA entities directly in controllers to prevent lazy-loading leaks and serialization issues.
  • Never mix field injection with constructor injection; maintain immutability for testability.
  • Never embed business logic in controllers or repository adapters; keep it in domain/application layers.
  • Always validate input aggressively to prevent constraint violations and produce consistent error payloads.
  • Always ensure migrations (Liquibase/Flyway) mirror aggregate evolution before deploying schema changes.
  • Always run integration tests with Testcontainers before merging to prevent persistence regressions.

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

38.28%
按下载量换算2,197

Claude

31.59%
按下载量换算1,813

Cursor

17.61%
按下载量换算1,011

Gemini CLI

8.34%
按下载量换算479

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills