Business request processing method and device, storage medium and electronic device

By receiving the client's service request, the parameter verification result processor, global exception processor and unified message packaging processor are used to automatically generate response messages, solving the problems of low efficiency in response messages generation and serious code coupling in the prior art. , realizes efficient packet generation and service processing decoupling with view rendering.

CN113127108BActive Publication Date: 2024-12-31JD DIGITS HAIYI INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110435327.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-22
Publication Date
2024-12-31
Estimated Expiration
2041-04-22

AI Technical Summary

Technical Problem

In the prior art, the generation efficiency of response packets is low, because each interface that needs to return the agreed packet format needs to be manually encapsulated, especially when there is an error code, it needs to be filled, resulting in an increase in repetitive labor and thus reduced. Development efficiency, serious code coupling, chaotic responsibilities, and difficult to decouple business processing and view rendering.

Method used

By receiving the client's service request, the preset parameter verification result processor and the global exception processor preset the service processing result, combined with the unified message packaging processor, the response message is automatically generated. And send it to the client, avoiding the duplicate work of manual encapsulation and error code filling, and realizing automatic generation and decoupling of packets.

Benefits of technology

It improves the efficiency of generating response messages, reduces repetitive labor, avoids code coupling, realizes the decoupling of business processing and view rendering, and improves code readability and development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113127108B_ABST
    Figure CN113127108B_ABST
Patent Text Reader

Abstract

The disclosed embodiment is about a method and device for processing a business request, a storage medium and an electronic device, and relates to the field of software development technology. The method includes: receiving a business request sent by a client, executing a business process corresponding to the business request in response to the business request to obtain a current business process result; performing a first preset process on the parameter check result included in the current business process result based on a preset parameter check result processor, and performing a second preset process on the abnormal error code included in the current business process result based on a preset global exception processor; performing a unified message encapsulation on the current business process result after the first preset process and the second preset process based on a preset unified message encapsulation processor to obtain a response message corresponding to the business request; sending the response message to the client so that the client displays the response message. The disclosed embodiment improves the efficiency of generating response messages.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] At present, Spring (open source application framework) and Spring Boot (open source lightweight framework) are the de facto standards in the field of Java (object-oriented programming language) back-end development. Many server-side applications are developed based on the Spring framework. In actual development, it is often necessary to interact with the front-end page or mobile application through the HTTP (Hypertext Transfer Protocol) interface. During the interaction process, the front-end and back-end usually define a unified data message format, and all return messages from the back-end must conform to this format, otherwise the front-end cannot parse it.

[0003] In order to solve the above problem, the prior art agrees on a unified data message format between the front-end and the back-end, and then manually encapsulates the operation result based on the unified data message format to obtain a response message.

[0004] However, the above scheme has the following defects: for each interface that needs to return the agreed message format, it needs to be manually encapsulated, and if there is an error code, it needs to be filled, which results in a lot of repetitive work, and thus makes the generation efficiency of the response message low.

[0005] Therefore, it is necessary to provide a new method and device for processing a service request.

[0006] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0007] The purpose of the present disclosure is to provide a method for processing a business request, a device for processing a business request, a computer-readable storage medium, and an electronic device, thereby at least to a certain extent overcoming the problem of low efficiency in generating response messages due to limitations and defects of related technologies.

[0008] According to one aspect of the present disclosure, a method for processing a service request is provided, comprising:

[0009] Receive a service request sent by a client, and in response to the service request, execute a service process corresponding to the service request to obtain a current service process result;

[0010] Based on a preset parameter check result processor, a first preset processing is performed on the parameter check result included in the current business processing result, and based on a preset global exception processor, a second preset processing is performed on the abnormal error code included in the current business processing result;

[0011] Based on a preset unified message encapsulation processor, a current service processing result after the first preset processing and the second preset processing is uniformly encapsulated to obtain a response message corresponding to the service request;

[0012] The response message is sent to the client, so that the client displays the response message.

[0013] In an exemplary embodiment of the present disclosure, before receiving the service request sent by the client, the service request processing method further includes:

[0014] Import global configuration annotations based on preset annotation import parameters;

[0015] The global configuration annotation is used to enable the parameter verification result processor, the global exception processor, and the unified message encapsulation processor.

[0016] In an exemplary embodiment of the present disclosure, receiving a service request sent by a client, and executing a service process corresponding to the service request in response to the service request to obtain a current service process result, including:

[0017] Utilize the control layer included in the Spring / Spring Boot framework to receive the service request sent by the client, and call the service logic layer included in the Spring / Spring Boot framework in response to the service request;

[0018] The business logic layer generates a query request according to the business attribute information included in the business request, and calls the data persistence layer included in the Spring / Spring Boot framework;

[0019] The data persistence layer obtains the current business processing result from the database entity layer included in the Spring / Spring Boot framework, and feeds back the current business processing result to the business logic layer, and then feeds back to the control layer via the business logic layer.

[0020] In an exemplary embodiment of the present disclosure, a first preset processing is performed on the parameter verification result included in the current business processing result based on a preset parameter verification result processor, including:

[0021] Based on a preset parameter verification result processor, determining whether there is a parameter abnormality in the parameter verification result included in the current business processing result;

[0022] When it is determined that there is a parameter abnormality, according to the abnormality category of the parameter abnormality and a preset first mapping relationship, a first default error code corresponding to the abnormality category is obtained;

[0023] The first default error code is sealed in the current service processing result of the device to complete the first preset processing.

[0024] In an exemplary embodiment of the present disclosure, a second preset process is performed on the abnormal error code included in the current business processing result based on a preset global exception handler, including:

[0025] Acquire an exception handling annotation based on a preset global exception handler, and use the exception handling annotation to extract the exception error code included in the current business processing result;

[0026] When it is determined that the abnormal error code is empty, obtaining a second default error code when the abnormal error code is empty according to a preset second mapping relationship, and filling the second default error code into the current business processing result to complete the second preset processing;

[0027] When it is determined that the exception error code is not empty, obtain the target error code in the exception handling annotation and the error prompt corresponding to the target error code, and fill the target error code and the error prompt into the current business processing result to complete the second preset processing.

[0028] In an exemplary embodiment of the present disclosure, a preset unified message encapsulation processor performs unified message encapsulation on the current service processing result after the first preset processing and the second preset processing to obtain a response message corresponding to the service request, including:

[0029] Based on the preset unified message encapsulation processor, determining whether the return type of the method included in the current business processing result after the first preset processing and the second preset processing is empty;

[0030] If the return type is empty, a default successful unified message object is created according to the current business processing result after the first preset processing and the second preset processing;

[0031] A response message corresponding to the service request is generated according to the successful unified message object.

[0032] In an exemplary embodiment of the present disclosure, the method for processing a service request further includes:

[0033] If the return type is not empty, determine whether the return value of the method is empty;

[0034] If the return value is empty, a default successful unified message object is created according to the current service processing result after the first preset processing and the second preset processing, and a response message corresponding to the service request is generated according to the successful unified message object;

[0035] If the return value is not empty and the return value is not a preset unified message definition class, the return value is encapsulated as an object of the unified message definition class, and a response message corresponding to the service request is generated according to the object of the unified message definition class.

[0036] According to one aspect of the present disclosure, a device for processing a service request is provided, including:

[0037] A business processing execution module, used to receive a business request sent by a client, and in response to the business request, execute a business process corresponding to the business request to obtain a current business processing result;

[0038] A business processing result processing module, used to perform a first preset processing on the parameter verification result included in the current business processing result based on a preset parameter verification result processor, and to perform a second preset processing on the abnormal error code included in the current business processing result based on a preset global exception processor;

[0039] A business processing result encapsulation module, used to perform unified message encapsulation on the current business processing result after the first preset processing and the second preset processing based on a preset unified message encapsulation processor, to obtain a response message corresponding to the business request;

[0040] A response message sending module is used to send the response message to the client so that the client displays the response message.

[0041] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method for processing a service request described in any one of the above is implemented.

[0042] According to one aspect of the present disclosure, there is provided an electronic device, including:

[0043] Processor; and

[0044] A memory, configured to store executable instructions of the processor;

[0045] The processor is configured to execute any one of the above-mentioned methods for processing a service request by executing the executable instructions.

[0046] A method for processing a business request provided by an embodiment of the present disclosure comprises the following steps: on the one hand, by receiving a business request sent by a client, executing business processing corresponding to the business request in response to the business request to obtain a current business processing result; then, based on a preset parameter verification result processor, performing a first preset processing on a parameter verification result included in the current business processing result, and based on a preset global exception processor, performing a second preset processing on an abnormal error code included in the current business processing result; then, based on a preset unified message encapsulation processor, performing unified message encapsulation on the current business processing result after the first preset processing and the second preset processing to obtain a response message corresponding to the business request; finally, sending the response message to the client so that the client can display the response message. The processor processes the parameter verification result and the abnormal error code included in the current business processing result, and based on the unified message encapsulation processor, performs unified message encapsulation on the processed current business processing result to obtain a response message, thereby realizing the automatic generation of the response message, and solving the problem in the prior art that each interface that needs to return the agreed message format needs to be manually encapsulated, and if there is an error code, it needs to be filled, resulting in a large amount of repetitive labor, thereby making the generation efficiency of the response message low, thereby improving the generation efficiency of the response message; on the other hand, since the message encapsulation is implemented in the unified message encapsulation processor, the problem of serious code coupling caused by the need to implement message encapsulation in the interface between the client and the server in the prior art is avoided, thereby realizing the decoupling of business processing and view rendering.

[0047] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.

[0049] Figure 1 The following is a flowchart schematically showing a method for processing a service request according to an exemplary embodiment of the present disclosure.

[0050] Figure 2 A structural framework diagram of Spring / Spring Boot according to an exemplary embodiment of the present disclosure is schematically shown.

[0051] Figure 3The flowchart schematically shows another method for processing a service request according to an exemplary embodiment of the present disclosure.

[0052] Figure 4 A flowchart of a method for performing a first preset processing on a parameter verification result included in the current business processing result based on a preset parameter verification result processor according to an exemplary embodiment of the present disclosure is schematically shown.

[0053] Figure 5 A flowchart of a method for performing a second preset process on an exception error code included in the current business processing result based on a preset global exception handler according to an exemplary embodiment of the present disclosure is schematically shown.

[0054] Figure 6 A flowchart schematically shows a method for performing unified message encapsulation on the current business processing result after the first preset processing and the second preset processing based on a preset unified message encapsulation processor according to an example embodiment of the present disclosure to obtain a response message corresponding to the business request.

[0055] Figure 7 A flowchart schematically shows a method for performing unified message encapsulation on the current business processing result after the first preset processing and the second preset processing based on another preset unified message encapsulation processor according to an example embodiment of the present disclosure to obtain a response message corresponding to the business request.

[0056] Figure 8 The flowchart schematically shows another method for processing a service request according to an exemplary embodiment of the present disclosure.

[0057] Fig. 9 A block diagram schematically shows a device for processing a service request according to an exemplary embodiment of the present disclosure.

[0058] Fig.10 An electronic device for implementing the method for processing the service request according to an exemplary embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0059] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.

[0060] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.

[0061] In some schemes, the commonly agreed unified data message format can be as follows:

[0062]

[0063] In order to encapsulate the execution results of the business request into the above unified response message format, the back-end developer first needs to define an entity class, which can be as follows:

[0064]

[0065] When the business request operation is successfully executed, the operation result is encapsulated into the object of the entity class.

[0066] However, if an exception occurs during the operation, the exception error code and error message need to be filled in according to the exception type and then returned to the front end.

[0067] Under existing technical conditions, the code logic structure of the interface can usually be as follows:

[0068]

[0069]

[0070] However, the above solution has the following defects:

[0071] On the one hand, the development efficiency is low: just to unify the message format, developers manually create messages, manually fill in results, and manually fill in error codes, which leads to low efficiency in the development process. It is entirely possible to consider extracting these tasks separately and completing them automatically.

[0072] On the other hand, repetitive work: each interface that needs to return the agreed message format needs to be encapsulated, and if there is an error code, it also needs to be filled.

[0073] On the other hand, the code is not easy to read: in order to return a unified message, the service layer code usually needs to return a message object, which will lead to the pollution of the method return value. That is, the method that originally needs to return a specific business object is forced to return the object encapsulated by the message. The definition of the method is no longer clear and the readability is reduced.

[0074] Furthermore, the code is coupled and the responsibilities are confused: the encapsulation of the returned message and error code, that is, encapsulating the execution result into the agreed message, or converting the abnormal error into an error code and returning it to the caller, these are the responsibilities of the view layer code. Currently, all of them are done manually in the business code, resulting in serious code coupling and unclear code responsibilities.

[0075] Furthermore, lengthy parameter verification tips: When the interface input parameters need to be verified, manual non-empty judgment and other verifications are often required. The more parameters that need to be verified, the more lengthy the code for verification. In fact, these codes are not core business logic, and should be handed over to the framework for verification.

[0076] Finally, the chaotic exception handling system: the existing technology captures exceptions in each interface, and then encapsulates the exception code into the above-mentioned Result and CommonResult according to different exceptions. The full try...catch not only makes the code redundant, but also affects the development efficiency and readability of the code. When an exception occurs in the API provided to the outside world when processing business logic, it cannot directly return the exception stack information to the caller, but must return the error code corresponding to the exception to facilitate the connection between developers on both sides. The exception class is not associated with the exception error code. When an exception is thrown, it is necessary to find the exception code corresponding to the exception in the enumeration class and the definition class, which is both error-prone and very inefficient.

[0077] Based on this, this exemplary embodiment first provides a method for processing a business request, which can be run on a server, server cluster or cloud server where the Spring / Spring Boot framework is located; of course, those skilled in the art can also run the method disclosed in this disclosure on other platforms as required, which is not specifically limited in this exemplary embodiment. Figure 1As shown, the method for processing the service request may include the following steps:

[0078] Step S110. Receive a service request sent by a client, and in response to the service request, execute a service process corresponding to the service request to obtain a current service process result;

[0079] Step S120. Performing a first preset processing on the parameter check result included in the current business processing result based on a preset parameter check result processor, and performing a second preset processing on the abnormal error code included in the current business processing result based on a preset global exception processor;

[0080] Step S130. Based on the preset unified message encapsulation processor, the current service processing result after the first preset processing and the second preset processing is uniformly encapsulated to obtain a response message corresponding to the service request;

[0081] Step S140: Send the response message to the client, so that the client displays the response message.

[0082] In the above-mentioned method for processing business requests, on the one hand, by receiving the business request sent by the client, in response to the business request, the business processing corresponding to the business request is executed to obtain the current business processing result; then, based on the preset parameter verification result processor, the first preset processing is performed on the parameter verification result included in the current business processing result, and based on the preset global exception processor, the second preset processing is performed on the abnormal error code included in the current business processing result; then, based on the preset unified message encapsulation processor, the current business processing result after the first preset processing and the second preset processing is unified message encapsulated to obtain a response message corresponding to the business request; finally, the response message is sent to the client, so that the client displays the response message. Since the parameter verification result processor and the global exception processor can be used to perform unified message encapsulation on the current business processing result after the first preset processing and the second preset processing, a response message corresponding to the business request is obtained; The parameter verification results and abnormal error codes included in the current business processing results are processed, and the processed current business processing results are uniformly encapsulated based on the unified message encapsulation processor to obtain a response message, thereby realizing the automatic generation of the response message. This solves the problem in the prior art that each interface that needs to return the agreed message format needs to be manually encapsulated, and if there is an error code, it needs to be filled in, resulting in a large amount of repetitive labor, which leads to low efficiency in generating the response message, thereby improving the efficiency in generating the response message. On the other hand, since the message encapsulation is implemented in the unified message encapsulation processor, the problem of serious code coupling caused by the need to implement message encapsulation in the interface between the client and the server in the prior art is avoided, thereby realizing the decoupling of business processing and view rendering.

[0083] Hereinafter, the method for processing a service request according to an exemplary embodiment of the present disclosure will be explained and illustrated in detail with reference to the accompanying drawings.

[0084] First, the Spring / Spring Boot framework of the exemplary embodiment of the present disclosure is explained and illustrated. Figure 2 As shown, the Spring / Spring Boot framework may include a model (database entity) layer 201 , a dao (data persistence) layer 202 , a service (business logic) layer 203 , and a controller (control) layer 204 .

[0085] The model layer is the database entity layer, also known as the entity layer, pojo layer; generally, a table in a database corresponds to an entity class, and the class attributes correspond to the table fields one by one;

[0086] The dao layer is the data persistence layer, also known as the mapper layer; the function of the dao layer is to access the database, send SQL statements to the database, and complete the tasks of adding, deleting, modifying and checking data;

[0087] The service layer is the business logic layer, and its role is to complete the functional design; the service layer calls the dao layer interface, receives the data returned by the dao layer, and completes the basic functional design of the project; the service can include interfaces and implementation classes;

[0088] The controller layer is the control layer, and its function is request and response control. The controller layer is responsible for the front-end and back-end interaction, accepting front-end requests, calling the service layer, receiving data returned by the service layer, and finally returning specific pages and data to the client.

[0089] Secondly, in order to realize the automatic generation of response messages, you also need to enable the component. For details, refer to Figure 3 As shown, the method for processing the service request may also include:

[0090] Step S310, importing global configuration annotations based on preset annotation import parameters;

[0091] Step S320, using the global configuration annotation, enabling the parameter verification result processor, the global exception processor and the unified message encapsulation processor.

[0092] Below, step S310 and step S320 are explained and illustrated. Specifically, in Spring Boot, the @Import annotation (that is, the preset annotation import parameter) is provided, which can be used to import other configurations. After defining the @EnableGlobalResultHandler (global configuration) annotation as a component switch, the configuration class modified by the @Configuration annotation is imported through the @Import annotation. The required beans are initialized in the configuration class.

[0093] The @EnableGlobalResultHandler annotation is as follows:

[0094] @Target({ElementType.TYPE})

[0095] @Retention(RetentionPolicy.RUNTIME)

[0096] @Documented

[0097] @Inherited

[0098] @Import(GlobalResultHandlerAutoConfig.class)

[0099] public@interface EnableGlobalResultHandler{

[0100] }

[0101] The introduced GlobalResultHandlerAutoConfig configuration class is:

[0102] @Configuration

[0103] @EnableConfigurationProperties(GlobalResultHandlerConfigProperties.class)

[0104] pulic class GlobalResultHandlerAutoConfig{

[0105] The default configuration is initialized in the GlobalResultHandlerAutoConfig configuration file, which can be as follows:

[0106]

[0107] In this way, you can enable components with one click through annotations.

[0108] The following, combined Figure 2 as well as Figure 3 Steps S110 to S140 are explained and described.

[0109] In a method for processing a service request in an exemplary embodiment of the present disclosure:

[0110] In step S110, a service request sent by a client is received, and in response to the service request, a service process corresponding to the service request is executed to obtain a current service process result.

[0111] In this example embodiment, first, the controller (control) layer included in the Spring / Spring Boot framework is used to receive the business request sent by the client, and the service (business logic) layer included in the Spring / Spring Boot framework is called in response to the business request; to this end, the service (business logic) layer generates a query request based on the business attribute information included in the business request, and calls the mapper (data persistence) layer included in the Spring / Spring Boot framework; finally, the mapper (data persistence) layer obtains the current business processing result from the model (database entity) layer included in the Spring / Spring Boot framework, and feeds back the current business processing result to the service (business logic) layer, and then feeds back to the controller (control) layer via the service (business logic) layer.

[0112] For example, when the server is developing an application, if the application needs to be tested, a test request can be sent to the server through the client, and then the Spring / Spring Boot framework can perform corresponding business processing according to the test scenario included in the test request to obtain the business processing result. For example, when the test scenario is to test the user's login behavior to the application, the test scenario can be a login test scenario, which can include the user's login name, login password, etc., and perform corresponding business processing, that is, to determine whether the login name and / or login password are correct, etc., which can be limited according to actual needs, and this example does not make special limitations on this.

[0113] In step S120, a first preset processing is performed on the parameter verification result included in the current business processing result based on a preset parameter verification result processor, and a second preset processing is performed on the abnormal error code included in the current business processing result based on a preset global exception processor.

[0114] In this example embodiment, first, based on a preset parameter verification result processor, a first preset processing is performed on the parameter verification result included in the current business processing result, which may specifically include: first, based on the preset parameter verification result processor, it is determined whether there is a parameter abnormality in the parameter verification result included in the current business processing result; secondly, when it is determined that there is a parameter abnormality, according to the abnormality category of the parameter abnormality and a preset first mapping relationship, a first default error code corresponding to the abnormality category is obtained; finally, the first default error code is sealed in the current business processing result of the device to complete the first preset processing.

[0115] Specifically, refer to Figure 4 As shown, the specific process of the first preset processing may include the following steps:

[0116] Step S401, calling the parameter verification result processor (ValidationExceptionAdvice);

[0117] Step S402, based on the parameter verification result, the processor determines whether there is a parameter abnormality in the parameter verification result; if so, jump to step S403; if not, continue to the next parameter verification;

[0118] Step S403, obtaining a first default error code according to the exception category and a preset first mapping relationship; wherein the exception category may include one or more of a verification exception (BindException), a new data error (ConstraintViolationException), and a message too long (MethodArgumentNotValidException);

[0119] Step S404: The first default error code is sealed in the current service processing result of the device.

[0120] To give a further example, continuing with the above login process, when filling out the login form, if the login name is a mobile phone number, but the data actually entered by the user is character information such as abcd, then illegal data will appear in the verification process. The corresponding first default error code may be that the user name data format is incorrect, or that the user name does not exist, etc.

[0121] Furthermore, in this example embodiment, it is also necessary to perform a second preset processing on the exception error code included in the current business processing result based on the preset global exception handler, which may specifically include: first, obtaining the @exceptionMapper (exception handling) annotation based on the preset global exception handler, and using the @exceptionMapper (exception handling) annotation to extract the exception error code included in the current business processing result; secondly, when it is determined that the exception error code is empty, obtaining the second default error code when the exception error code is empty according to the preset second mapping relationship, and filling the second default error code into the current business processing result to complete the second preset processing; finally, when it is determined that the exception error code is not empty, obtaining the target error code in the @exceptionMapper (exception handling) annotation and the error prompt corresponding to the target error code, and filling the target error code and the error prompt into the current business processing result to complete the second preset processing.

[0122] Specifically, refer to Figure 5 As shown, the specific process of the second preset processing may include the following steps:

[0123] Step S501, calling the global exception handler (GlobalExceptionAdivce);

[0124] Step S502, obtaining ExceptionMapper annotation;

[0125] Step S503, determine whether the abnormal error code is empty; if so, jump to step S504; if not, jump to step S505;

[0126] Step S504, obtaining a second default error code based on the second mapping relationship, and filling it into the current business processing result;

[0127] Step S505, obtaining the target error code and error prompt in the @exceptionMapper annotation, and filling the target error code and the error prompt into the current business processing result.

[0128] For example, continuing with the above login process, when the user logs in, if the password is incorrect, an exception message is thrown; the login scenario gives an error code, and the return value of the error message to the front end can be, for example, 1400, and msg is the password error; the error prompt is displayed; the specific processing process of GlobalExceptionAdivce is: get the annotation, and judge whether the login password is wrong according to the custom exception information. If an exception occurs, capture the annotation; some exceptions do not belong to the custom range. If they are within the range, fill in the unified response object; if they are not within the range, fill in the default error code (the default error code can be, for example: server error or network exception, etc., this example does not make special restrictions on this).

[0129] In step S130, a preset unified message encapsulation processor performs unified message encapsulation on the current service processing result after the first preset processing and the second preset processing to obtain a response message corresponding to the service request.

[0130] In this example embodiment, first, based on the preset unified message encapsulation processor, it is determined whether the return type of the method included in the current business processing result after the first preset processing and the second preset processing is empty; secondly, if the return type is empty, a default success unified message object is created according to the current business processing result after the first preset processing and the second preset processing; finally, a response message corresponding to the business request is generated according to the success unified message object.

[0131] Furthermore, in this example embodiment, if the return type is not empty, it is determined whether the return value of the method is empty; if the return value is empty, a default success unified message object is created according to the current business processing result after the first preset processing and the second preset processing, and a response message corresponding to the business request is generated according to the success unified message object; if the return value is not empty and the return value is not a preset unified message definition class, the return value is encapsulated as an object of the unified message definition class, and a response message corresponding to the business request is generated according to the object of the unified message definition class.

[0132] The following, combined Figure 6 as well as Figure 7 Step S130 is further explained and illustrated.

[0133] First, refer to Figure 6 As shown:

[0134] Step S601, calling a unified message encapsulation processor (VoidResponseBodyAdvice);

[0135] Step S602, determine whether the return type of the method is void; if so, jump to step S603; if not, jump to step S701;

[0136] Step S603: create a default success unified message object and generate a response message.

[0137] Secondly, refer to Figure 7 As shown:

[0138] Step S701, calling a unified message encapsulation processor (NotVoidResponseBodyAdvice);

[0139] Step S702, determine whether the return type of the method is not void (NotVoid); if so, jump to step S703; if not, continue to the next method;

[0140] Step S703, determine whether the return value of the method is null; if so, jump to step S704; if not, jump to step S705;

[0141] Step S704, creating a default success unified message object and generating a response message;

[0142] Step S705: encapsulate the return value into an object of the unified message definition class and generate a response message.

[0143] In step S140, the response message is sent to the client, so that the client displays the response message.

[0144] Specifically, after the client displays the response message, the user and / or tester can determine whether the test passes according to the response message. If the test fails, the user and / or tester can also see the reason for the test failure and then debug according to the reason for the failure. This method greatly improves development efficiency.

[0145] The following, combined Figure 8 The method for processing a service request according to the exemplary embodiment of the present disclosure is further explained and illustrated. Figure 8 As shown, the method for processing the service request may include the following steps:

[0146] Step S810, enable annotations, and configure the unified message encapsulation and exception error code matching components through annotations;

[0147] Step S820, the controller receives the service request sent by the client, and calls the service layer to perform the service processing to obtain the current service processing result;

[0148] Step S830, the controller uses the unified message encapsulation and exception error code matching component to encapsulate the current business processing result to obtain a response message;

[0149] In step S840, the controller sends the response message to the client, so that the client displays the response message.

[0150] The method for processing a service request provided by the exemplary embodiment of the present disclosure has at least the following advantages:

[0151] On the one hand, it improves development efficiency: through an annotation, the global automatic return message encapsulation and exception error code matching are enabled. After that, each interface no longer needs to manually create a success message object or fill in the error code, which greatly improves development efficiency.

[0152] On the other hand, it reduces repetitive work: after the annotation is turned on, the component automatically encapsulates the message without manual participation, and there is no need to repeatedly encapsulate the return object in each interface.

[0153] On the other hand, it improves code readability: only business-related code logic needs to be written in the interface, and the encapsulation of the return message has been completely completed by the component, so the code readability is very high.

[0154] Furthermore, code is decoupled: only business logic is processed in the interface, and the encapsulation of the return message is completely completed by the component, which decouples business processing from view rendering and makes the code responsibilities clear.

[0155] Furthermore, the existing parameter validation method is integrated: by integrating the Hibernate Validator parameter validation framework, parameter validation and prompt return can be performed without additional coding.

[0156] Finally, a simple and feasible exception error code system is provided: through the @ExceptionMapper annotation, when customizing the exception, define the exception code, and the component automatically fills in the error code when the exception is thrown. The exception definition is as follows:

[0157] @ExceptionMapper(code=1404, msg=“Not found!”)

[0158] public static class NotFoundException extends RuntimeException{}

[0159] The present disclosure also provides a device for processing a service request. Fig. 9As shown, the service request processing device may include a service processing execution module 910, a service processing result processing module 920, a service processing result encapsulation module 930 and a response message sending module 940. Among them:

[0160] The business processing execution module 910 may be used to receive a business request sent by a client, and in response to the business request, execute a business process corresponding to the business request to obtain a current business processing result;

[0161] The business processing result processing module 920 may be used to perform a first preset processing on the parameter verification result included in the current business processing result based on a preset parameter verification result processor, and perform a second preset processing on the abnormal error code included in the current business processing result based on a preset global exception processor;

[0162] The business processing result encapsulation module 930 may be used to perform unified message encapsulation on the current business processing result after the first preset processing and the second preset processing based on a preset unified message encapsulation processor to obtain a response message corresponding to the business request;

[0163] The response message sending module 940 may be configured to send the response message to the client so that the client displays the response message.

[0164] In an exemplary embodiment of the present disclosure, the service request processing device further includes:

[0165] Annotation import module, which can be used to import global configuration annotations based on preset annotation import parameters;

[0166] The processing activation module can be used to use the global configuration annotation to activate the parameter verification result processor, the global exception processor and the unified message encapsulation processor.

[0167] In an exemplary embodiment of the present disclosure, the business processing execution module may also be configured to:

[0168] Utilize the control layer included in the Spring / Spring Boot framework to receive the service request sent by the client, and call the service logic layer included in the Spring / Spring Boot framework in response to the service request;

[0169] The business logic layer generates a query request according to the business attribute information included in the business request, and calls the data persistence layer included in the Spring / Spring Boot framework;

[0170] The data persistence layer obtains the current business processing result from the database entity layer included in the Spring / Spring Boot framework, and feeds back the current business processing result to the business logic layer, and then feeds back to the control layer via the business logic layer.

[0171] In an exemplary embodiment of the present disclosure, the business processing result processing module may also be configured to:

[0172] Based on a preset parameter verification result processor, determining whether there is a parameter abnormality in the parameter verification result included in the current business processing result;

[0173] When it is determined that there is a parameter abnormality, according to the abnormality category of the parameter abnormality and a preset first mapping relationship, a first default error code corresponding to the abnormality category is obtained;

[0174] The first default error code is sealed in the current service processing result of the device to complete the first preset processing.

[0175] In an exemplary embodiment of the present disclosure, the business processing result processing module may also be configured to:

[0176] Acquire an exception handling annotation based on a preset global exception handler, and use the exception handling annotation to extract the exception error code included in the current business processing result;

[0177] When it is determined that the abnormal error code is empty, obtaining a second default error code when the abnormal error code is empty according to a preset second mapping relationship, and filling the second default error code into the current business processing result to complete the second preset processing;

[0178] When it is determined that the exception error code is not empty, obtain the target error code in the exception handling annotation and the error prompt corresponding to the target error code, and fill the target error code and the error prompt into the current business processing result to complete the second preset processing.

[0179] In an exemplary embodiment of the present disclosure, the business processing result encapsulation module may also be configured to:

[0180] Based on the preset unified message encapsulation processor, determining whether the return type of the method included in the current business processing result after the first preset processing and the second preset processing is empty;

[0181] If the return type is empty, a default successful unified message object is created according to the current business processing result after the first preset processing and the second preset processing;

[0182] A response message corresponding to the service request is generated according to the successful unified message object.

[0183] In an exemplary embodiment of the present disclosure, the business processing result encapsulation module may also be configured to:

[0184] If the return type is not empty, determine whether the return value of the method is empty;

[0185] If the return value is empty, a default successful unified message object is created according to the current service processing result after the first preset processing and the second preset processing, and a response message corresponding to the service request is generated according to the successful unified message object;

[0186] If the return value is not empty and the return value is not a preset unified message definition class, the return value is encapsulated as an object of the unified message definition class, and a response message corresponding to the service request is generated according to the object of the unified message definition class.

[0187] The specific details of each module in the above-mentioned service request processing device have been described in detail in the corresponding service request processing method, so they will not be repeated here.

[0188] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.

[0189] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.

[0190] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.

[0191] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods or program products. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: complete hardware implementation, complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as "circuits", "modules" or "systems".

[0192] Refer to the following Fig.10 The electronic device 1000 according to this embodiment of the present disclosure is described. Fig.10 The electronic device 1000 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0193] like Fig.10 As shown, the electronic device 1000 is in the form of a general computing device. The components of the electronic device 1000 may include, but are not limited to: the at least one processing unit 1010, the at least one storage unit 1020, a bus 1030 connecting different system components (including the storage unit 1020 and the processing unit 1010), and a display unit 1040.

[0194] The storage unit stores a program code, which can be executed by the processing unit 1010, so that the processing unit 1010 performs the steps according to various exemplary embodiments of the present disclosure described in the above “Exemplary Method” section of this specification. For example, the processing unit 1010 can perform the following steps: Figure 1 The step S110 shown in the figure is: receiving a business request sent by a client, and executing a business processing corresponding to the business request in response to the business request to obtain a current business processing result; step S120: performing a first preset processing on the parameter verification result included in the current business processing result based on a preset parameter verification result processor, and performing a second preset processing on the exception error code included in the current business processing result based on a preset global exception processor; step S130: performing unified message encapsulation on the current business processing result after the first preset processing and the second preset processing based on a preset unified message encapsulation processor to obtain a response message corresponding to the business request; step S140: sending the response message to the client, so that the client displays the response message.

[0195] The storage unit 1020 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 10201 and / or a cache storage unit 10202 , and may further include a read-only storage unit (ROM) 10203 .

[0196] The storage unit 1020 may also include a program / utility 10204 having a set (at least one) of program modules 10205, such program modules 10205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0197] Bus 1030 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0198] The electronic device 1000 may also communicate with one or more external devices 1100 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1000, and / or may communicate with any device that enables the electronic device 1000 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 1050. Furthermore, the electronic device 1000 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 1060. As shown, the network adapter 1060 communicates with other modules of the electronic device 1000 via a bus 1030. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1000, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0199] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.

[0200] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present disclosure may also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary implementations of the present disclosure described in the above "Exemplary Method" section of the present specification.

[0201] According to the program product for implementing the above method in the embodiment of the present disclosure, it can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0202] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0203] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0204] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.

[0205] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0206] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.

[0207] Other embodiments of the present disclosure will be readily apparent to those skilled in the art after considering the specification and practicing the inventions invented herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not invented by the present disclosure. The specification and examples are to be considered merely exemplary, and the true scope and spirit of the present disclosure are indicated by the claims.

Claims

1. A method for processing a service request, characterized in that: include: Based on a preset annotation import parameter, a global configuration annotation is imported, and the global configuration annotation is used as a component switch; wherein the preset annotation import parameter is an Import annotation; Using the global configuration annotation, enable the parameter verification result processor, the global exception processor, and the unified message encapsulation processor; Receive a service request sent by a client, and in response to the service request, execute a service process corresponding to the service request to obtain a current service process result; Based on a preset parameter check result processor, determine whether there is a parameter abnormality in the parameter check result included in the current business processing result; when it is determined that there is a parameter abnormality, obtain a first default error code corresponding to the abnormal category according to the abnormal category of the parameter abnormality and a preset first mapping relationship; encapsulate the first default error code into the current business processing result to complete the first preset processing, and obtain an exception processing annotation based on a preset global exception processor, and use the exception processing annotation to extract the abnormal error code included in the current business processing result; when it is determined that the abnormal error code is empty, obtain a second default error code when the abnormal error code is empty according to a preset second mapping relationship, and fill the second default error code into the current business processing result to complete the second preset processing; when it is determined that the abnormal error code is not empty, obtain a target error code in the exception processing annotation and an error prompt corresponding to the target error code, and fill the target error code and the error prompt into the current business processing result to complete the second preset processing; Based on a preset unified message encapsulation processor, a current service processing result after the first preset processing and the second preset processing is uniformly encapsulated to obtain a response message corresponding to the service request; The response message is sent to the client, so that the client displays the response message.

2. The method for processing a service request according to claim 1, characterized in that: Receiving a service request sent by a client, and executing a service process corresponding to the service request in response to the service request to obtain a current service process result, including: Utilize the control layer included in the Spring / Spring Boot framework to receive the service request sent by the client, and call the service logic layer included in the Spring / Spring Boot framework in response to the service request; The business logic layer generates a query request according to the business attribute information included in the business request, and calls the data persistence layer included in the Spring / Spring Boot framework; The data persistence layer obtains the current business processing result from the database entity layer included in the Spring / Spring Boot framework, and feeds back the current business processing result to the business logic layer, and then feeds back to the control layer via the business logic layer.

3. The method for processing a service request according to claim 1, characterized in that: Based on the preset unified message encapsulation processor, the current service processing result after the first preset processing and the second preset processing is uniformly encapsulated to obtain a response message corresponding to the service request, including: Based on the preset unified message encapsulation processor, determining whether the return type of the method included in the current business processing result after the first preset processing and the second preset processing is empty; If the return type is empty, a default successful unified message object is created according to the current business processing result after the first preset processing and the second preset processing; A response message corresponding to the service request is generated according to the successful unified message object.

4. The method for processing a service request according to claim 3, characterized in that: The method for processing the service request also includes: If the return type is not empty, determine whether the return value of the method is empty; If the return value is empty, a default successful unified message object is created according to the current service processing result after the first preset processing and the second preset processing, and a response message corresponding to the service request is generated according to the successful unified message object; If the return value is not empty and the return value is not a preset unified message definition class, the return value is encapsulated as an object of the unified message definition class, and a response message corresponding to the service request is generated according to the object of the unified message definition class.

5. A service request processing device, characterized in that: include: An annotation import module, used to import global configuration annotations based on preset annotation import parameters, and use the global configuration annotations as component switches; wherein the preset annotation import parameters are Import annotations; A processing start module, used to use the global configuration annotation to start the parameter verification result processor, the global exception processor and the unified message encapsulation processor; A business processing execution module, used to receive a business request sent by a client, and in response to the business request, execute a business process corresponding to the business request to obtain a current business processing result; A business processing result processing module, used to determine whether there is a parameter abnormality in the parameter verification result included in the current business processing result based on a preset parameter verification result processor; when it is determined that there is a parameter abnormality, according to the abnormal category of the parameter abnormality and a preset first mapping relationship, obtain a first default error code corresponding to the abnormal category; encapsulate the first default error code into the current business processing result to complete the first preset processing, and obtain an exception processing annotation based on a preset global exception processor, and use the exception processing annotation to extract the abnormal error code included in the current business processing result; when it is determined that the abnormal error code is empty, obtain a second default error code when the abnormal error code is empty according to a preset second mapping relationship, and fill the second default error code into the current business processing result to complete the second preset processing; when it is determined that the abnormal error code is not empty, obtain a target error code in the exception processing annotation and an error prompt corresponding to the target error code, and fill the target error code and the error prompt into the current business processing result to complete the second preset processing; A business processing result encapsulation module, which is used to perform unified message encapsulation on the current business processing result after the first preset processing and the second preset processing based on a preset unified message encapsulation processor to obtain a response message corresponding to the business request; wherein the parameter verification result processor, the global exception processor and the unified message encapsulation processor are enabled through global configuration annotations; A response message sending module is used to send the response message to the client so that the client displays the response message.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for processing a service request according to any one of claims 1 to 4 is implemented.

7. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to execute the method for processing a service request according to any one of claims 1 to 4 by executing the executable instructions.