The main menu is the kind of background management system in which you can control whether to display a certain menu or a certain function in a certain menu through configuration.
Regarding its design and implementation, my personal summary is as follows.
(1)
Save with database table
Generally, the main menu is a tree structure, and there are two solutions based on traditional relational databases.
(1-1)
Using a table solution, the table contains an id and parentid to associate the parent-child relationship.
(1-2)
With the two-table solution, one table is used to record the parent-child relationship of the menu, and the other table purely records the menu information.
There are also two data transfer schemes:
(1-1-1)
The backend queries the data and constructs it through the background code loop, or uses sql transactions to build the tree structure and then passes it to the frontend
(1-1-2)
The backend queries the data and passes it to the frontend, allowing the frontend to build its own tree structure
(2)
Save with json
This is the way I mainly want to know about this problem. I don’t know if you have used it before. Then directly build the parent and child node information of the main menu into json format. Save it to a configuration table or a json file. This saves you the trouble of constructing a tree structure. However, since it is a pure json format, manual maintenance is okay if the data structure is not complex. If you encounter a complex situation, you may need to write a maintenance interface to maintain it. At this time, since json does not have a query syntax similar to sql, the front end (Assuming it is js) It will be particularly complicated to write additions, deletions and check modifications (especially deletions).
this. . . . I don’t know what method you usually use? If possible, I hope you can briefly talk about it.
At the same time, if you have any opinions on (2) using json to save
, you can also talk about it.
Comprehensively consider performance, scalability, maintainability, etc.
The solution should be chosen based on technology. As for the two solutions you gave, the first one is more suitable for relational database implementation, and the second one is more suitable for NoSQL database implementation.
In summary, the first solution is recommended. Flattening the menu structure will be more convenient when designing users, user groups, permissions and other modules later. Using JSON solutions to perform these operations will be more complicated.