Method and device for verifying code
By analyzing the annotations of the business code, obtaining the verification strategy, and calling the corresponding verification code for verification, solving the problem of coupling between the verification code and the business code, improving the flexibility and maintainability of the verification code, and reducing development costs.
Patent Information
- Application Number
- CN202111053416.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-09
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2041-09-09
AI Technical Summary
In the prior art, coupling of verification code and business code leads to poor flexibility and poor reusability, which increases development costs and time costs and reduces development efficiency.
By obtaining the annotations of the business code, analyzing the verification strategy from the annotations, and using the analytical verification strategy to verify the business code to verify the verification code, realizing the decoupling of the verification code and the business code.
It improves the flexibility and maintainability of verification codes, reduces the labor and time costs of development, and improves development efficiency.
Smart Images

Figure CN113742235B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for verifying a code. Background Art
[0002] With the popularization of Internet applications, the functions of Internet applications are becoming more and more abundant, so the development complexity of Internet applications is becoming higher and higher. Usually, the code used to develop Internet applications needs to be verified in different ways, such as the validity of parameters and the logical validity of business logic data.
[0003] Currently, the method for code verification is usually: for each business code segment that needs to be verified, verification code is added for verification to realize the verification of each code segment. Since this method couples the verification code for verification with the business code, it causes problems such as poor flexibility, poor reusability, and poor maintainability of the verification code. It also increases the manpower and time costs of development and reduces development efficiency. Summary of the Invention
[0004] In view of this, an embodiment of the present invention provides a method and device for verifying code, which can obtain the annotations of the business code, parse the verification strategy for the code from the annotations, and call the corresponding verification code through the verification strategy to perform verification on the business code; overcome the problem of coupling between the verification code and the business code, thereby overcoming the problems of poor flexibility and reusability of the verification code; improve the maintainability of the verification code; and improve development efficiency by reducing the labor cost and time cost of development.
[0005] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a method for verifying code is provided, which is characterized in that it includes: obtaining the annotation corresponding to the business code, parsing the annotation type from the annotation, and obtaining the verification strategy associated with the annotation type from the annotation; among the preset multiple verification codes, searching for a first verification code that matches the verification strategy, and calling the first verification code to verify the business code.
[0006] Optionally, the code verification method is characterized in that:
[0007] The annotation types include: method annotations and / or parameter annotations.
[0008] Optionally, the method for verifying the code is characterized in that the annotation type is parsed from the annotation, and the verification strategy associated with the annotation type is obtained from the annotation, including: the annotation type is the method annotation, and in response to a call instruction of any business method in the business code, the call instruction is intercepted; the method annotation of the business method corresponding to the call instruction is determined; and the verification strategy corresponding to the method annotation is obtained from the method annotation.
[0009] Optionally, the method for verifying the code is characterized in that parsing the annotation type from the annotation includes: the annotation type is the parameter annotation, determining the input parameter field corresponding to the parameter annotation, and obtaining the parameter value corresponding to the input parameter field.
[0010] Optionally, the method for verifying the code is characterized in that it further includes: in response to the existence of multiple verification rules in the verification strategy, the first verification code includes a priority order for executing the verification rules; using the first verification code to perform verification on the business code includes: based on the priority order, sequentially calling the second verification code corresponding to the verification rule to verify the business code.
[0011] Optionally, the code verification method is characterized in that:
[0012] The first verification code has a corresponding verification context; further comprising: storing the data to be verified included in the business code into the verification context; and using the verification context to share the data to be verified for multiple second verification codes.
[0013] Optionally, the code verification method is characterized in that:
[0014] The first verification code includes a verification annotation; the verification annotation includes verification rule identifiers corresponding to multiple verification rules; further including: matching each verification rule identifier included in the verification strategy with the multiple verification rule identifiers included in the verification annotation; according to the matching result, executing the step of sequentially calling the second verification code corresponding to the verification rule to verify the business code.
[0015] To achieve the above-mentioned purpose, according to a second aspect of an embodiment of the present invention, a device for verifying code is provided, characterized in that it comprises: an annotation parsing module and a code verification module; wherein,
[0016] The annotation parsing module is used to obtain the annotation corresponding to the business code, parse the annotation type from the annotation, and obtain the verification strategy associated with the annotation type from the annotation;
[0017] The verification code module is used to search for a first verification code that matches the verification strategy among a plurality of preset verification codes, and call the first verification code to verify the business code.
[0018] Optionally, the device for verifying the code is characterized in that:
[0019] The annotation types include: method annotations and / or parameter annotations.
[0020] Optionally, the device for verifying the code is characterized in that the annotation type is parsed from the annotation, and the verification strategy associated with the annotation type is obtained from the annotation, including: the annotation type is the method annotation, and in response to a call instruction of any business method in the business code, the call instruction is intercepted; the method annotation of the business method corresponding to the call instruction is determined; and the verification strategy corresponding to the method annotation is obtained from the method annotation.
[0021] Optionally, the device for verifying the code is characterized in that parsing the annotation type from the annotation further includes: the annotation type is the parameter annotation, determining the input parameter field corresponding to the parameter annotation, and obtaining the parameter value corresponding to the input parameter field.
[0022] Optionally, the device for verifying the code is characterized in that it further includes: in response to the existence of multiple verification rules in the verification strategy, the first verification code includes a priority order for executing the verification rules; using the first verification code to perform verification on the business code includes: based on the priority order, sequentially calling the second verification code corresponding to the verification rule to verify the business code.
[0023] Optionally, the device for verifying the code is characterized in that:
[0024] The first verification code has a corresponding verification context; further comprising: storing the data to be verified included in the business code into the verification context; and using the verification context to share the data to be verified for multiple second verification codes.
[0025] Optionally, the device for verifying the code is characterized in that:
[0026] The first verification code includes a verification annotation; the verification annotation includes verification rule identifiers corresponding to multiple verification rules; further including: matching each verification rule identifier included in the verification strategy with the multiple verification rule identifiers included in the verification annotation; according to the matching result, executing the step of sequentially calling the second verification code corresponding to the verification rule to verify the business code.
[0027] To achieve the above-mentioned purpose, according to the third aspect of an embodiment of the present invention, there is provided an electronic device for verifying a code, characterized in that it includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement any of the methods described in the above-mentioned methods for verifying a code.
[0028] To achieve the above-mentioned purpose, according to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, characterized in that when the program is executed by a processor, any method as described in the above-mentioned code verification method is implemented.
[0029] An embodiment of the above invention has the following advantages or beneficial effects: it can obtain the annotations of the business code, parse the verification strategy for the code from the annotations, and call the corresponding verification code through the verification strategy to perform verification of the business code; it overcomes the problem of coupling between the verification code and the business code, thereby overcoming the problem of poor flexibility and reusability of the verification code; it improves the maintainability of the verification code; and it improves development efficiency by reducing the manpower and time costs of development.
[0030] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The accompanying drawings are provided for a better understanding of the present invention and are not intended to limit the present invention.
[0032] Figure 1 1 is a flow chart of a code verification method provided by one embodiment of the present invention;
[0033] Figure 2 This is a schematic diagram of a code verification process provided by an embodiment of the present invention;
[0034] Figure 3 1 is a schematic structural diagram of a code verification device provided by one embodiment of the present invention;
[0035] Figure 4 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
[0036] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0037] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0038] In view of this, if Figure 1 As shown, an embodiment of the present invention provides a method for verifying a code, which may include the following steps:
[0039] Step S101: Obtain the annotation corresponding to the business code, parse the annotation type from the annotation, and obtain the verification strategy associated with the annotation type from the annotation.
[0040] Specifically, the business code is the source code for implementing the application; for example, if the application is an e-commerce mall, each page, business logic, and function of the e-commerce mall can be implemented through the business code.
[0041] The annotations corresponding to the business code are added for business code verification. The annotations are usually added to the business code segment. The annotations are usually identified by "@". The annotations corresponding to the business code can be obtained by searching for the character "@" and the associated string as the keyword to obtain the annotation; for example, "@validation" is used to indicate the business code that requires code verification; depending on the verification type and verification strategy, there can be one or more annotations; wherein, the annotation includes a predefined annotation type and a verification strategy used to verify the business code, wherein the verification strategy is set based on the annotation type; that is, the annotation type can be parsed from the annotation, and the verification strategy associated with the annotation type can be obtained from the annotation.
[0042] Furthermore, annotation types include method annotations and / or parameter annotations. Method annotation types are added to methods (e.g., functions) contained in business code. For example, @UserServiceValid is used to identify method annotation types; the annotation type is determined to be a method annotation by parsing the "@UserServiceValid" keyword from the code; @UserFieldValid is used to identify parameter annotations; the annotation type is determined to be a parameter annotation by parsing the "@UserFieldValid" keyword from the code.
[0043] Furthermore, the verification strategy associated with the annotation type is obtained from the annotation. It is understandable that the verification strategies adopted for different annotation types are different. For example, for parameter annotations, the verification strategy associated with the parameter annotation corresponds to the validity of the verification parameters, such as parameter value non-empty verification, parameter value format verification, parameter value maximum and minimum values, etc.; for method annotations, the verification strategy associated with the method annotation is related to the actual business according to the application scenario. For example, if the business method is an order call interface, the corresponding verification strategy is to verify whether the order number is legal and whether the inventory of the order product is non-zero.
[0044] The verification strategy is part of the annotation, for example: the business code segment contains the parameter annotation @UserFieldValid, and contains one or more verification strategies corresponding to the parameter, such as: @rule_empty (indicating the verification strategy for judging whether the parameter is empty), @rule_length (indicating whether the verification strategy for judging whether the parameter length is legal), etc.; the annotation can also be set to contain a type field for the verification strategy, and a field value indicating the verification strategy corresponding to the type field to identify the specific type of verification strategy used; it is understandable that the business code segment can contain any one or two of parameter annotations and method annotations, as well as verification strategies corresponding to parameter annotations and method annotations. Method annotations, parameter annotations, and verification strategies can be custom annotations. The present invention does not limit the annotation content contained in the business code, or the specific form and content of the method annotations, parameter annotations, and verification strategies contained in the annotations.
[0045] Furthermore, there are two ways to obtain (parse) the verification strategy associated with the annotation type from the annotation:
[0046] The first method: the annotation type is the method annotation, and in response to the call instruction of any business method in the business code, the call instruction is intercepted; the method annotation of the business method corresponding to the call instruction is determined; and the verification strategy corresponding to the method annotation is parsed (obtained) from the method annotation. Specifically, the call instruction can be intercepted using AOP (Aspect Oriented Programming) technology. The request or call of any business method in the business code is a call instruction. Before the call or request is processed, it is intercepted (i.e., the call instruction is intercepted) and the parameters contained in the business method and the verification strategy used for the business method are parsed (i.e., the method annotation of the business method corresponding to the call instruction is determined), thereby decoupling the verification code from the code logic of the business method. It can be seen that the flexibility and reusability of the verification code are improved by setting annotations.
[0047] The second method: the annotation type is the parameter annotation, the input parameter field corresponding to the parameter annotation is determined, and the parameter value corresponding to the input parameter field is obtained. Specifically, in the case where the annotation type is a parameter annotation, the input parameter field corresponding to the parameter annotation can be parsed, that is, the input parameter field that needs to be verified. Further, the reflection technology (reflection technology is to obtain the properties, methods, annotations, parameters, etc. in the class file corresponding to the bytecode object through the bytecode object) can be used to obtain the parameter value corresponding to the input parameter field; wherein, the input parameter field identified by the parameter annotation can be attributed to the various parameters of the business method and the various parameters corresponding to the business request. The input parameter field is obtained by parsing from the parameter annotation, and the parameter value corresponding to the input parameter field is obtained to further verify the legitimacy of the parameter value. For example: the input parameter field is "cellNumber" (mobile phone number), and the corresponding parameter value is "12345678901". After parsing the parameter value, it can be further verified whether the parameter value is a legal mobile phone number.
[0048] Step S102: searching for a first verification code that matches the verification strategy among a plurality of preset verification codes, and calling the first verification code to verify the business code.
[0049] Specifically, a variety of verification codes are preset according to applications and business scenarios, and the preset verification code is executed on the set business code to determine whether the verified method or parameter has the preset legitimacy through the logic of the verification code; wherein, the verification code can belong to one or more class files; for example: if the verification strategy is "user information verification", then the "user information verification code" (that is, the first verification code) corresponding to the "user information verification" is searched from the verification code, and the first verification code is called to verify the user information corresponding to the business code. It can be understood that multiple applications or scenarios can have the same verification strategy, and multiple methods or parameters in an application can also have the same verification strategy. Using the first verification code corresponding to the verification strategy reduces the development of verification logic code for each business code, and improves the efficiency of developing and verifying the code by decoupling the verification code from the business code.
[0050] Furthermore, the verification strategy includes multiple verification rules, for example: the verification strategy is "user information verification", which includes: user name legitimacy verification, user ID card information legitimacy verification, user mobile phone number legitimacy verification, etc.; therefore, based on each verification rule (the verification rule can be parsed from the annotation), the verification code corresponding to the verification rule (that is, the second verification code) is found; wherein, the method for finding the second verification code can be through the verification rule identifier; the verification rule identifier belongs to the first verification code; further, the first verification code contains annotations for identifying one or more verification strategies and multiple verification rules corresponding to the verification code; that is, the first verification code contains verification annotations; the verification annotation contains verification rule identifiers corresponding to multiple verification rules; further including: matching each verification rule identifier included in the verification strategy with the multiple verification rule identifiers included in the verification annotation; according to the matching results, executing the steps of calling the second verification code corresponding to the verification rule in sequence to verify the business code. For example: the verification rule is "whether the parameter is null", and the verification annotation of the first verification code contains "@rule_null" to indicate the second verification code for verifying "whether the parameter is null"; that is, the verification annotation contains multiple verification rule identifiers corresponding to the verification rules; each verification rule identifier is matched with the multiple verification rule identifiers contained in the verification annotation; according to the matching result, the step of sequentially calling the second verification code corresponding to the verification rule to verify the business code is executed; preferably, the annotation (including the verification rule identifier) contained in the first verification code is loaded into the memory when the service is started, so as to match each verification rule identifier included in the verification strategy with the multiple verification rule identifiers contained in the verification annotation, and run the verification code corresponding to the verification rule identifier, and execute the step of sequentially calling the second verification code corresponding to the verification rule to verify the business code.
[0051] Furthermore, in response to the presence of multiple verification rules in the verification strategy, the first verification code includes a priority order for executing the verification rules; using the first verification code to perform verification on the business code includes: based on the priority order, sequentially calling the second verification code corresponding to the verification rule to verify the business code. Specifically, in the case of multiple verification rules, a priority order can be set for the verification rules so that the second verification code executes the verification code steps according to the priority order, for example: the verification strategy is order verification; the set verification rule priority order is: first verify the legitimacy of the order number, then verify the validity of the order number, and finally verify the operation authority corresponding to the order number, etc.; it can be understood that the priority order information can be set in the first verification code.
[0052] Furthermore, the first verification code has a corresponding verification context; further comprising: storing the data to be verified included in the business code into the verification context; and using the verification context to share the data to be verified for multiple second verification codes. Specifically, the verification context is used to provide source data objects and business data objects for the verification code, thereby achieving data exchange between different verification codes. For example, if two verification rules are both associated with user information data, the saved user information data (i.e., the data to be verified) can be obtained from the verification context; for example, if verification rule 1 is to verify the user name, the second verification code corresponding to the verification user name can obtain the user information from the user information data stored in the verification context, and parse out the user name for verification; if verification rule 2 is to verify the user's mobile phone number, the second verification code corresponding to the verification user's mobile phone number can directly obtain the user's mobile phone number information from the user information stored in the verification context, thereby achieving data sharing, i.e., multiple second verification codes share the data to be verified.
[0053] Preferably, technologies such as ConcurrentHashMap and ThreadLocal can be used to improve data security during data transmission using verification context. ConcurrentHashMap belongs to the java.util.concurrent package and supports efficient multi-threaded concurrency. ThreadLocal is an internal storage class that can store data within a specified thread, ensuring that only the specified thread can access the stored data after it is stored.
[0054] As can be seen, this application achieves decoupling between verification rules, verification code, and business logic (business code) through code isolation, thereby improving the scalability and flexibility of the verification business code; this application implements verification code based on setting annotations, reducing the difficulty and complexity of development. At the same time, the verification code's ability to orchestrate verification strategies (verification rules) improves the flexibility of using verification rules; the annotation type includes parameter annotations, and the granularity of verification can be flexibly configured, further improving the flexibility and maintainability of the verification code.
[0055] like Figure 2 As shown, an embodiment of the present invention provides a method for verifying a code, which may include the following steps:
[0056] Step S201: Acquire multiple annotation types: method annotations, parameter annotations.
[0057] Specifically, the descriptions of method annotations, parameter annotations, and verification annotations are consistent with those of steps S101 and S102 and are not repeated here.
[0058] Step S202: calling the first verification code for verification: the first verification code includes a plurality of second verification codes corresponding to the verification rules.
[0059] Specifically, annotations are intercepted through AOP and / or parsed through reflection, where the annotations include the annotation type described in step S201, and various verification strategies. According to the parsed annotation type and the corresponding verification strategy, the first verification code corresponding to the verification strategy is called to perform verification.
[0060] The specific descriptions of the first verification code, the second verification code, and the verification rules; as well as the specific descriptions of intercepting annotations through AOP and parsing annotations through reflection are consistent with the description of step S102 and are not repeated here.
[0061] Step S203: using the verification context to provide shared data to be verified.
[0062] Specifically, when calling the first verification code for verification, the verification context is used to provide shared data to be verified; that is, the first verification code has a corresponding verification context; further including: storing the data to be verified included in the business code into the verification context; using the verification context to share the data to be verified for multiple second verification codes.
[0063] Step S204: Generate verification results.
[0064] Specifically, the first verification code can be encapsulated as a verifier engine, which is used to encapsulate the verification strategy (and multiple verification rules) contained in the class file corresponding to the first verification code; optionally, the priority order of the verification rules can also be encapsulated. Preferably, the verifier engine is used to encapsulate the verification result return data, so that a unified interface can be used to feedback return information such as verification failure, verification success, and verification exception.
[0065] It is understood that the order of steps in this process is a schematic order and may be different from the execution order.
[0066] like Figure 3 As shown, an embodiment of the present invention provides a device 300 for verifying code, comprising: an annotation parsing module 301 and a code verification module 302; wherein,
[0067] The annotation parsing module 301 is used to obtain the annotation corresponding to the business code, parse the annotation type from the annotation, and obtain the verification strategy associated with the annotation type from the annotation;
[0068] The verification code module 302 is configured to search for a first verification code that matches the verification strategy among a plurality of preset verification codes, and call the first verification code to verify the business code.
[0069] Optionally, in the annotation parsing module 301 , the annotation types include: method annotations and / or parameter annotations.
[0070] Optionally, the annotation parsing module 301 is also used to intercept the calling instruction in response to the calling instruction of any business method in the business code when the annotation type is the method annotation; determine the method annotation of the business method corresponding to the calling instruction; and obtain the verification strategy corresponding to the method annotation from the method annotation.
[0071] Optionally, the annotation parsing module 301 is further configured to, when the annotation type is the parameter annotation, determine an input parameter field corresponding to the parameter annotation and obtain a parameter value corresponding to the input parameter field.
[0072] Optionally, the verification code module 302 is also used to respond to the existence of multiple verification rules in the verification strategy, and the first verification code includes a priority order for executing the verification rules; using the first verification code to perform verification on the business code, including: based on the priority order, calling the second verification code corresponding to the verification rule in sequence to verify the business code.
[0073] Optionally, the verification code module 302 is also used for the first verification code to have a corresponding verification context; further includes: storing the data to be verified included in the business code into the verification context; using the verification context to share the data to be verified for multiple second verification codes.
[0074] Optionally, the verification code module 302 is also used to match each verification rule identifier included in the verification strategy with multiple verification rule identifiers contained in the verification annotation; based on the matching result, execute the step of sequentially calling the second verification code corresponding to the verification rule to verify the business code.
[0075] An embodiment of the present invention also provides an electronic device for verifying codes, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in any of the above embodiments.
[0076] An embodiment of the present invention further provides a computer-readable medium having a computer program stored thereon, and when the program is executed by a processor, the method provided in any of the above embodiments is implemented.
[0077] Figure 4 An exemplary system architecture 400 is shown to which the code verification method or code verification apparatus according to an embodiment of the present invention may be applied.
[0078] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0079] Users can use terminal devices 401, 402, and 403 to interact with server 405 via network 404 to receive or send messages, etc. Various client applications can be installed on terminal devices 401, 402, and 403, such as e-commerce client applications, web browser applications, search applications, instant messaging tools, and email clients.
[0080] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting various client applications, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0081] The server 405 may be a server that provides various services, such as a background management server that provides support for client applications used by users using the terminal devices 401, 402, and 403. The background management server may process the received verification code request and feed back the verification result to the terminal device.
[0082] It should be noted that the code verification method provided in the embodiment of the present invention is generally executed by the server 405 , and the code verification device is generally set in the server 405 .
[0083] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.
[0084] Reference below Figure 5 , which shows a schematic structural diagram of a computer system 500 of a terminal device suitable for implementing an embodiment of the present invention. Figure 5 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0085] like Figure 5As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage unit 508 into a random access memory (RAM) 503. Various programs and data required for the operation of the system 500 are also stored in the RAM 503. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0086] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, and the like; an output section 507 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 508 including a hard disk; and a communication section 509 including a network interface card such as a LAN card or a modem. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 510 as needed, so that computer programs read therefrom can be installed into the storage section 508 as needed.
[0087] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 509, and / or installed from a removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are performed.
[0088] It should be noted that the computer-readable medium described in the present invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media can include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wireline, optical fiber cable, RF, or any suitable combination thereof.
[0089] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0090] The modules and / or units involved in the embodiments of the present invention may be implemented in software or in hardware. The modules and / or units described may also be provided in a processor. For example, they may be described as follows: a processor includes an annotation parsing module and a code verification module. The names of these modules do not, in some cases, constitute a limitation on the module itself. For example, the annotation parsing module may also be described as "obtaining the annotation corresponding to the business code, parsing the annotation type from the annotation, and obtaining the verification strategy module associated with the annotation type from the annotation."
[0091] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently and not be incorporated into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the device, the device is caused to: obtain an annotation corresponding to a business code, parse the annotation type from the annotation, and obtain a verification strategy associated with the annotation type from the annotation; search for a first verification code that matches the verification strategy among multiple preset verification codes, and call the first verification code to verify the business code.
[0092] The embodiments of the present invention can obtain the annotations of the business code, parse the verification strategy for the code from the annotations, and call the corresponding verification code through the verification strategy to perform verification on the business code; overcome the problem of coupling the verification code with the business code, thereby overcoming the problems of poor flexibility and reusability of the verification code; improve the maintainability of the verification code; and improve development efficiency by reducing the labor cost and time cost of development.
[0093] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A method for verifying a code, characterized in that: include: Obtain the annotation corresponding to the business code, parse the annotation type from the annotation, and obtain the verification strategy associated with the annotation type from the annotation; Searching for a first verification code that matches the verification strategy among a plurality of preset verification codes, and calling the first verification code to verify the business code; The first verification code has a corresponding verification context; The verification context is used to provide source data objects and business data objects for the verification code to enable data exchange between different verification codes; The verification strategy includes a plurality of verification rules, and searching for a second verification code corresponding to the verification rule; The method further comprises: storing the to-be-verified data included in the business code into the verification context; The verification context is used to share the data to be verified for multiple second verification codes.
2. The method according to claim 1, characterized in that The annotation types include: method annotations and / or parameter annotations.
3. The method according to claim 2, characterized in that The parsing of the annotation type from the annotation and obtaining the verification strategy associated with the annotation type from the annotation includes: The annotation type is the method annotation, In response to a call instruction of any business method in the business code, intercept the call instruction; Determine the method annotation of the business method corresponding to the call instruction; Obtain the verification strategy corresponding to the method annotation from the method annotation.
4. The method according to claim 2, characterized in that The parsing of the annotation type from the annotation further comprises: The annotation type is the parameter annotation, Determine the input parameter field corresponding to the parameter annotation, and obtain the parameter value corresponding to the input parameter field.
5. The method according to claim 1, wherein Further including: In response to the verification strategy having a plurality of the verification rules, the first verification code includes a priority order for executing the verification rules; Performing verification on the service code using the first verification code includes: Based on the priority order, the second verification code corresponding to the verification rule is called in sequence to verify the business code.
6. The method according to claim 5, characterized in that The first verification code includes a verification annotation; the verification annotation includes verification rule identifiers corresponding to multiple verification rules; Further including: Matching each verification rule identifier included in the verification strategy with multiple verification rule identifiers included in the verification annotation; According to the matching result, the step of sequentially calling the second verification code corresponding to the verification rule to verify the business code is executed.
7. A device for verifying a code, characterized in that: include: Parsing annotation module and verification code module; among them, The annotation parsing module is used to obtain the annotation corresponding to the business code, parse the annotation type from the annotation, and obtain the verification strategy associated with the annotation type from the annotation; The verification code module is configured to search for a first verification code that matches the verification strategy among a plurality of preset verification codes, and call the first verification code to verify the business code; The verification strategy includes a plurality of verification rules, and searching for a second verification code corresponding to the verification rule; The first verification code has a corresponding verification context; the verification context is used to provide source data objects and business data objects for the verification code to enable data exchange between different verification codes; The device is further configured to store the data to be verified included in the business code into the verification context; and utilize the verification context to share the data to be verified for multiple second verification codes.
8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer-readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Parameter verification method and device
CN110765422A