disclosure of Invention
The invention aims to overcome the defects of the prior art and provides a high-efficiency data verification system and method under a front-end and back-end separation framework for ensuring the consistency of front-end and back-end data verification rules
in order to achieve the above object, the present invention provides a data checking system under a front-end and back-end separated architecture, which includes a front end and a back end,
The back end includes:
The verification rule analysis engine is used for analyzing and caching the data verification rules in the uniform JSON format into a memory at the back end;
A check rule routing engine, configured to search a corresponding data check rule according to the service operation applied by the service request, and perform routing binding on the searched data check rule and the specific service operation, so that the data check rule after routing binding is used as a data check basis for the form request;
the back-end rule checking engine is used for performing data checking on each data field in the submitted form request according to the route-bound data checking rule at the back end;
-a rule transmission unit, configured to transmit the route-bound data check rule from the back-end to the front-end;
the front end comprises:
-a front-end rule checking engine for performing data checking at the front-end on data fields in the form request according to the data checking rules transmitted from the back-end;
before submitting a form request to the back end for data verification, the front end sends a service request to the back end to request to search a corresponding data verification rule and transmits the data verification rule to the front end from the back end, so that the service request is used as a basis for data verification by the front end rule verification engine before submitting the form request.
further, the attributes in any of the data verification rules include one or more attributes of field type, string length, whether null, maximum and minimum values, regular expression rules, identity card rules, phone number rules, e-mail rules, whether two passwords are consistent rules, multiple field combination association rules, and password strength rules.
a data verification method under a front-end and back-end separation architecture comprises a front-end verification process and a back-end verification process, wherein a verification rule analysis engine analyzes and caches a unified JSON format data verification rule in a back-end memory in advance so that the front-end verification process and the back-end verification process can acquire the corresponding data verification rule;
The front-end verification process specifically comprises the following steps:
A1. before submitting any form request, the front end firstly sends a corresponding service request to the back end;
A2. After receiving the service request, the back end searches a corresponding data check rule according to the service operation applied by the service request, wherein if the corresponding data check rule is searched, the back end performs routing binding on the data check rule and the specific service operation and transmits the data check rule and the specific service operation to the front end through the rule transmission unit; otherwise, if the corresponding data verification rule cannot be found, sending an instruction for not executing form request submission to the front end;
A3. the front end enters a data verification stage after receiving the data verification rule, wherein in the data verification stage, the front end rule verification engine traverses each data field in the form request to be submitted based on the received data verification rule, performs front end data verification, and finally returns a verification result, wherein if all the verification results conform to the data verification rule, the verification is judged to be successful; if any one of the verification results does not accord with the data verification rule, determining that the verification fails;
A4. the front end submits the form request which is judged to be successful by the front end data verification to the back end;
The back-end verification process specifically comprises the following steps:
B1. after receiving the form request from the front end, the back end enters a data verification stage;
B2. in the data verification stage, the back-end rule verification engine performs back-end data verification on each data field in the form request according to the bound data verification rule and returns a verification result, wherein if all the verification results conform to the data verification rule, the verification is judged to be successful; if any one of the verification results does not accord with the data verification rule, determining that the verification fails;
B3. and the back end continues to execute corresponding business operation backwards according to the form request which is judged to be successful by the back end data verification.
furthermore, the data check rule transmitted from the rule transmission unit to the front end does not need to be converted into a format.
The invention adopts the scheme, and has the beneficial effects that: the data verification of the form request at the front end and the back end is respectively carried out through the front end verification process and the back end verification process, and the front end and the back end share one set of data verification rules, so that the accuracy of the data verification is improved, and the complexity and the workload of development and maintenance of complex verification services are reduced.
Detailed Description
to facilitate an understanding of the invention, the invention is described more fully below with reference to the accompanying drawings. Preferred embodiments of the present invention are shown in the drawings. This invention may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. These embodiments are provided so that this disclosure will be thorough and complete.
Referring to fig. 1, in this embodiment, a data verification system under a front-end and back-end separation architecture includes a front end and a back end, where the front end is used as a client for a user, and the back end is used as a server of the system.
In this embodiment, the backend includes a check rule parsing engine, a check rule routing engine, a backend rule checking engine, and a rule transmission unit.
The verification rule parsing engine of this embodiment is configured to parse and cache the data verification rule in the unified JSON format into the memory at the back end, that is, a developer sets the data verification rule in advance, and stores the data verification rule in the unified JSON format into the back end, and then, in the process of starting and initializing the back end, reads the data verification rule by using the verification rule interpretation engine, parses a specific rule therein, converts the rule into a calculation object inside the back end system, and caches the calculation object into the memory, so that the front end or the back end can quickly obtain the data verification subsequently performed.
The check rule routing engine of this embodiment is configured to search a corresponding data check rule according to a service operation applied by a service request, and route and bind the searched data check rule and a specific service logic, and for convenience of understanding, the description is specifically made in combination with a specific implementation case: the data verification rule is obtained through conversion according to a URL address of a rear end endpoint needing data processing, if a form request is submitted to a service operation endpoint of/api/roles at the rear end, the data verification rule is named as api # roles.
the back-end rule check engine of this embodiment is configured to perform, at the back end, back-end data check on each data field in the submitted form request according to the route-bound data check rule, that is, the data check rules used by the back-end rule check engine are all previously bound by the check rule routing engine, and specifically, the back-end rule check engine performs back-end data check on each data field by traversing each data field of the form request according to the corresponding data check rule to return a check result, and then determines whether to continue to execute the corresponding business operation backward according to the check result.
the rule transmission unit in this embodiment is configured to transmit the route-bound data verification rule from the back end to the front end, and specifically, before the front end submits a form request, the front end first sends a corresponding service request to the back end, and according to the service request, the rule transmission unit needs to obtain the corresponding bound data verification rule and transmit the bound data verification rule from the back end to the front end, so that the rule transmission unit serves as a basis for the front end to perform data verification before submitting the form request. In addition, if the data verification rule corresponding to the expression request does not exist, the rule transmission unit does not acquire any data verification rule and sends an instruction for not executing form request submission to the front end.
In this embodiment, the front end includes a front-end rule checking engine, where the front-end rule checking engine of this embodiment is configured to perform data checking on each data field in a form request according to a data checking rule transmitted from the back end at the front end, that is, before submitting a form request, the front end first sends a corresponding service request to the back end, and then transmits a corresponding data checking rule to the front end by using a rule transmission unit, and the front-end rule checking engine performs front-end data checking on each data field in the form request to be submitted according to the data checking rule, specifically, the front-end rule checking engine performs front-end data checking on each data field by traversing each data field of the form request and according to the corresponding data checking rule to return a checking result, and then judging whether to continue to execute the corresponding business operation or not according to the checking result. In addition, if the front end returns the instruction of not executing the form request submission after sending a corresponding service request to the back end, the front end does not execute the front end data verification and submission operation of the form request.
in this embodiment, the attribute in any data verification rule includes one or more attributes of a field type, a string length, whether the data verification rule is empty, a maximum value and a minimum value, a regular expression rule, an identity card rule, a telephone number rule, an e-mail rule, whether two passwords are consistent, a plurality of field combination association rules, and a password strength rule, and a developer can correspondingly select the attribute in a proper data verification rule according to an actual data verification requirement, and can even expand other different verification data verification rules according to requirements, such as a special rule for querying a database to verify data validity; the present invention is not limited to the attributes listed in the above data checking rules, and those skilled in the art can make the derived selections according to the actual requirements.
for ease of understanding, the data verification system described above is further explained below in conjunction with a specific data verification method.
In this embodiment, a data verification method under a front-end and back-end separation architecture includes a front-end verification process and a back-end verification process, where a verification rule parsing engine parses and caches a uniform JSON-format data verification rule in advance in a back-end memory, so that the front-end verification process and the back-end verification process obtain corresponding data verification rules.
referring to fig. 2, the front-end verification process of this embodiment specifically includes the following steps:
A1. before submitting any form request, the front end firstly sends a corresponding service request to the back end;
A2. After receiving the service request, the back end searches a corresponding data check rule according to the service operation applied by the service request, wherein if the corresponding data check rule is searched, the back end performs routing binding on the data check rule and the specific service operation and transmits the data check rule and the specific service operation to the front end through the rule transmission unit; otherwise, if the corresponding data verification rule cannot be found, sending an instruction for not executing form request submission to the front end;
A3. the front end enters a data verification stage after receiving the data verification rule, wherein in the data verification stage, the front end rule verification engine traverses each data field in the form request to be submitted based on the received data verification rule, performs front end data verification, and finally returns a verification result, wherein if all the verification results conform to the data verification rule, the verification is judged to be successful; if any one of the verification results does not accord with the data verification rule, determining that the verification fails;
A4. the front end submits the form request which is judged to be successfully verified through the front end data verification to the back end.
In step a2, after the front end receives the instruction not to execute the form request submission, the data verification and submission operation of the form request is not executed.
In step a3, for the form request determined as failed in verification, the error prompt information in the data verification rule is transmitted to the front-end related display component for display, so that the user can view the verification result.
Referring to fig. 3, the back-end verification process of this embodiment specifically includes the following steps:
B1. After receiving the form request from the front end, the back end enters a data verification stage;
B2. in the data verification stage, the back-end rule verification engine performs back-end data verification on each data field in the form request according to the bound data verification rule and finally returns a verification result, wherein if all the verification results conform to the data verification rule, the verification is judged to be successful; if any one verification result does not accord with the data verification rule, the verification is judged to be successful;
B3. and the back end continues to execute corresponding business operation backwards according to the form request which is judged to be successfully verified through the back end data verification.
In step B2, for the form request determined as failed in verification, an error prompt message in the data verification rule is returned to the response result.
in both the front-end verification process and the back-end verification process, the data verification rules used are in an SON format, and the data verification rules transmitted to the front end by the rule transmission unit do not need to be converted into a JSON format.
the above-described embodiments are merely preferred embodiments of the present invention, which is not intended to limit the present invention in any way. Those skilled in the art can make many changes, modifications, and equivalents to the embodiments of the invention without departing from the scope of the invention as set forth in the claims below. Therefore, equivalent changes made according to the spirit of the present invention should be covered within the protection scope of the present invention without departing from the contents of the technical scheme of the present invention.