Parameter verification method and device, storage medium, and service terminal

By obtaining and verifying the parameters of the called interface, combined with proxy classes and aspect logic, the problem of complexity of interface data verification is solved, convenience and efficiency are improved, and it is suitable for verification scenarios of multiple interfaces.

CN112650488BActive Publication Date: 2024-10-22上海际链网络科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910967122.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-10-12
Publication Date
2024-10-22
Estimated Expiration
2039-10-12

AI Technical Summary

Technical Problem

In the existing technology, the interface itself needs to write complex code to call the data verification logic, which leads to the complexity of data verification and lack of convenience, especially in the case of multiple called interfaces.

Method used

By obtaining the parameters of the called interface, calling the data verification logic for verification, and deciding whether to execute the interface's business logic based on the verification results, using proxy classes and aspect logic to simplify the verification process, for example, through Hibernate-validator and Spring AOP. Unified data verification.

Benefits of technology

It realizes convenient verification of interface parameters, avoids the use of complex codes for data verification on the interface itself, simplifies the development process, and supports the reuse of multiple interfaces, improving development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112650488B_ABST
    Figure CN112650488B_ABST
Patent Text Reader

Abstract

A parameter verification method and device, a storage medium, and a service terminal, wherein the parameter verification method comprises: obtaining the parameters of the called interface; calling data verification logic to perform data verification on the parameters to obtain a verification result; and determining whether to execute the business logic of the called interface according to the verification result. The technical solution of the present invention can realize the convenience of interface data verification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a parameter verification method and device, a storage medium, and a service terminal. Background Art

[0002] Hibernate-validator provides data validation function. When each interface needs to use the data validation function, the interface itself needs to call the validation logic of Hibernate-validator. In other words, each interface needs to write code to implement the validation logic.

[0003] However, when the interface itself calls the verification logic, the code is complex, which makes the implementation of the interface when performing data verification also more complicated. Summary of the invention

[0004] The technical problem solved by the present invention is how to realize the convenience of interface data verification.

[0005] To solve the above technical problems, an embodiment of the present invention provides a parameter verification method, which includes: obtaining parameters of a called interface; calling data verification logic to perform data verification on the parameters to obtain a verification result; and determining whether to execute the business logic of the called interface based on the verification result.

[0006] Optionally, after obtaining the parameters of the called interface, the method includes: obtaining annotations of the called interface, the annotations indicating restrictions on the parameters; and calling data verification logic to perform data verification on the parameters includes: calling data verification logic to perform data verification on the parameters using the restrictions.

[0007] Optionally, determining whether to execute the business logic of the called interface based on the verification result includes: if the verification result indicates that the verification passes, executing the business logic of the called interface; if the verification result indicates that the verification fails, returning verification error information.

[0008] Optionally, calling data verification logic to perform data verification on the parameters includes: generating a proxy class, the proxy class calling aspect logic, and the aspect logic can call data verification logic to perform data verification on the parameters.

[0009] Optionally, the generating the proxy class includes: generating the proxy class according to the proxy class generating annotation in the called interface.

[0010] Optionally, the proxy class generates an annotation of @RestController in the spring framework.

[0011] Optionally, calling data verification logic to perform data verification on the parameters includes: calling data verification logic of Hibernate-validator to perform data verification on the parameters.

[0012] To solve the above technical problems, an embodiment of the present invention further discloses a parameter verification device, which includes: a parameter acquisition module, used to obtain the parameters of the called interface; a verification module, used to call data verification logic to perform data verification on the parameters to obtain a verification result; and an execution module, used to determine whether to execute the business logic of the called interface according to the verification result.

[0013] The embodiment of the present invention further discloses a storage medium on which computer instructions are stored. When the computer instructions are executed, the steps of any one of the parameter verification methods are executed.

[0014] The embodiment of the present invention further discloses a service terminal, including a memory and a processor, wherein the memory stores computer instructions that can be executed on the processor, and the processor executes the steps of the parameter verification method when executing the computer instructions.

[0015] Compared with the prior art, the technical solution of the embodiment of the present invention has the following beneficial effects:

[0016] In the technical solution of the present invention, the parameters of the called interface are obtained; the data verification logic is called to perform data verification on the parameters to obtain the verification result; and it is determined whether to execute the business logic of the called interface according to the verification result. The technical solution of the present invention avoids the use of complex codes to implement data verification in the interface itself by performing data verification before the business logic of the called interface is executed, and determines whether to execute the business logic of the called interface according to the result of the data verification, thereby achieving the convenience of interface parameter verification. In addition, in the case where there are multiple called interfaces, the parameter verification of multiple called interfaces can be achieved through the solution of the present invention (for example, by reusing a section of code), further ensuring the convenience of interface parameter verification.

[0017] Furthermore, calling the data verification logic to perform data verification on the parameters includes: generating a proxy class, the proxy class calling the aspect logic, and the aspect logic can call the data verification logic to perform data verification on the parameters. The technical solution of the present invention combines aspect logic, such as Spring AOP, to achieve unified call verification of all interfaces through aspects, and only needs to add corresponding annotations on the interfaces, which simplifies development and improves development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 is a flow chart of a parameter verification method according to an embodiment of the present invention;

[0019] Figure 2 is a flow chart of another parameter verification method according to an embodiment of the present invention;

[0020] Figure 3 It is a structural schematic diagram of a parameter verification device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0021] As described in the background art, when the interface itself calls the verification logic, the code is complex, which makes the implementation of the interface when performing data verification also complex.

[0022] The technical solution of the present invention performs data verification before the business logic of the called interface is executed, and determines whether to execute the business logic of the called interface according to the result of the data verification, thereby avoiding the interface itself from using complex code to implement data verification, and realizing the convenience of interface parameter verification. In addition, in the case where there are multiple called interfaces, the parameter verification of multiple called interfaces can be realized through the solution of the present invention (for example, by reusing a piece of code), further ensuring the convenience of interface parameter verification.

[0023] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0024] Figure 1 The present invention is a flowchart of a parameter verification method according to an embodiment of the present invention.

[0025] The parameter verification method of the embodiment of the present invention can be used in a service terminal, wherein the service terminal may include one or more service-providing interfaces. Figure 1 The individual steps of the method are shown.

[0026] Figure 1 The parameter verification method shown may include the following steps:

[0027] Step S101: Obtaining parameters of the called interface;

[0028] Step S102: calling data verification logic to perform data verification on the parameters to obtain verification results;

[0029] Step S103: Determine whether to execute the business logic of the called interface according to the verification result.

[0030] It should be pointed out that the serial numbers of the steps in this embodiment do not limit the execution order of the steps.

[0031] In this embodiment, a terminal requiring service, such as a client, can call an interface of a service terminal, and the interface called by the client can be called a called interface. The called interface can provide services to the client that calls the interface, such as providing services to the client through output parameters.

[0032] In this embodiment, each step of the above parameter verification method can be implemented by executing a piece of computer code.

[0033] In the specific implementation of step S101, the parameters of the called interface may be obtained. The parameters may be the parameters output by the called interface, and may specifically include parameter names and parameter values.

[0034] In the specific implementation of step S102, the data verification logic can be called to perform data verification on the parameters. The verification result can include verification passing or verification failing. Specifically, the data verification logic can be pre-set. The data verification logic can be implemented using a piece of computer code.

[0035] It should be noted that the specific implementation process of implementing data verification by the data verification logic can be set according to actual business requirements, and the embodiment of the present invention does not limit this.

[0036] In a specific embodiment, the data verification of the parameters may be performed by calling the data verification logic of Hibernate-validator.

[0037] In the specific implementation of step S102, it can be determined whether to execute the business logic of the called interface according to the verification result. Specifically, when determining to execute the business logic of the called interface, the business logic of the called interface can be executed by calling the interface class of the called interface.

[0038] The embodiment of the present invention performs data verification before the business logic of the called interface is executed, and determines whether to execute the business logic of the called interface according to the result of the data verification, thereby avoiding the interface itself from using complex code to implement data verification, and realizing the convenience of interface parameter verification. In addition, in the case where there are multiple called interfaces, the parameter verification of multiple called interfaces can be realized through the scheme of the present invention (for example, by reusing a piece of code), further ensuring the convenience of interface parameter verification.

[0039] In a non-limiting embodiment of the present invention, please refer to Figure 2 , after step S101, the following steps may also be included:

[0040] Step S201: Obtain the annotation of the called interface, where the annotation indicates the restriction condition of the parameter.

[0041] In a specific implementation, the annotation of the called interface can be obtained to obtain the restriction conditions of the parameters in the business logic of the called interface. Since the interface itself can know the annotation of the called interface when executing its business logic, but the caller of the called interface cannot call the annotation of the called interface, it is necessary to obtain the annotation of the called interface by executing step S201.

[0042] In a specific application scenario, for the following code:

[0043]

[0044] Among them, @NotNull and @Min(2) represent annotations of the interface (that is, the called interface). The annotations @NotNull and @Min(2) respectively represent constraint 1: the parameter manufacturer cannot be null, and constraint 2: the minimum value of the parameter seatCount is 2.

[0045] It should be noted that the annotations on the parameters and the restrictive conditions they represent may be in any feasible form, and the embodiments of the present invention do not impose any limitation on this.

[0046] Figure 1 The step S102 shown may include the following steps:

[0047] Step S202: calling data verification logic to perform data verification on the parameters using the restriction conditions.

[0048] In specific implementation, the restriction condition will be involved in the process of data verification of the parameter. That is to say, when verifying the parameter, the data verification logic can determine whether the parameter meets the restriction condition. For example, whether the value of the parameter is empty, whether the value of the parameter is greater than 2, etc.

[0049] In a specific application scenario, the data validation logic can be Hibernate-validator.

[0050] In a non-limiting embodiment, Figure 1 Step S103 may include the following steps:

[0051] If the verification result indicates that the verification is passed, the business logic of the called interface is executed; if the verification result indicates that the verification is not passed, verification error information is returned.

[0052] In this embodiment, if the verification result indicates that the verification is passed, it means that the parameters of the interface to be called have passed the data verification, and then the business logic of the called interface can continue to be executed. Specifically, the logic in the interface class can be executed by calling the interface class of the called interface.

[0053] On the contrary, if the verification result indicates that the verification has not passed, it means that the parameters of the interface to be called have not passed the data verification, and the verification error information can be returned to the caller, for example, the verification result can be returned to the caller to prompt the caller that the parameters of the called interface have errors in the verification process. In this case, the business logic of the called interface will not be executed, that is, the interface class of the called interface will not be called further.

[0054] In a non-limiting embodiment, Figure 1 The step S102 shown may include the following steps: generating a proxy class, the proxy class calling aspect logic, and the aspect logic being able to call data verification logic to perform data verification on the parameters.

[0055] In this embodiment, the proxy class can call the aspect logic, and the aspect logic can call the data verification logic to perform data verification on the parameters. The aspect logic can be executed before the business logic of the called interface.

[0056] Furthermore, the proxy class is generated according to the proxy class generation annotation in the called interface.

[0057] In this embodiment, an annotation may be added to the called interface, that is, a proxy class generation annotation, and the proxy class generation annotation may trigger generation of a proxy class.

[0058] Furthermore, the proxy class generates an annotation of @RestController in the spring framework.

[0059] That is to say, if there is a proxy class generation annotation @RestController in the called interface, spring generates a proxy class based on the annotation. The proxy class can call the aspect logic before calling the business logic of the interface class.

[0060] Please refer to Figure 3 The embodiment of the present invention further discloses a parameter verification device 30 , which may include a parameter acquisition module 301 , a verification module 302 and an execution module 303 .

[0061] Among them, the parameter acquisition module 301 is used to obtain the parameters of the called interface; the verification module 302 is used to call the data verification logic to perform data verification on the parameters to obtain the verification result; the execution module 303 is used to determine whether to execute the business logic of the called interface according to the verification result.

[0062] The embodiment of the present invention performs data verification before the business logic of the called interface is executed, and determines whether to execute the business logic of the called interface according to the result of the data verification, thereby avoiding the interface itself from using complex code to implement data verification, and realizing the convenience of interface parameter verification. In addition, in the case where there are multiple called interfaces, the parameter verification of multiple called interfaces can be realized through the scheme of the present invention (for example, by reusing a piece of code), further ensuring the convenience of interface parameter verification.

[0063] In a non-limiting embodiment of the present invention, Figure 3 The parameter checking device 30 shown may also include an annotation acquisition module (not shown) for acquiring annotations of the called interface, wherein the annotations represent restriction conditions of the parameters.

[0064] Further, Figure 3 The verification module 302 shown may call data verification logic to perform data verification on the parameters using the restriction conditions.

[0065] In a non-limiting embodiment of the present invention, Figure 3 The execution module 303 shown executes the business logic of the called interface when the verification result indicates that the verification has passed; the execution module 303 returns verification error information when the verification result indicates that the verification has not passed.

[0066] In a non-limiting embodiment of the present invention, Figure 3 The verification module 302 shown may include a proxy class generation unit (not shown) for generating a proxy class, wherein the proxy class calls the aspect logic, and the aspect logic can call the data verification logic to perform data verification on the parameters.

[0067] Furthermore, the proxy class generation unit generates the proxy class according to the proxy class generation annotation in the called interface.

[0068] Furthermore, the proxy class generates an annotation of @RestController in the spring framework.

[0069] Further, Figure 3 The verification module 302 shown may call the data verification logic of Hibernate-validator to perform data verification on the parameters.

[0070] For more information about the working principle and working method of the parameter verification device 30, please refer to Figure 1 to Figure 2 The relevant description in will not be repeated here.

[0071] The embodiment of the present invention also discloses a storage medium, which is a computer-readable storage medium and stores computer instructions. When the computer instructions are executed, Figure 1 or Figure 2 The steps of the parameter verification method shown in . The storage medium may include ROM, RAM, magnetic disk or optical disk, etc. The storage medium may also include non-volatile memory (non-volatile) or non-transitory memory, etc.

[0072] The embodiment of the present invention also discloses a service terminal, which may include a memory and a processor, wherein the memory stores computer instructions that can be run on the processor. When the processor runs the computer instructions, it can execute Figure 1 or Figure 2 The steps of the parameter verification method shown in . The service terminal includes but is not limited to mobile phones, computers, tablet computers and other terminal devices.

[0073] Although the present invention is disclosed as above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the scope defined by the claims.

Claims

1. A parameter verification method, It is characterized in that include: Get the parameters of the called interface; Calling data verification logic to perform data verification on the parameters to obtain a verification result; Determine whether to execute the business logic of the called interface according to the verification result; The method of obtaining the parameters of the called interface includes: Obtaining an annotation of the called interface, wherein the annotation indicates a restriction condition of the parameter; The calling of data verification logic to perform data verification on the parameter includes: Generate a proxy class, the proxy class calls the aspect logic, the aspect logic can call the data verification logic to perform data verification on the parameters using the restriction conditions, wherein the proxy class is generated according to the proxy class generation annotation in the called interface.

2. The parameter verification method according to claim 1, It is characterized in that Determining whether to execute the business logic of the called interface according to the verification result includes: If the verification result indicates that the verification is passed, the business logic of the called interface is executed; If the verification result indicates that the verification fails, a verification error message is returned.

3. The parameter verification method according to claim 1, It is characterized in that The proxy class generates an annotation of @RestController in the spring framework.

4. The parameter verification method according to claim 1, It is characterized in that The calling of data verification logic to perform data verification on the parameter includes: The data validation logic of Hibernate-validator is called to perform data validation on the parameters.

5. A parameter verification device, It is characterized in that include: Parameter acquisition module, used to obtain the parameters of the called interface; An annotation acquisition module, used to acquire the annotation of the called interface, wherein the annotation indicates the restriction condition of the parameter; A verification module, used to call the data verification logic to perform data verification on the parameters to obtain a verification result; An execution module, used to determine whether to execute the business logic of the called interface according to the verification result; The verification module generates a proxy class, and the proxy class calls the aspect logic. The aspect logic can call the data verification logic to perform data verification on the parameters using the restriction conditions, wherein the proxy class is generated according to the proxy class generation annotation in the called interface.

6. A storage medium having computer instructions stored thereon, It is characterized in that When the computer instructions are executed, the steps of the parameter verification method according to any one of claims 1 to 4 are executed.

7. A service terminal, comprising a memory and a processor, wherein the memory stores computer instructions that can be executed on the processor, It is characterized in that When the processor runs the computer instructions, the steps of the parameter verification method according to any one of claims 1 to 4 are performed.