The permission system should be designed like this, a stable batch!

For the background management system, the permission function is already an essential part. If you have used some rapid development scaffolding, you will find that many of them directly integrate the permission function. Making the permission function a general function is very conducive to code reuse. Today, I will take my actual mall e-commerce project as an example to talk about the design and implementation of the authority system!

mall project introduction

Here is a brief introduction to the mall project. The mall project is an e-commerce system based on SpringBoot + Vue + uni-app. It is currently available on Github, 60K的Starincluding the front-end mall project and the background management system, which can support a complete order process! Covering functions such as products, orders, shopping carts, permissions, coupons, members, etc., the functions are very powerful!

feature design

Before starting to develop the permission module, we have to design the function first, and we can produce a rendering. Since the mall project permission function has been developed, here you can directly refer to its rendering.

As can be seen from the system effect diagram, the permission functions of the mall project are divided into four functions: user management, role management, resource management, and menu management. The following introduces these functions respectively.

User Management

User management mainly includes the management of user information and the function of assigning roles to users.

role management

Role management mainly includes the management of role information, the functions of assigning menus to roles, and assigning resources to roles.

menu management

Menu management mainly includes the management of menu information.

resource management

Resource management mainly includes the management of resource information and resource classification.

Functional arrangement

After the function design is completed, we need to organize the functions. The main thing is to consider how to store the corresponding data and which tables and fields to design. You can use the mind map function to organize. The following is the functional mind map I have organized .

Database Design

Next, we can design the database table according to the organized mind map. This is the database table structure of the permission module of the mall project that I designed.

interface design

After making these preparations, we can start to write code to realize the function of the permission module. We can design the interface according to the rendering of the system to meet the needs of the system. For example, the user management function interface of the mall project is designed as follows.

technical points

In fact, during the development process, we will also involve the use of some permission frameworks, such as Spring Security is used in my mall project.

  • In order to realize the authentication and authorization functions, Spring Security and JWT are integrated in the project.
  • In order to make the permission function more flexible and versatile, we will also implement dynamic permission control of the interface through Spring Security.
  • In order to improve the performance of the system, we will also use Redis+AOP to optimize the rights management function.

Summarize

The development of a function module generally needs to go through the process of function design, function organization, database design, interface design, etc. At the same time, it also needs to solve the technical problems in the development process. As long as you master its general design ideas, it is not difficult to develop function modules !

Project source address

github.com/macrozheng/…

Guess you like

Origin juejin.im/post/7256769427600490553