Understanding the Backend Configuration of Jianghu JS Framework
120021. Introduction to This Lesson
In this lesson, you will learn about the backend operations and configuration types in web applications. The Jianghu JS framework simplifies control logic through database configuration, which includes handling requests and interacting with the database. You will learn about the advantages of this configuration and the tables involved in implementing it.
2. Overview of How the Backend of Web Applications Works
The backend of a web application is responsible for processing requests from the frontend and generating corresponding responses. Below is a brief introduction to how the backend of a web application works:
Backend Operations
The backend operations are divided into the following steps based on the workflow:
(1) Receiving and Processing Requests: When a user initiates a request in the browser, the request is sent to the backend. Upon receiving the request, the backend determines how to process it based on the information contained in the request.
(2) Information and Data Processing: The backend executes the corresponding processing based on the received request. This may involve querying data from the database, processing data, performing calculations, etc.
(3) Interacting with the Database: During request processing, the backend typically needs to interact with the database. This includes operations such as creating, reading, updating, and deleting data.
(4) Generating Responses: After completing the information and data processing, the backend generates a response. The response is returned in the format required by the frontend.
(5) Sending Responses to the Frontend: Finally, the backend sends the generated response back to the frontend. Upon receiving the response, the frontend can update the page and display data based on the content of the response.
Types of Backend Configuration
Backend configuration generally refers to the various settings and parameters configured for backend applications during backend development. There are two types of backend configuration:
(1) File Configuration: Based on the needs of the frontend pages, the backend creates different files and writes the processes and methods for handling requests within them. Most frameworks use this approach, which can be cumbersome and prone to omissions.
(2) Database Configuration: The request information, data tables, and operation statements are all defined in a single record in the database. Through this record, developers can easily configure information without modifying code, thereby simplifying the configuration of backend control logic.
3. Design Features of Jianghu JS Framework: Simplifying Control Logic with Database Configuration
The Jianghu JS framework simplifies control logic through database configuration. The projects generated using the jianghu-init tool contain a series of system tables, some of which are used to configure backend control logic, such as the _page, _resource, and _user_group_role tables.
By configuring these tables, backend operations can be managed without directly modifying code. Developers only need to adjust the information in these tables to control page navigation, manage interactions between pages and the database, set user permissions, etc. This approach is simple and effective, making program development more flexible and efficient.
4. Advantages of Simplifying Control Logic through Configuration
From the above examples, we see that the system tables in the database configure backend control logic. This approach has the following characteristics:
(1) Flexibility: By configuring data in the database, the behavior of the application can be easily changed without modifying code. This flexibility makes the application more adaptable to changes and requirements.
(2) Maintainability: Separating configuration information from code makes the code clearer and more concise. Developers can focus more on implementing business functions without mixing page function code with configuration information. Additionally, centralized management of configuration information makes maintenance and management easier. When modifications are needed, only the database data needs to be changed, eliminating the need to delve into the code to find and modify related information, thus reducing maintenance costs.
(3) Scalability: Using configuration files allows for the easy addition of new configuration options, enhancing the scalability of the application. For example, if new features need to be introduced or existing features need to be adjusted, this can be done by modifying the database data without large-scale modifications to the existing code.
5. Configuration of Jianghu JS Framework in the Database
When opening the jianghu-basic project, you must log in to access the doUiAction page. The doUiAction page has a menu bar at the top, and clicking on a menu item will take you to the corresponding page. Any actions performed on the page will return corresponding information from the backend. All these operations are achieved by configuring backend control logic using the database.
The Jianghu JS framework uses different tables in the database to configure different functionalities:
(1) Page Configuration: The _page table controls the content of the page menu bar and page navigation.
(2) Data Interface Configuration: The _resource table controls the functionality for creating, reading, updating, and deleting data.
(3) User and User Permission Configuration: Controls users and user permissions.
- Basic Tables:
_usertable,_grouptable,_roletable, - Relationship Tables:
_user_group_roletable,_user_group_role_pagetable,_user_group_role_resourcetable.
Subsequent lessons will provide detailed introductions on how to configure these tables to help you gain a deeper understanding of the Jianghu JS framework.