286Categories
Product / document categories arranged as a tree: each category may have a parent.
Try it
Category tree
Built in memory from parent_id by CategoryService.tree()-
π»
Electronics
ELEC3 sub -
β
π₯οΈ
Computers
ELEC-COMP3 sub -
β
π»
Laptops
ELEC-COMP-LAP -
β
π₯οΈ
Desktops
ELEC-COMP-DESK -
β
π΅
Monitors
ELEC-COMP-MON -
β
π±
Phones & Tablets
ELEC-PHONE -
β
π§
Accessories
ELEC-ACC -
ποΈ
Home & Living
HOME2 sub -
β
πͺ
Furniture
HOME-FURN -
β
π³
Kitchen
HOME-KIT -
π
Office Supplies
OFFICE2 sub -
β
π
Paper
OFFICE-PAPER -
β
βοΈ
Writing Tools
OFFICE-WRITE -
π οΈ
Services
SERV2 sub -
β
π§
Installation
SERV-INST -
β
π§°
Maintenance
SERV-MAINT
Tip: edit a category and pick a new Parent to move it - try putting a category under its own child to see the loop check.
| # | Code | Name | Parent | Icon | Sort order | Status | |
|---|---|---|---|---|---|---|---|
| 1 | ELEC | Electronics | β | π» | 1 | Active | βοΈ |
| 5 | ELEC-COMP | Computers | ELEC - Electronics | π₯οΈ | 1 | Active | βοΈ |
| 14 | ELEC-COMP-LAP | Laptops | ELEC-COMP - Computers | π» | 1 | Active | βοΈ |
| 8 | HOME-FURN | Furniture | HOME - Home & Living | πͺ | 1 | Active | βοΈ |
| 10 | OFFICE-PAPER | Paper | OFFICE - Office Supplies | π | 1 | Active | βοΈ |
| 12 | SERV-INST | Installation | SERV - Services | π§ | 1 | Active | βοΈ |
| 15 | ELEC-COMP-DESK | Desktops | ELEC-COMP - Computers | π₯οΈ | 2 | Active | βοΈ |
| 6 | ELEC-PHONE | Phones & Tablets | ELEC - Electronics | π± | 2 | Active | βοΈ |
| 2 | HOME | Home & Living | β | ποΈ | 2 | Active | βοΈ |
| 9 | HOME-KIT | Kitchen | HOME - Home & Living | π³ | 2 | Active | βοΈ |
| 11 | OFFICE-WRITE | Writing Tools | OFFICE - Office Supplies | βοΈ | 2 | Active | βοΈ |
| 13 | SERV-MAINT | Maintenance | SERV - Services | π§° | 2 | Active | βοΈ |
| 7 | ELEC-ACC | Accessories | ELEC - Electronics | π§ | 3 | Active | βοΈ |
| 16 | ELEC-COMP-MON | Monitors | ELEC-COMP - Computers | π΅ | 3 | Active | βοΈ |
| 3 | OFFICE | Office Supplies | β | π | 3 | Active | βοΈ |
Showing 1β15 of 16
π Learn: how this master is built table category
Key points
- Self-referencing table: category.parent_id β category.id (adjacency list).
- CategoryService.tree() loads all rows once and builds the tree in memory - no recursive SQL needed.
- CategoryService.validate() walks up the parents to stop loops (A under B under A).
Code
- Entity
domain/Category.java- Repository
repo/CategoryRepository.java- Definition
MasterRegistry: "categories"- Page / form
web/MasterController.java- Try-it panel
templates/tools/category-tree.html- REST API
GET /api/masters/categories?q=comp
SQL to try in SSMS (database MasterDataLabDB)
-- the whole tree with a recursive CTE WITH tree AS ( SELECT id, code, name, parent_id, 0 AS depth, CAST(name AS NVARCHAR(400)) AS path FROM category WHERE parent_id IS NULL UNION ALL SELECT c.id, c.code, c.name, c.parent_id, t.depth + 1, CAST(t.path + N' > ' + c.name AS NVARCHAR(400)) FROM category c JOIN tree t ON c.parent_id = t.id ) SELECT * FROM tree ORDER BY path;