This is a simple implementation of the closure table pattern for Spring Data JPA. The closure table pattern is a way to store hierarchical data in a relational database. It is a simple and efficient way to store and query hierarchical data.
- Java 17
- Kotlin 1.9.25
- Spring Boot 3.3.5
- Spring Web
- Spring Data JPA
- PostgreSQL 16.4
docker run \
-e POSTGRES_DB=test \
-e POSTGRES_PASSWORD=dev \
-e POSTGRES_USER=dev \
-p 5432:5432 \
postgres:16.4 -d
curl -X POST "http://localhost:8080/departments?name=dep1"
curl -X POST "http://localhost:8080/departments?name=dep2&parentId=1"
curl -X GET "http://localhost:8080/departments/tree"
curl -X GET "http://localhost:8080/departments/1/tree"
curl -X POST "http://localhost:8080/departments/2/move?newParentId=3"
curl -X DELETE "http://localhost:8080/departments/2?strategy=CASCADE"