Parameter validation result generation method and apparatus, validation platform, and storage medium
By binding verification rules and error codes in the Spring Validation framework, the verification failure result of each field is generated and the problem of missing error codes in the prior art is solved, and the availability and coding efficiency of verification results are improved.
Patent Information
- Application Number
- PCT/CN2024/092748
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-01-11
- Filing Date
- 2024-05-13
- Publication Date
- 2025-07-17
AI Technical Summary
In the prior art, using the Spring Validation verification tool to lack error codes in the verification results generated after the verification failure, resulting in difficulty in distinguishing subsequent business logic, and writing hard codes for each API interface are cumbersome and workloads.
By binding the verification rules and verification error messages to the error code, the verification failure results of each field are automatically generated, so as to decouple the verification results from business encoding, reducing hard coding and repeated judgments.
It enhances the availability of verification results, reduces the workload of code writing and maintenance, and realizes the verification error output corresponding error codes and messages for each field of each interface.
Smart Images

Figure CN2024092748_17072025_PF_FP_ABST
Abstract
Description
Parameter verification result generation method and device, verification platform and storage medium Technical Field
[0001] This application relates to the field of application parameter verification technology, and more particularly to a method and apparatus for generating parameter verification results, a verification platform, and a storage medium. This application references Chinese Patent Application No. 202410040435.2, filed on January 11, 2024, entitled "Method and Apparatus for Generating Parameter Verification Results, Verification Platform, and Storage Medium," which is incorporated herein by reference in its entirety. Background Art
[0002] When a client calls a server-side service, parameter validation is often required. Spring Validation is a commonly used validation tool. Spring Validation provides an additional layer of encapsulation for Hibernate Validator, making it easier to use within Spring. Technical issues
[0003] Currently, when using Spring Validation technology, the verification results generated after a verification failure include a verification failure message, but the error code corresponding to the verification failure is missing, making it difficult to distinguish subsequent business logic. Adding an error code for each verification failure result requires hard coding for each API (Application Programming Interface), exhaustively listing every field to be verified, and then determining the error code and error message for each field after the verification fails. This requires a lot of code writing and modification work. Technical Solutions
[0004] The purpose of some embodiments of the present application is to provide a parameter verification result generation method and device, a verification platform and a storage medium. By binding the verification rules, verification error messages and corresponding error codes, the corresponding error code and verification error message are automatically generated for the verification failure result of each field, thereby increasing the availability of the verification result when the verification fails, and decoupling from the business coding without the need for hard coding and error code judgment for each interface, greatly reducing the workload.
[0005] In a first aspect, an embodiment of the present application provides a method for generating a parameter verification result, comprising: receiving a request from a client to call a cloud application programming interface (API);
[0006] Verify the request based on the MVC verification framework and obtain the verification result;
[0007] When the verification result includes a verification error message, the corresponding target error code enumeration is found according to the verification error message and a preset error code enumeration list; wherein each error code enumeration in the error code enumeration list includes: an error code and a verification error message corresponding to the error code;
[0008] The error code of the request and a verification error message are returned to the client according to the target error code enumeration.
[0009] As an embodiment, the MVC verification framework is a Spring MVC verification framework, which includes: a Request Mapping module, a Spring Validation module, a global exception handler, a Request Bean module, and an error code enumeration module; the verification result includes a verification error message;
[0010] Verifying the request based on the MVC verification framework and obtaining a verification result includes:
[0011] The Request Mapping module obtains the request object of the request through the Request Bean module according to the request path;
[0012] The Request Bean module obtains the model of the request object according to the request object and returns it to the Request Mapping module. The Request Mapping module obtains the validation parameters of the model according to the request object and sends them to the Spring Validation module.
[0013] The Spring Validation module performs validation based on the validation parameters of the model of the request object, and throws validation exception information if the validation is abnormal;
[0014] The global exception handler captures the verification exception information and extracts the verification error message of the request.
[0015] As an embodiment, the step of finding the corresponding target error code enumeration according to the verification error message and a preset error code enumeration list includes:
[0016] The error code enumeration module receives the verification error message of the request sent by the global exception handler, and searches the error code enumeration list according to the verification error message to obtain the target error code enumeration.
[0017] As an embodiment, the Spring MVC verification framework further includes: a Request Body Advice module; and returning the error code of the request and the verification error message to the client according to the target error code enumeration includes:
[0018] The error code enumeration module sends the target error code enumeration to the Request Body Advice module through the global exception handler and the API interface module in sequence;
[0019] The Request Body Advice module enumerates the error code of the request according to the target error code and verifies the error message and sends it to the API interface module;
[0020] The API interface module returns the error code of the request and a verification error message to the client.
[0021] As an embodiment, the method further includes:
[0022] After the Spring Validation module verifies the parameters of the request, it sends a verification pass message to the Request Mapping module, the API interface module, and the Request Body Advice module in sequence;
[0023] The Request Body Advice module assembles and obtains a request verification success message and sends it to the API interface module;
[0024] The API interface module returns the request verification success message to the client.
[0025] In a second aspect, an embodiment of the present application provides a parameter verification result generating device, comprising:
[0026] The request receiving module is used to receive the request from the client to call the cloud application program interface API;
[0027] A verification module is used to verify the request based on the MVC verification framework and obtain a verification result;
[0028] a verification error search module configured to, when the verification result of the verification module includes a verification error message, search for a corresponding target error code enumeration based on the verification error message and a preset error code enumeration list; each error code enumeration in the error code enumeration list includes: an error code and a verification error message corresponding to the error code;
[0029] The verification result returning module is used to return the error code of the request and the verification error message to the client according to the target error code enumeration.
[0030] As an embodiment, the MVC verification framework is a Spring MVC verification framework, which includes: a Request Mapping module, a Spring Validation module, a global exception handler, a Request Bean module, and an error code enumeration module; the verification result includes a verification error message;
[0031] The verification module includes:
[0032] Request object parsing submodule, the Request Mapping module obtains the request object of the request through the Request Bean module according to the request path;
[0033] Parameter extraction submodule, the Request Bean module obtains the model of the request object according to the request object and returns it to the Request Mapping module, the Request Mapping module obtains the model verification parameters according to the model of the request object and sends them to the Spring Validation module;
[0034] Spring validation submodule, the Spring Validation module performs validation according to the validation parameters of the model of the request object, and throws validation exception information if the validation is abnormal;
[0035] The verification error message capturing submodule, the global exception processor captures the verification exception information and extracts the verification error message of the request.
[0036] As an embodiment, the verification error search module includes: the error code enumeration module receives the verification error message of the request sent by the global exception handler, and searches the error code enumeration list according to the verification error message to obtain the target error code enumeration.
[0037] In a third aspect, an embodiment of the present application provides a verification platform, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein when the processor executes the program, the parameter verification result generating method as described in the first aspect is implemented.
[0038] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the parameter verification result generating method as described in the first aspect. Beneficial effects
[0039] Compared with the prior art, the technical solution provided by the embodiments of the present application has at least the following positive effects:
[0040] The parameter verification result generation method of the embodiment of the present application, when the request is verified based on the MVC verification framework and the obtained verification result includes a verification error message, the corresponding target error code enumeration is found according to the verification error message and the preset error code enumeration list, and then the requested error code and verification error message are returned to the client according to the target error code enumeration. By binding the verification rules with the error code and error message, the verification result is decoupled from the business coding. Not only can the corresponding error code and verification error message be output for the verification error of each field of each interface, thereby enhancing the availability of the verification result, but also the need for hard coding and error code judgment is eliminated, thereby reducing the workload of coding and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, a brief introduction will be given below to the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0042] FIG1 is a flow chart of a method for generating parameter verification results according to a first embodiment of the present application;
[0043] FIG2 is a schematic diagram of a specific flow chart of a method for generating parameter verification results according to the first embodiment of the present application;
[0044] FIG3 is a schematic diagram of the structure of a parameter verification result generating device provided in Example 2 of the present application;
[0045] FIG4 is a schematic diagram of the structure of the verification platform provided in Example 3 of the present application. Best Mode for Carrying Out the Invention
[0046] The preferred embodiments of this application are described below and will not be described in detail here. Modes for Carrying Out the Invention
[0047] In order to make the purpose, technical solutions and advantages of this application more clear, some embodiments of this application are further described in detail below in conjunction with the accompanying drawings and examples. It should be understood that the specific embodiments described here are only used to explain this application and are not used to limit this application.
[0048] The inventor discovered that when the existing technology performs parameter verification based on the Spring-Validation verification framework, after the verification fails, the FieldError object is obtained from the BindingResult, thereby obtaining the value of the message set in the annotation on the field that needs to be verified, that is, the error message when the verification fails. Then, the error message is bound to a unified error code, that is, if any field verification fails, the generated error code is the same, and the verification error information of different parameters is only different in the error message prompt. At this time, the request end cannot execute subsequent business logic according to the business error code. The inventor proposed an ingenious solution. By binding the verification rules and the error messages and error codes of the verification annotations, the verification error of each field can automatically generate an error code that matches it. Since it can be decoupled from the business code, there is no need for hard-coded and repetitive judgment code.
[0049] Figure 1 is a flow chart illustrating a method for generating parameter verification results according to a first embodiment of the present application. The technical solution of this embodiment is applicable to verifying parameters in Web application requests. This method can be performed by a parameter verification result generation device according to an embodiment of the present application. This device can be implemented using software and / or hardware and configured on a verification platform. The method specifically includes the following steps:
[0050] Step 101: Receive a request from a client to call a cloud application programming interface (API).
[0051] The client can call the cloud API based on the web to perform the required business, such as the business based on digital keys in the Internet of Vehicles. The embodiment of this application does not impose specific restrictions on the actual business. The client can call the cloud API based on a web page made according to the HTML5 specification.
[0052] Step 102: Verify the request based on the MVC verification framework and obtain the verification result.
[0053] The validation platform includes an API interface module and the Spring MVC validation framework. The Spring MVC validation framework includes a Request Mapping module, a Spring Validation module, a global exception handler, a Request Bean module, a Request Body Advice module, and an error code enumeration module. Verification results include a validation success message and / or a validation error message.
[0054] Step 102 verifies the request based on the MVC verification framework and obtains the verification result, which may include: the Request Mapping module obtains the request object of the request through the RequestBean module according to the request path, the Request Bean module obtains the model of the request object according to the request object and returns it to the Request Mapping module, the Request Mapping module obtains the verification parameters of the model according to the request object and sends it to the Spring Validation module, the Spring Validation module verifies according to the verification parameters of the model of the request object, and throws a verification exception message if the verification is abnormal, and the global exception handler captures the verification exception message and extracts the verification error message of the request.
[0055] Step 103: When the verification result includes a verification error message, a corresponding target error code enumeration is found according to the verification error message and a preset error code enumeration list.
[0056] Each error code enumeration in the ErrorCodeEnum list contains an error code and its corresponding error message. The ErrorCodeEnum list defines the error code and error message for each field of each API and parameter. Each error code in the ErrorCodeEnum list is associated with an error message. The error message can be used to find the corresponding ErrorCodeEnum.
[0057] Step 103 of finding the corresponding target error code enumeration according to the verification error message and the preset error code enumeration list may include: the error code enumeration module receives the verification error message of the request sent by the global exception handler, and finds the error code enumeration list according to the verification error message to obtain the target error code enumeration.
[0058] Step 104: Return the requested error code and verification error message to the client according to the target error code enumeration.
[0059] Extract the error code corresponding to the request from the target error code enumeration and verify the error message and return it to the client.
[0060] Step 104 of returning the requested error code and verification error message to the client according to the target error code enumeration may include: the error code enumeration module sends the target error code enumeration to the Request Body Advice module through the global exception handler and the API interface module in sequence, the Request Body Advice module obtains the requested error code and verification error message according to the target error code enumeration and sends them to the API interface module, and the API interface module returns the requested error code and verification error message to the client.
[0061] When the verification results are all successful, the Spring Validation module verifies the request parameters and sends the verification pass message to the Request Mapping module, API interface module and Request Body Advice module in sequence. The Request Body Advice module assembles the request verification success message and sends it to the API interface module. The API interface module returns the request verification success message to the client.
[0062] FIG2 is a schematic diagram of an exemplary process of generating a parameter verification result based on the Spring MVC verification framework. The following is a detailed description of the method shown in FIG2 and taking the Spring MVC verification framework as an example:
[0063] S201: The client calls the cloud API.
[0064] The client calls the cloud API through the web, and the cloud's Spring MVC validation framework can be used for parameter verification. The API interface (API Entry) module sends the request to the Request Mapping module.
[0065] S202: The Request Mapping module obtains the request object from the Request bean module.
[0066] For examples of request objects, see Request Bean1 and RequestBean2 below.
[0067] S203: The Request bean module returns the object model to the Request Mapping module.
[0068] S204: The Request Mapping module obtains the verification parameters of the object model according to the object model, and sends them to the Spring Validation module for parameter verification.
[0069] S205: The Spring Validation module performs parameter verification according to the verification parameters of the object model.
[0070] S206: After the verification is passed, the Spring Validation module sends the verification result to the API interface through the Request Mapping module.
[0071] S207: The API interface requests the Request Body Advice module to process the verification result and return the request data.
[0072] S208: The Request Body Advice module returns the processed request data to the API interface.
[0073] For example, the return data when all parameters pass the verification is: {"code":0, "msg":"Operation successful"}.
[0074] S209: The API interface returns the requested data to the client.
[0075] S206 to S209 are the cases where all parameters have passed verification. The following steps 10 to 16 are the process of returning the verification result of the parameter USERNAME_NULL (user name is empty).
[0076] S210: When the S205 parameter verification fails, the Spring Validation module throws a verification failure exception.
[0077] S211: The Whole Exception Processor captures the exception and extracts the message from the exception. The message is USER_NAME_NULL (the user name is empty).
[0078] S212: The global exception handler sends the verification error message msg to the error code enumeration module. The error code enumeration module searches for the corresponding ErrorCodeEnum (error code enumeration) according to the verification error message msg (msg=USER_NAME_NULL).
[0079] S213: The error code enumeration module finds the target error code enumeration.
[0080] The target error code enumeration is USER_NAME_NULL{code:10000,Msg:"User name is empty"}.
[0081] The error code enumeration module sends the target error code enumeration to the global exception handler and API interface in sequence.
[0082] S214: The API interface requests Request Body Advice and processes the returned data according to the target error code enumeration.
[0083] S215: The Request Body Advice module processes and obtains the return data.
[0084] The returned data is: {"code":10000;"msg":"Username is empty"}. The Request Body Advice module returns the processed data to the API interface.
[0085] S216: The API interface returns the interface request data to the client.
[0086] The returned request data contains: {"code":10000;"msg":"The user name is empty"}.
[0087] In S201~S216, the Spring MVC validation framework will find the request method in the corresponding Controller from the Request Mapping according to the request path, and then hand it over to the Spring validation framework for verification based on the object that needs to be verified defined in the method.
[0088] If the Username parameter is null, the Spring validation framework will throw one of the following exceptions: Bind Exception, Method Argument Not Valid Exception, or Constraint Violation Exception, based on the @NotNull(msg="USERNAME_NULL") annotation used for the Username field defined in the Request Bean. The global exception handler will then catch these exceptions, retrieve the message from the exception information, and find the USERNAME_NULL enumeration in the business error enumeration using the message. The enumeration data {"code":10000, "msg": "Username is null"} will be returned to the client (app / html5).
[0089] This embodiment of the application binds the verification rules, verification error messages, and error codes, decoupling the generation of error codes from the business code. This automatically includes the error code in the generated verification results, eliminating the need for hard-coded or duplicated judgment code. The following pseudocode illustrates the advantages of this embodiment of the application compared to other solutions.
[0090] First, different solutions require defining the request object and business error code. The following defines the request object, corresponding fields to be checked, and corresponding business error codes for two interfaces based on different verification result generation solutions.
[0091] Business error enumeration:
[0092] ErrorCodeEnum {
[0093] USERNAME_NULL {
[0094] code: 10000,
[0095] msg: "Username is empty"
[0096] },
[0097] PHONE_NO_NULL {
[0098] code: 10001,
[0099] msg: "Mobile number is empty"
[0100] },
[0101] PHONE_NO_WRONG_LENGTH {
[0102] code: 10002,
[0103] msg: "The phone number length is incorrect"
[0104] },
[0105] VIN_NULL {
[0106] code: 10003,
[0107] msg: "VIN is empty"
[0108] },
[0109] VIN_WRONG_LENGTH {
[0110] code: 10004,
[0111] msg: "VIN length is incorrect"
[0112] },
[0113] VALIDATE_ERROR {
[0114] code:99999
[0115] }
[0116] }
[0117] Comparison Solution 1: Use hard coding to verify each parameter in each interface, then manually identify the fields that fail verification and return the corresponding error.
[0118] Request Object:
[0119] RqusetBean1{
[0120] Username;
[0121] PhoneNo;
[0122] }
[0123] RequestBean2{
[0124] Username;
[0125] Vin;
[0126] }
[0127] RequsetBean1 requires that the Username field cannot be empty, the PhoneNo field cannot be empty, and the length must be 11 characters. RequestBean2 requires that the Username field cannot be empty, the VinNo field cannot be empty, and the length must be 17 characters.
[0128] Interface 1: / api / test1
[0129] test1(RequestBean1) {
[0130] if (RequsetBean1.Username == null)
[0131] return ErrorCodeEnum.USERNAME_NULL;
[0132] else if (RequestBean1.PhoneNo == null)
[0133] return ErrorCodeEnum.PHONE_NO_NULL;
[0134] else if (RequestBean1.PhoneNo.length == 11)
[0135] return ErrorCodeEnum.PHONE_NO_WRONG_LENGTH;
[0136] }
[0137] Interface 2: / api / test2
[0138] test2(RequestBean2) {
[0139] if (RequsetBean2.Username == null)
[0140] return ErrorCodeEnum.USERNAME_NULL;
[0141] else if (RequestBean2.Vin == null)
[0142] return ErrorCodeEnum.VIN_NULL;
[0143] else if (RequestBean2.Vin.length == 17)
[0144] return ErrorCodeEnum.VIN_WRONG_LENGTH;
[0145] }
[0146] Calling interface and interface response:
[0147] / api / test1 {PhoneNo:“12345678911”} => {code:10001,msg:“Username is empty”}
[0148] / api / test1 {Username:"Zhang San",PhoneNo:"123"} => {code:10003,msg:"The phone number length is incorrect"}
[0149] / api / test2 {Username: "Zhang San"} => {code:10003,msg:"VIN length is incorrect"}
[0150] As can be seen from Comparison Plan 1, the hard-coding method requires writing corresponding code for each interface and each field that needs to be verified in each interface. This is cumbersome and labor-intensive, and is not easy to maintain. When a verification field is changed, multiple parts of the code need to be modified.
[0151] Comparison plan 2: Use the Spring Validation framework and judge the return in each interface method.
[0152] Request Object:
[0153] RequestBean1{
[0154] @NotNull(msg="Username is empty")
[0155] Username;
[0156] @NotNull(msg="Phone number is empty")
[0157] @Length(min=11,max=11,msg="Incorrect phone number length")
[0158] PhoneNo;
[0159] }
[0160] RequestBean2{
[0161] @NotNull(msg="Username is empty")
[0162] Username;
[0163] @NotNull(msg="VIN is null")
[0164] @Length(min=17,max=17,msg="Incorrect VIN length")
[0165] Vin;
[0166] }
[0167] Interface 1: / api / test1
[0168] test1(@Valid ReuqsetBean1, BindResult) {
[0169] return {
[0170] code: ErrorCodeEnum.VALIDATE_ERROR.code,
[0171] msg: BindResult.msg
[0172] }
[0173] }
[0174] Interface 2: / api / test2
[0175] test2(@Valid RequsetBean2, BindResult) {
[0176] return {
[0177] code: ErrorCodeEnum.VALIDATE_ERROR.code,
[0178] msg: BindResult.msg
[0179] }
[0180] }
[0181] Interface call and interface response:
[0182] / api / test1 {PhoneNo: “12345678911”} => {code:99999,msg: “Username is empty”}
[0183] / api / test1 {Username: “张三”,PhoneNo: “123”} => {code:99999,msg: “Phone number length is incorrect”}
[0184] / api / test2 {Username: “张三”} => {code:99999,msg: “VIN length is incorrect”}
[0185] As can be seen from Comparative Solution 2, it is still necessary to add return error codes in each interface method, and all validation failures can only correspond to one error code (99999). If the client (APP / H5) executes business logic based on business error codes, it will be impossible to distinguish specific errors. <>
[0186] Comparison Solution 3: Use the Spring Validation framework and global exception handling.
[0187] Request object:
[0188] Same as Comparison Solution 2
[0189] Interface 1: / api / test1
[0190] test1(@Valid ReuqsetBean1);
[0191] Interface 2: / api / test2
[0192] test2(@Valid RequestBean2);
[0193] Global exception handling:
[0194] WholeExceptionProcessor {
[0195] doException (BindException) {
[0196] return {
[0197] code: ErrorCodeEnum.VALIDATE_ERROR.code,
[0198] msg: BindException.errorField.msg
[0199] }
[0200] }
[0201] }
[0202] Calling the interface and interface response:
[0203] / api / test1 {PhoneNo: “12345678911”} => {code:99999,msg: “Username is empty”}
[0204] / api / test1 {Username: “张三”,PhoneNo: “123”} => {code:99999,msg: “The length of the phone number is incorrect”}
[0205] / api / test2 {Username: “张三”} => {code:99999,msg: “The length of the VIN is incorrect”}
[0206] Compared with Comparison Plan 2, Comparison Plan 3 does not need to return an error in every interface method. Other than that, it is the same as Comparison Plan 2.
[0207] However, in the embodiment of the present application, a corresponding error code can be added to each verification error message in the returned verification result, rather than a unified error code.
[0208] Scheme 4: Example of this application
[0209] Request Object:
[0210] RequestBean1{
[0211] @NotNull (msg = “USERNAME_NULL”)
[0212] Username;
[0213] @NotNull (msg = “PHONE_NO_NULL”)
[0214] @Length (min=11, max = 11, msg = “PHONE_NO_WRONG_LENGTH”)
[0215] PhoneNo;
[0216] }
[0217] RequestBean2{
[0218] @NotNull (msg = “USERNAME_NULL”)
[0219] Username;
[0220] @NotNull (msg = “VIN_NULL”)
[0221] @Length (min = 17, max = 17, msg = "VIN_WRONG_LENGTH")
[0222] Vin;
[0223] }
[0224] Interface 1: / api / test1
[0225] test1(@Valid ReuqsetBean1);
[0226] Interface 2: / api / test2
[0227] test2(@Valid RequestBean2);
[0228] WholeExceptionProcessor {
[0229] doException (BindException) {
[0230] return ErrorCodeEnum.find(BindException.errorField.msg);
[0231] }
[0232] }
[0233] Calling interface and interface response:
[0234] / api / test1 {PhoneNo:“12345678911”} => {code:10001,msg:“Username is empty”}
[0235] / api / test1 {Username:"Zhang San",PhoneNo:"123"} => {code:10003,msg:"The phone number length is incorrect"}
[0236] / api / test2 {Username: "Zhang San"} => {code:10003,msg:"VIN length is incorrect"}
[0237] This application returns the error code corresponding to each field that fails verification and is decoupled from the business code. When the interface and field are changed, the code writing workload is small as long as the verification rules and verification annotation msg are bound to the error enumeration name.
[0238] Compared with the prior art, the parameter verification result generation method of the embodiment of the present application, when the request is verified based on the MVC verification framework and the verification result includes a verification error message, finds the corresponding target error code enumeration according to the verification error message and the preset error code enumeration list, and then returns the requested error code and verification error message to the client according to the target error code enumeration. By binding the verification rules with the error code and error message, the verification result is decoupled from the business coding. Not only can the corresponding error code and verification error message be output for the verification error of each field of each interface, thereby enhancing the availability of the verification result, but also there is no need for hard coding and error code judgment, thereby reducing the workload of coding and maintenance.
[0239] The second embodiment of the present application provides a parameter verification result generation device, which is configured on a verification platform, i.e., the cloud. As shown in FIG3 , the parameter verification result generation device 300 includes: a request receiving module 302 , a verification module 304 , a verification error finding module 306 , and a verification result returning module 308 .
[0240] The request receiving module 302 is used to receive a request from a client to call a cloud application programming interface (API).
[0241] The verification module 304 is used to verify the request based on the MVC verification framework and obtain a verification result.
[0242] The verification error search module 306 is used to find the corresponding target error code enumeration based on the verification error message and a preset error code enumeration list when the verification result of the verification module includes a verification error message. Each error code enumeration in the error code enumeration list includes: an error code and a verification error message corresponding to the error code.
[0243] The verification result returning module 308 is used to return the requested error code and verification error message to the client according to the target error code enumeration.
[0244] Optionally, the MVC validation framework may be a Spring MVC validation framework, which includes a Request Mapping module, a Spring Validation module, a global exception handler, a Request Bean module, and an error code enumeration module. The validation result includes a validation pass and / or a validation error message.
[0245] The verification module includes: a request object parsing submodule, the Request Mapping module obtains the request object of the request through the Request Bean module according to the request path; a parameter extraction submodule, the Request Bean module obtains the model of the request object according to the request object and returns it to the Request Mapping module, the Request Mapping module obtains the verification parameters of the model according to the request object and sends them to the Spring Validation module; a Spring verification submodule, the Spring Validation module verifies according to the verification parameters of the request object model, and throws a verification exception message if the verification is abnormal; a verification error message capture submodule, the global exception handler captures the verification exception information and extracts the verification error message of the request.
[0246] The verification error search module 306 includes: an error code enumeration module that receives the verification error message of the request sent by the global exception handler, and searches the error code enumeration list according to the verification error message to obtain the target error code enumeration.
[0247] Optionally, the Spring MVC validation framework also includes a Request Body Advice module. The validation result return module 308 includes: an error code enumeration module that sends a target error code enumeration to the Request Body Advice module via the global exception handler and the API interface module; the Request Body Advice module that obtains the request error code and validation error message based on the target error code enumeration and sends them to the API interface module; and the API interface module that returns the request error code and validation error message to the client.
[0248] Optionally, the verification result return module 308 includes: after the Spring Validation module verifies the request parameters, it sends a verification pass message to the Request Mapping module, the API interface module and the Request Body Advice module in sequence; the Request Body Advice module assembles a request verification success message and sends it to the API interface module; the API interface module returns the request verification success message to the client.
[0249] Compared with the prior art, the parameter verification result generating device of the embodiment of the present application is different from the prior art in that when the request is verified based on the MVC verification framework and the verification result includes a verification error message, the corresponding target error code enumeration is found according to the verification error message and the preset error code enumeration list, and then the requested error code and verification error message are returned to the client according to the target error code enumeration. By binding the verification rules with the error code and error message, the verification result is decoupled from the business coding. Not only can the corresponding error code and verification error message be output for the verification error of each field of each interface, thereby enhancing the availability of the verification result, but also the need for hard coding and error code judgment is eliminated, thereby reducing the workload of coding and maintenance.
[0250] The parameter verification result generation device provided in this embodiment can execute the parameter verification result generation method provided in the above method embodiment, and has the corresponding functional modules and beneficial effects of the execution method. The implementation principle and technical effects of this embodiment are similar to those of the above method embodiment, and will not be repeated here.
[0251] Figure 4 is a schematic diagram of the structure of the verification platform provided in Example 3 of the present application. The verification platform 40 includes a memory 41, a processor 42, and a computer program stored in the memory 41 and executable on the processor 42. When the processor 42 executes the program, the technical solution described in Example 1 above is implemented.
[0252] Embodiment 4 of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a computer processor, the computer program is used to execute the technical solution of any method embodiment.
[0253] Through the above description of the implementation methods, those skilled in the art can clearly understand that the present application can be implemented with the help of software and necessary general-purpose hardware, and of course it can also be implemented with hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the existing technology, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or grid device, etc.) to execute the methods described in each embodiment of the present application.
[0254] It is worth noting that in the embodiments of the above-mentioned device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application.
[0255] Note that the above are only preferred embodiments of the present application and the technical principles employed. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application has been described in more detail through the above embodiments, the present application is not limited to the above embodiments and may include many other equivalent embodiments without departing from the scope of the present application. The scope of the present application is determined by the scope of the appended claims. Sequence Listing Free Content
[0256] This application does not involve a sequence listing.
Claims
1. A method for generating parameter verification results, characterized in that including: Receiving a request from a client to call a cloud application programming interface (API); Validating the request based on an MVC validation framework and obtaining a validation result; When the validation result contains a validation error message, finding a corresponding target error code enumeration according to the validation error message and a preset error code enumeration list; wherein, each error code enumeration in the error code enumeration list includes: an error code and the validation error message corresponding to the error code; Returning the error code and the validation error message of the request to the client according to the target error code enumeration; The MVC validation framework is a Spring MVC validation framework, and the Spring MVC validation framework includes: a Request Mapping module, a Spring Validation module, a global exception handler, a Request Bean module, and an error code enumeration module; The validating the request based on the MVC validation framework and obtaining a validation result includes: The Request Mapping module obtains a request object of the request through the Request Bean module according to a request path; The Request Bean module obtains a model of the request object based on the request object and returns it to the Request Mapping module, and the Request Mapping module sends validation parameters of the model to the Spring Validation module according to the model of the request object; The Spring Validation module validates according to the validation parameters of the model of the request object, and throws a validation exception message if a validation exception occurs; The global exception handler extracts the validation error message of the request after capturing the validation exception message.
2. The method for generating a parameter verification result according to claim 1, wherein The finding a corresponding target error code enumeration according to the validation error message and the preset error code enumeration list includes: The error code enumeration module receives the validation error message of the request sent by the global exception handler, and finds the target error code enumeration according to the validation error message in the error code enumeration list.
3. The method for generating a parameter verification result according to claim 2, wherein The Spring MVC validation framework further includes: a Request Body Advice module; the returning the error code and the validation error message of the request to the client according to the target error code enumeration includes: The error code enumeration module sequentially sends the target error code enumeration to the Request Body Advice module through the global exception handler and the API interface module; The Request Body Advice module obtains the error code and the validation error message of the request according to the target error code enumeration and sends them to the API interface module; The API interface module returns the error code and the validation error message of the request to the client.
4. The method for generating a parameter verification result according to claim 3, wherein The method further includes: After the parameter verification of the request by the Spring Validation module, a verification passed message is successively sent to the Request Mapping module, the API interface module, and the Request Body Advice module; After the Request Body Advice module assembles a request verification success message, it sends the message to the API interface module; The API interface module returns the request verification success message to the client.
5. A parameter verification result generation device, characterized in that, It includes: A request receiving module for receiving a request from a client to call a cloud application programming interface (API); A verification module for verifying the request based on the MVC verification framework and obtaining a verification result; A verification error finding module for, when the verification result of the verification module contains a verification error message, finding a corresponding target error code enumeration according to the verification error message and a preset error code enumeration list; each error code enumeration in the error code enumeration list includes: an error code and the verification error message corresponding to the error code; A verification result returning module for returning the error code of the request and the verification error message to the client according to the target error code enumeration; The MVC verification framework is the Spring MVC verification framework, and the Spring MVC verification framework includes: a Request Mapping module, a Spring Validation module, a global exception handler, a Request Bean module, and an error code enumeration module; The verification module includes: A request object parsing sub-module, and the Request Mapping module obtains the request object of the request through the Request Bean module according to the request path; A parameter extraction sub-module, the Request Bean module obtains the model of the request object according to the request object and returns it to the Request Mapping module, and the Request Mapping module obtains the verification parameters of the model according to the model of the request object and sends them to the Spring Validation module; A Spring verification sub-module, and the Spring Validation module verifies according to the verification parameters of the model of the request object. If a verification exception occurs, a verification exception message is thrown; A verification error message capturing sub-module, and the global exception handler extracts the verification error message of the request after capturing the verification exception message.
6. The apparatus for generating a parameter verification result according to claim 5, wherein The verification error finding module includes: the error code enumeration module receives the verification error message of the request sent by the global exception handler, and finds the target error code enumeration according to the verification error message in the error code enumeration list.
7. The parameter verification result generation device according to claim 6, wherein The Spring MVC verification framework further includes: a Request Body Advice module; The verification result return module includes: the error code enumeration module sequentially sends the target error code enumeration to the Request Body Advice module through the global exception handler and the API interface module; The Request Body Advice module obtains the error code of the request and the verification error message according to the target error code enumeration and sends them to the API interface module; The API interface module returns the error code of the request and the verification error message to the client.
8. The parameter verification result generation device according to claim 7, characterized in that The verification result return module further includes: after the Spring Validation module passes the parameter verification of the request, it sequentially sends a verification passed message to the Request Mapping module, the API interface module, and the Request Body Advice module; The Request Body Advice module assembles a request verification success message and sends it to the API interface module; The API interface module returns the request verification success message to the client.
9. A verification platform, characterized in that, It includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the parameter verification result generation method according to any one of claims 1-4.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the parameter verification result generation method according to any one of claims 1-4.
Citation Information
Patent Citations
Exception prompting method, device and system for big data product, equipment and medium
CN110347560A
Service request processing method and device, storage medium and electronic equipment
CN113127108A
Business processing system and abnormal data processing method based on business processing system
CN113837584A
Data verification method and device, storage medium and electronic equipment
CN115061851A
Parameter verification result generation method and device, verification platform and storage medium
CN117556809A