springboot-jpa-best-practices

springboot-jpa-best-practices is a cursor rule for Cursor from holtwood/awesome-cursorrules-zh. It costs 0 tokens per session (525 once invoked), scanned A, original, MIT.

A set of Chinese-language rules for structuring Java Spring Boot applications that use JPA, a library for database access.

In plain words
What is it for?
It guides REST endpoints, database repositories, service logic, DTOs, entity relationships, validation, transactions, exception handling, project structure, and related coding style.
Why use it?
It promotes consistent separation between web controllers, services, repositories, data entities, and transfer objects while addressing transactions, errors, security, and performance.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit It guides REST endpoints, database repositories, service logic, DTOs, entity relationships, validation, transactions, exception handling, project structure, and related coding style.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/holtwood/awesome-cursorrules-zh/springboot-jpa-best-practices
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/holtwood/awesome-cursorrules-zh

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for springboot-jpa-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/springboot-jpa-best-practices/github.svg)](https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/springboot-jpa-best-practices)
Your own site
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/springboot-jpa-best-practices"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/springboot-jpa-best-practices/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for springboot-jpa-best-practices

Your own site · 80×15
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/springboot-jpa-best-practices"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/springboot-jpa-best-practices.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 525 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00525
Opus 5 $0.00000 $0.00262
Sonnet 5 $0.00000 $0.00105
Haiku 4.5 $0.00000 $0.00052

Measured 10d ago against content hash 8097f9c3e2f8, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

springboot-jpa-best-practices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 10d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/rules/backend/java/springboot-jpa-best-practices.mdc · 28 lines

What it actually says

  • 所有请求与响应必须仅在 RestController 层处理
  • 所有数据库操作逻辑仅在 ServiceImpl 层实现,ServiceImpl 只能调用 Repository 提供的方法
  • RestController 不应直接注入 Repository,除非有特殊理由
  • ServiceImpl 不得直接操作数据库,只能通过 Repository 间接访问
  • RestController 与 ServiceImpl 之间仅用 DTO 传递数据,Entity 只作为数据库数据载体
  • Entity 类需加 @Entity 注解,主键加 @Id 和 @GeneratedValue(strategy=GenerationType.IDENTITY)
  • Entity 关系建议默认使用 FetchType.LAZY,属性应加 @Size、@NotEmpty、@Email 等校验注解
  • Repository 必须为接口,继承 JpaRepository<Entity, ID>,加 @Repository 注解
  • 多表关联查询使用 DTO 作为数据容器,@Query 建议用 JPQL,避免 N+1 问题时用 @EntityGraph
  • Service 层为接口,具体实现类加 @Service 注解,依赖用 @Autowired 注入
  • ServiceImpl 方法返回 DTO,不直接返回 Entity
  • 多步数据库操作需加 @Transactional 或使用 transactionTemplate
  • DTO 推荐使用 Java 17 record,构造器中校验参数合法性
  • Controller 类加 @RestController 注解,类级路由用 @RequestMapping
  • 方法级用 @PostMapping/@GetMapping 等,依赖用 @Autowired
  • Controller 方法返回 ResponseEntity,所有逻辑用 try...catch 包裹
  • 异常统一由 GlobalExceptionHandler 处理
  • 全局响应类 ApiResponse 包含 result、message、data 字段
  • 遵循 SOLID、DRY、KISS、YAGNI 原则,遵守 OWASP 安全最佳实践
  • 代码风格统一,推荐使用 Lombok 简化代码
  • 技术栈建议:Spring Boot 3、Spring Web、Spring Data JPA、Thymeleaf、Lombok、PostgreSQL
  • 项目结构清晰分层,逻辑拆解细致,便于维护与扩展
  • 参考官方文档与 OWASP 指南,定期审计安全与性能
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 10d ago First seen · 28 lines · 0 tokens per session scan A 8097f9c3e2f8

Subscribe to this mod's changes

springboot-jpa-best-practices is a cursor rule published in the GitHub repository holtwood/awesome-cursorrules-zh (233 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 525 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.