Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kaciras/closuretable
基于 ClosureTable 的数据库无限级分类示例。
https://github.com/kaciras/closuretable
Last synced: 5 days ago
JSON representation
基于 ClosureTable 的数据库无限级分类示例。
- Host: GitHub
- URL: https://github.com/kaciras/closuretable
- Owner: Kaciras
- License: mit
- Created: 2018-04-19T14:53:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-24T03:04:19.000Z (about 2 years ago)
- Last Synced: 2023-03-05T11:33:53.476Z (almost 2 years ago)
- Language: Java
- Homepage: https://blog.kaciras.com/article/6
- Size: 5.55 MB
- Stars: 71
- Watchers: 4
- Forks: 44
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ClosureTable
[![Test](https://github.com/Kaciras/ClosureTable/actions/workflows/test.yml/badge.svg)](https://github.com/Kaciras/ClosureTable/actions/workflows/test.yml)
[![GitHub license](https://img.shields.io/github/license/Kaciras/ClosureTable)](https://github.com/Kaciras/ClosureTable/blob/master/LICENSE)基于闭包表的数据库无限级分类示例。
闭包表用一张额外的表存储节点之间的关系、其中包含了任何两个有关系(祖先与子代)节点的关联信息,共有 3 个字段:
* `ancestor` 祖先节点的 ID
* `descendant` 子代节点的 ID
* `distance` 子代到祖先中间隔了几代以这三个字段作为条件,能够很方便的应对各种操作。闭包表是牺牲空间和修改效率来换取查询效率的典型设计。
配套文章 [https://blog.kaciras.com/article/6/store-tree-in-database](https://blog.kaciras.com/article/6/store-tree-in-database)
# 运行
![screenshot](https://github.com/Kaciras/ClosureTable/blob/master/screenshot.png)
本项目带有一个演示网页,运行要求 JAVA >= 18。
构建并启动:
```bash
mvn package
java -jar target/closure-table-3.0.0.jar
```访问 [http://localhost:7777](http://localhost:7777) 查看演示页面。
数据库支持 Sqlite、Mariadb 和 PostgreSQL,默认使用 Sqlite 的内存数据库,可以在`application.properties`里修改数据库设置。
* 测试数据和建表脚本位于 `src/main/resources` 下。
* SQL 见 `CategoryMapper.java`。
* 完整的 API 见 `Repository.java` 和 `Category.java`。