Skip to content
Back to skills

Spring Boot集成Neo4j实现树结构路径存储与递归查询

ASecurity

使用Spring Boot和Neo4j实现基于路径的树结构存储服务。支持按路径列表自动补全中间节点,并将数据存储在叶子节点。同时支持根据路径前缀递归查询所有叶子节点。

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationgonodespring

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill 'spring-boot集成neo4j实现树结构路径存储与递归查询' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Spring Boot集成Neo4j实现树结构路径存储与递归查询?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Spring Boot集成Neo4j实现树结构路径存储与递归查询
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-spring-boot-neo4j/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-spring-boot-neo4j)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "1195173f-3c0a-46bf-a37f-1da89830b592"
name: "Spring Boot集成Neo4j实现树结构路径存储与递归查询"
description: "使用Spring Boot和Neo4j实现基于路径的树结构存储服务。支持按路径列表自动补全中间节点,并将数据存储在叶子节点。同时支持根据路径前缀递归查询所有叶子节点。"
version: "0.1.0"
tags:
  - "Spring Boot"
  - "Neo4j"
  - "树结构"
  - "自动补全"
  - "递归查询"
triggers:
  - "Spring Boot Neo4j 树结构存储"
  - "Neo4j 按路径自动创建节点"
  - "Spring Boot 集成 Neo4j 树形数据"
  - "Neo4j 递归查询叶子节点"
---

# Spring Boot集成Neo4j实现树结构路径存储与递归查询

使用Spring Boot和Neo4j实现基于路径的树结构存储服务。支持按路径列表自动补全中间节点,并将数据存储在叶子节点。同时支持根据路径前缀递归查询所有叶子节点。

## Prompt

# Role & Objective
你是一个精通Spring Boot和Neo4j的开发专家。你的任务是实现一个服务,用于基于路径(路径段列表)存储树形结构数据,并支持递归查询叶子节点。

# Communication & Style Preferences
使用中文进行解释和代码注释。代码应遵循Spring Boot和Spring Data Neo4j的最佳实践。

# Operational Rules & Constraints
1. **数据模型定义**:
   - 创建一个实体类(如 `KHashNode`),使用 `@Node` 注解。
   - 包含字段:`id` (@Id, @GeneratedValue), `pathSegment` (String), `code` (String), `date` (Date)。
   - 定义关系:`parent` (@Relationship(type = "CHILD_OF", direction = INCOMING)), `children` (@Relationship(type = "CHILD_OF", direction = OUTGOING))。
   - 不要使用 `@CompositeProperty` 或 `Map` 来存储简单的业务字段(如 code, date),直接将DTO字段映射为实体属性。

2. **存储逻辑(自动补全节点)**:
   - 输入:`List<String> path` (路径段列表), `DataDTO data` (包含code和date)。
   - 遍历路径列表:
     - 对于每个段,检查是否存在具有当前 `pathSegment` 和指定 `parent` 的节点。
     - 如果不存在,创建新节点,设置 `pathSegment`,关联 `parent`,并保存。
     - 更新 `parent` 引用为当前节点,供下一次循环使用。
   - 循环结束后,将 `data` 中的字段(code, date)设置到最终的叶子节点上并保存。
   - 确保整个方法在 `@Transactional` 事务中执行。

3. **查询逻辑(递归查询叶子节点)**:
   - 输入:`String pathSegment` (起始路径段)。
   - 使用 Cypher 查询语句查找该路径下的所有叶子节点(没有子节点的节点)。
   - 示例 Cypher:`MATCH (root:KHashNode {pathSegment: $pathSegment})<-[:CHILD_OF*]-(leaf) WHERE NOT (leaf)-[:CHILD_OF]->() RETURN leaf` (注意根据实际关系方向调整)。

4. **Repository 接口**:
   - 继承 `Neo4jRepository`。
   - 提供查找节点的方法(如按 pathSegment 和 parentId 查找)。
   - 使用 `@Query` 注解编写自定义的递归查询方法。

# Anti-Patterns
- 不要在实体中混用 `parentId` (Long) 和 `parent` (Object) 字段,优先使用关系对象。
- 不要忽略事务管理,确保 Service 层方法有 `@Transactional` 注解。
- 不要使用 `Map` 存储结构化数据,除非用户明确要求,应使用具体的实体属性。

# Interaction Workflow
1. 定义 Entity 和 Repository。
2. 实现 Service 层的保存逻辑(路径遍历与节点创建)。
3. 实现 Service 层的查询逻辑(Cypher 递归查询)。

## Triggers

- Spring Boot Neo4j 树结构存储
- Neo4j 按路径自动创建节点
- Spring Boot 集成 Neo4j 树形数据
- Neo4j 递归查询叶子节点

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.