A parameter verification method and device

By using abstract business objects and section interception technology in JAVA applications, the low coupling and scalability of parameter verification logic is achieved, and the intrusiveness and cumbersomeness of parameter verification in the existing technology is solved, and the development efficiency is improved. Extensibility.

CN110765422BActive Publication Date: 2025-01-14BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN201810825281.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-07-25
Publication Date
2025-01-14
Estimated Expiration
2038-07-25

AI Technical Summary

Technical Problem

The existing parameter verification scheme requires intrusion into business code, and the parameter verification work is cumbersome and has poor scalability, making it difficult to achieve low coupling and reusability.

Method used

Receive input parameters of business logic through predefined abstract business objects, and obtain the list of fields to be checked by sectional interception before the business logic is executed, and verify according to the parameter verification rules corresponding to the abstract business objects, using abstraction Custom methods and rules for subclasses to which the business object belongs are filtered and verified.

Benefits of technology

The parameter verification logic does not invade business code, the logic and business logic are lowly coupled, and the development versatility, reusability and scalability are good, which simplifies the development cost and the workload of parameter verification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110765422B_ABST
    Figure CN110765422B_ABST
Patent Text Reader

Abstract

The present invention discloses a parameter verification method and device, and relates to the field of computer technology. A specific implementation of the method includes: receiving input parameters of business logic through a predefined abstract business object; intercepting the business logic through a section before the business logic is executed, and obtaining a list of fields to be verified of the input parameters when the method parameters of the business logic include the abstract business object; verifying each field in the list of fields to be verified according to the parameter verification rules corresponding to the abstract business object to obtain the input parameter verification result of the business logic. This implementation makes the parameter verification logic not invade the business code, the parameter verification logic and the business logic are low-coupled, and the development versatility, reusability, and scalability are good, which simplifies the development cost and the workload of parameter 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. Background Art

[0002] In the development of JAVA applications, the system needs to obtain input parameters submitted by users from the interaction with users, so it has to face two abnormal situations: the first is the missing parameters; the second is the illegal parameter values. When pursuing a good user experience and system robustness, parameter verification must be performed, so that the terminal business will handle the illegal parameters and inform the system users of the reasons. There are two common ways to handle exceptions: one is detailed processing, that is, parameter verification within the business logic; the other is unprocessed (missing or illegal parameters will waste server resources and may even cause the program to crash).

[0003] The existing parameter verification scheme (the above-mentioned detailed processing) performs parameter verification within the business logic. The parameter verification logic needs to invade the business code. When the system is large and the business is numerous, the parameter verification work is cumbersome and the scalability is poor. Due to the differences in business functions, the parameter verification logic is difficult to share.

[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0005] The existing parameter verification scheme requires intrusion into business code, and the parameter verification work is cumbersome and has poor scalability. Summary of the invention

[0006] In view of this, an embodiment of the present invention provides a parameter verification method and device, so that the parameter verification logic does not invade the business code, the parameter verification logic and the business logic are loosely coupled, and the development versatility, reusability and scalability are good, which simplifies the development cost and the workload of parameter verification.

[0007] To achieve the above objective, according to one aspect of an embodiment of the present invention, a parameter verification method is provided.

[0008] A parameter verification method comprises: receiving input parameters of business logic through a predefined abstract business object; intercepting the business logic through a section before the business logic is executed, and obtaining a list of fields to be verified of the input parameters when the method parameters of the business logic include the abstract business object; and verifying each field in the list of fields to be verified according to the parameter verification rule corresponding to the abstract business object to obtain the input parameter verification result of the business logic.

[0009] Optionally, before the step of receiving the input parameters of the business logic through the predefined abstract business object, it includes: defining an abstract business base class, which is the parent class of the subclass to which the abstract business object belongs; wherein the abstract business base class includes a business method for determining whether the parameter is legal, a business method for setting detailed information of illegal parameters, a business method for obtaining verification fields, and a field in a data format for storing information on illegal parameters.

[0010] Optionally, the step of obtaining the list of fields to be checked for the input parameters includes: calling the business method for obtaining verification fields in the abstract business base class, so as to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection, thereby obtaining the list of fields to be checked for the input parameters.

[0011] Optionally, the step of obtaining the list of fields to be checked for the input parameters includes: calling a business method for obtaining verification fields that is customized in the subclass to which the abstract business object belongs, so as to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection; filtering the obtained fields according to the customized filtering rules of the subclass to which the abstract business object belongs, and obtaining the list of fields to be checked for the input parameters according to the filtered fields.

[0012] Optionally, the step of verifying each field in the list of fields to be verified according to the parameter verification rules corresponding to the abstract business object includes: calling a business method in the abstract business base class to determine whether a parameter is legal, so as to perform a first verification according to the configuration information in the annotation, or perform the first verification and the second verification; wherein the first verification includes: verifying whether each field in the list of fields to be verified is empty; the second verification includes: verifying at least one of the following three of each field: maximum character length, minimum character length, and regular expression.

[0013] Optionally, the step of verifying each field in the list of fields to be verified according to the parameter verification rules corresponding to the abstract business object includes: verifying whether each field in the list of fields to be verified complies with the custom verification rules in the subclass to which the abstract business object belongs according to the custom verification rules.

[0014] Optionally, after the step of checking each field in the list of fields to be checked, it includes: calling a business method in the abstract business base class to set detailed information of illegal parameters, so as to record the detailed information of illegal parameters that fail the check in the field of the data format for storing illegal parameter information.

[0015] According to another aspect of an embodiment of the present invention, a parameter verification device is provided.

[0016] A parameter verification device comprises: a receiving module, which is used to receive input parameters of business logic through a predefined abstract business object; an obtaining module, which is used to intercept the business logic through a section before the business logic is executed, and when the method parameters of the business logic include the abstract business object, obtain a list of fields to be verified of the input parameters; and a verification module, which is used to verify each field in the list of fields to be verified according to the parameter verification rules corresponding to the abstract business object, so as to obtain the input parameter verification result of the business logic.

[0017] Optionally, it also includes a business base class definition module, which is used to: define an abstract business base class, which is the parent class of the subclass to which the abstract business object belongs; wherein the abstract business base class includes a business method for determining whether a parameter is legal, a business method for setting detailed information of illegal parameters, a business method for obtaining a verification field, and a field in a data format for storing information on illegal parameters.

[0018] Optionally, the acquisition module is also used to: call the business method for obtaining verification fields in the abstract business base class to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection, thereby obtaining a list of fields to be checked for the input parameters.

[0019] Optionally, the acquisition module is also used to: call the business method for obtaining verification fields customized in the subclass to which the abstract business object belongs, so as to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection; filter the obtained fields according to the customized filtering rules of the subclass to which the abstract business object belongs, and obtain the list of fields to be checked for the input parameters based on the filtered fields.

[0020] Optionally, the verification module is also used to: call the business method in the abstract business base class to determine whether the parameters are legal, so as to perform a first check according to the configuration information in the annotation, or perform the first check and the second check; wherein the first check includes: checking whether each field in the list of fields to be checked is empty; the second check includes: checking at least one of the following three of each field: maximum character length, minimum character length, and regular expression.

[0021] Optionally, the verification module is further used to: verify whether each field in the list of fields to be verified complies with the custom verification rule according to the custom verification rule in the subclass to which the abstract business object belongs.

[0022] Optionally, it also includes an information recording module, which is used to: call the business method for setting the detailed information of illegal parameters in the abstract business base class, so as to record the detailed information of illegal parameters that fail the verification in the field of the data format for storing illegal parameter information.

[0023] According to yet another aspect of the embodiments of the present invention, an electronic device is provided.

[0024] An electronic device comprises: one or more processors; a memory 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 parameter verification method provided by the present invention.

[0025] According to yet another aspect of an embodiment of the present invention, a computer readable medium is provided.

[0026] A computer readable medium stores a computer program, which implements the parameter verification method provided by the present invention when executed by a processor.

[0027] One embodiment of the above invention has the following advantages or beneficial effects: receiving the input parameters of the business logic through a predefined abstract business object; intercepting the business logic through the aspect before the business logic is executed, and obtaining the list of fields to be checked of the input parameters when the method parameters of the business logic include the abstract business object; verifying each field in the list of fields to be checked according to the parameter verification rules corresponding to the abstract business object to obtain the input parameter verification result of the business logic. The parameter verification logic does not invade the business code, and the parameter verification logic and the business logic are loosely coupled. When obtaining the list of fields to be checked for the input parameters, and verifying each field in the list of fields to be checked, the customized business methods or rules in the subclass to which the abstract business object belongs can be used, which has good development versatility, reusability, and scalability, and simplifies the development cost and workload of parameter verification.

[0028] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0030] Figure 1 is a schematic diagram of the main steps of a parameter verification method according to an embodiment of the present invention;

[0031] Figure 2 is a schematic diagram of a preferred flow of business processing according to an embodiment of the present invention;

[0032] Figure 3is a schematic diagram of the inheritance relationship between the service reception parameter object and the BaseVo class according to an embodiment of the present invention;

[0033] Figure 4 This is a schematic diagram of the structure of the custom annotation NotNull according to an embodiment of the present invention;

[0034] Figure 5 is a schematic diagram of a preferred processing flow of parameter verification according to an embodiment of the present invention;

[0035] Figure 6 is a schematic diagram of main modules of a parameter verification device according to an embodiment of the present invention;

[0036] Figure 7 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0037] Figure 8 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

[0038] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill 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 clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0039] Figure 1 4 is a schematic diagram of main steps of a parameter verification method according to an embodiment of the present invention.

[0040] like Figure 1 As shown, the parameter verification method of the embodiment of the present invention mainly includes the following steps S101 to S103.

[0041] Step S101: receiving input parameters of business logic through a predefined abstract business object.

[0042] Before step S101, an abstract service base class may be defined, where the abstract service base class is the parent class of the subclass to which the abstract service object belongs.

[0043] The abstract business base class includes a business method for determining whether a parameter is legal, a business method for setting detailed information of illegal parameters, a business method for obtaining a verification field, and a field for storing a data format of illegal parameter information.

[0044] Step S102: intercept the business logic through the aspect before the business logic is executed, and when the method parameters of the business logic include abstract business objects, obtain the list of fields to be checked of the input parameters.

[0045] In one implementation, the step of obtaining a list of fields to be checked of the input parameters may specifically include:

[0046] The business method for obtaining verification fields in the abstract business base class is called to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection, thereby obtaining a list of fields to be verified for the input parameters.

[0047] In another embodiment, the step of obtaining a list of fields to be checked of the input parameters may specifically include:

[0048] Call the custom business method for obtaining validation fields in the subclass to which the abstract business object belongs, so as to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection;

[0049] The obtained fields are filtered according to the customized filtering rules of the subclass to which the abstract business object belongs, and a list of fields to be checked of the input parameters is obtained based on the filtered fields.

[0050] In this implementation, the subclass of the abstract business base class (ie, the subclass to which the abstract business object belongs) can rewrite the business method for obtaining the verification field specified in the abstract business base class according to business requirements, which has good scalability.

[0051] Among them, reflection is a computer processing method. The ability of a program to access, detect and modify its own state or behavior can provide encapsulated assemblies (assemblies contain modules, modules contain types, and types contain members) and objects of types.

[0052] Step S103: verify each field in the to-be-verified field list according to the parameter verification rule corresponding to the abstract business object to obtain the input parameter verification result of the business logic.

[0053] In one implementation, the step of verifying each field in the list of fields to be verified according to the parameter verification rule corresponding to the abstract business object may specifically include:

[0054] Call the business method in the abstract business base class to determine whether the parameters are legal, so as to perform the first check, or the first check and the second check according to the configuration information in the annotation;

[0055] The first check includes: checking whether each field in the field list to be checked is empty; the second check includes: checking at least one of the following three of each field: maximum character length, minimum character length, and regular expression.

[0056] Among them, it can be determined whether to perform the second check and which of the above three checks in the second check is performed according to the configuration information in the annotation, including the configuration of the strMinLen (minimum length of characters), strMaxLen (maximum length of characters), and regStr (regular expression) attributes. For example, when the configuration information in the annotation does not configure the strMinLen, strMaxLen, and regStr attributes, the second check is not performed; when the three attributes of strMinLen, strMaxLen, and regStr are configured, the maximum length of characters, the minimum length of characters, and the regular expression check are performed on the field of the input parameter. In addition, when performing the check, the first check can be performed first, and if the first check passes, the second check can be performed. When performing the second check, the check can be performed in the following order: minimum length of characters, maximum length of characters, and regular expression, that is, for the field currently being checked, first check its minimum length of characters, if the minimum length of characters is checked, check the maximum length of characters, and if the maximum length of characters is checked, finally perform the regular expression check. If the check of each link fails, the check process ends.

[0057] In another embodiment, the step of verifying each field in the list of fields to be verified according to the parameter verification rule corresponding to the abstract business object may specifically include:

[0058] According to the custom validation rules in the subclass to which the abstract business object belongs, verify whether each field in the field list to be verified complies with the custom validation rules.

[0059] In this implementation, the subclass of the abstract business base class (i.e., the subclass to which the abstract business object belongs) can rewrite the business method for determining whether the parameters are legal as specified in the abstract business base class according to business needs, and verify the input parameters according to the custom verification rules. For example, in business scenarios such as determining whether the value of an input parameter is a specific expected parameter value, if the parameter verification rules of the parent class (abstract business base class) are used, the verification will fail. According to this implementation, the user can rewrite the judgment logic of the parameter verification in the subclass of the abstract business base class, and determine that when the field value of the input parameter is consistent with the specific expected parameter value, the verification passes, otherwise the verification fails. This makes the parameter verification method of the embodiment of the present invention have good scalability and versatility, and simplifies the development cost in a complex system with a large system and a variety of businesses.

[0060] After the step of checking each field in the list of fields to be checked, the business method for setting the details of illegal parameters in the abstract business base class can be called to record the details of illegal parameters that failed the check in the field of the data format for storing illegal parameter information.

[0061] The input parameter verification result may include verification passed and verification failed. If the verification is passed, the business logic is executed using the parameters that passed the verification. If the verification is failed, the business logic is not executed and the business processing flow ends.

[0062] Figure 2 It is a schematic diagram of a preferred flow of business processing according to an embodiment of the present invention.

[0063] like Figure 2 As shown, in the business processing flow of the embodiment of the present invention, after defining the processing specification of the parameter verification logic, the parameter verification is automatically performed before the business processing according to the defined specification, so as to have no intrusion on the business function code. The specific steps include step S201 to step S203.

[0064] Step S201: define the processing specification of parameter verification logic.

[0065] In order to unify the verification logic of different business function parameters and make the business logic reusable and extensible, the embodiment of the present invention defines the following processing specifications:

[0066] The embodiment of the present invention defines the specification of receiving the input parameters of the business logic using the abstract BaseVo type in JAVA. The class defines the business method for determining whether the parameter is legal, the business method for setting the detailed information of the illegal parameter, the business method for obtaining the verification field, and the field in the Map data format for storing the illegal parameter information.

[0067] The abstract BaseVo type is an abstract business base class. When receiving the input parameters of the business logic, the input parameters are received through the business receiving parameter object of the subclass of the BaseVo class, that is, the abstract business object. Therefore, the business receiving parameter object must be a subclass of BaseVo, so that the subclass can use the characteristics of JAVA inheritance to have the above-mentioned business methods of the parameter verification logic defined by the parent class. In addition, the subclass can rewrite the business method of judging whether the parameter is legal according to its own unique scenario to achieve the purpose of expansion. The inheritance relationship between the business receiving parameter object and the BaseVo class is as follows: Figure 3 As shown, Figure 3 Two service receiving parameter objects are shown as examples: service VO1 and service VO2. The subclasses to which service VO1 and service VO2 belong can utilize the characteristics of JAVA inheritance and have various service methods of parameter verification logic defined by the parent class (BaseVO).

[0068] The business method for obtaining the validation field is mainly based on the @NotNull custom annotation acting on the subclass field of the BaseVo class. The fields marked with the annotation in the subclass are obtained according to the JAVA reflection technology, and returned in the form of a list of fields to be verified of the input parameters.

[0069] The business method for judging whether the parameter is legal is to traverse the list of fields to be checked according to the list of fields to be checked returned by the business method for obtaining the verification field. In order to save performance overhead, if the current verification field is found to be illegal during the traversal process, the traversal will be stopped, the illegal parameter details will be saved, and the illegal parameter result will be returned. Specifically, first determine whether the field is empty. If the field is empty, it means that the parameter verification is illegal. The business method for setting the details of the illegal parameter is called, and the illegal parameter details are saved; if the parameter is not empty, then further determine whether to perform string length and regular expression verification based on the configuration information in the @NotNull annotation, including the configured strMinLen (minimum character length), strMaxLen (maximum character length), and regStr (regular expression) attributes. Among them, the three attributes of strMinLen, strMaxLen, and regStr in the configuration information will only take effect if they are configured. Not configuring means that no verification is required.

[0070] The business method for setting the details of illegal parameters is to record the details of illegal parameters in the fields of the Map data structure defined in the BaseVO class. The key in this Map field records the type information of illegal parameters (such as missing parameters, illegal parameter values, etc.) and illegal details (the received field name will be carried in order to quickly locate the problem).

[0071] The present invention also defines a custom annotation specification for parameter verification. The custom annotation is used to store the configuration information of the parameter verification logic. The present invention defines a custom annotation NotNull, which indicates that the input parameter cannot be empty. The annotation also declares three attributes: strMinLen (minimum character length), strMaxLen (maximum character length), and regStr (regular expression). Relying on the powerful functions of regular expressions, the above three attributes can cover most application scenarios in daily business. strMinLen indicates the minimum length of the string. When it is -1, it means there is no limit. This attribute only works for the input parameters of the string class; strMaxLen indicates the maximum length of the string. When it is -1, it means there is no limit. This attribute only works for the input parameters of the string class; regStr represents the regular expression for verification, which works when the value is not empty. The custom annotation NotNull composition structure is as follows Figure 4 shown.

[0072] The embodiment of the present invention also defines that the method parameters of the business logic must include the specification of the subclass of the BaseVo class, and can further stipulate that the first method parameter of the business logic is a subclass of the BaseVo class, so as to quickly and accurately find the object that needs to be parameter checked. In order to unify the parameter check processing logic, it is agreed that the parameters that need to be parameter checked are encapsulated in the subclass of the BaseVo class, that is, the class to which the business receiving parameter object (or abstract business object) belongs is a subclass of the BaseVo class.

[0073] Step S202: Perform parameter verification according to the defined specifications. If the verification passes, execute step S203, otherwise end the process.

[0074] Step S203: Perform business logic processing using the input parameters that have passed the verification.

[0075] Figure 5 It is a schematic diagram of a preferred processing flow of parameter verification according to an embodiment of the present invention.

[0076] like Figure 5 As shown, a preferred processing flow of parameter verification of an embodiment of the present invention includes the following steps S501 to S513.

[0077] Step S501: Determine whether the first method parameter of the business logic is a BaseVo instance. If so, execute step S502; otherwise, end the process.

[0078] The BaseVo instance may be an object of the BaseVo class or a subclass of the BaseVo class.

[0079] Step S502: Obtain the annotated fields in the subclass of the BaseVo class to obtain a list of fields to be checked for the input parameters.

[0080] Specifically, the business method for obtaining verification fields in the abstract business base class (BaseVo class) is called to obtain all annotated fields in the subclasses of the BaseVo class through JAVA reflection, thereby obtaining a list of fields to be verified for the input parameters.

[0081] Step S503: determine whether there are any unchecked fields in the list of fields to be checked. If yes, execute step S504; otherwise, end the process.

[0082] Step S504: Determine whether the current check field is empty, if so, end the process, otherwise execute step S505.

[0083] Step S505: Determine whether character minimum length verification is required, if so, execute step S506, otherwise, execute step S508.

[0084] Step S506: perform character minimum length verification on the current check field, and then execute step S507.

[0085] Step S507: Determine whether the character minimum length verification of the current check field passes, if so, execute step S508, otherwise end the process.

[0086] Step S508: Determine whether character maximum length verification is required, if so, execute step S509, otherwise, execute step S511.

[0087] Step S509: Perform character maximum length verification on the current check field, and then execute step S510.

[0088] Step S510: Determine whether the maximum length verification of the characters in the current verification field is passed. If so, execute step S511, otherwise end the process.

[0089] Step S511: Determine whether regular verification is required, if so, execute step S512, otherwise, return to step S503.

[0090] Step S512: Perform regular verification on the current check field, and then execute step S513.

[0091] Step S513: Determine whether the regular verification of the current check field passes. If so, return to step S503, otherwise, end the process.

[0092] The business method in the abstract business base class (BaseVo class) that determines whether the parameters are legal can be called to perform the above-mentioned operations of determining whether the current check field is empty, as well as performing character minimum length verification, character maximum length verification, and regular expression verification according to the configuration information in the annotation. The configuration information in the annotation includes the configured strMinLen (character minimum length), strMaxLen (character maximum length), and regStr (regular expression) attributes. If any of the three attributes is not configured, it means that the attribute of the field does not need to be verified.

[0093] In addition, in order to prevent the parameter verification logic from intruding into the business code, the embodiment of the present invention adopts the Spring AOP (aspect-oriented programming) concept and is implemented in the form of surround notification. The BaseVO logic for determining whether the parameters are legal is called in advance before the business logic. When the parameters are illegal, a custom business exception is output.

[0094] The embodiment of the present invention defines a general abstract business object for receiving user input parameters, implements the parameter verification code in the abstract business base class, uses custom annotations in the parameter verification process, configures the judged parameters through annotation attributes, and calls the unified parameter verification logic through a custom aspect. The unified parameter verification logic of the embodiment of the present invention can overcome the problem that the parameter verification logic is difficult to share due to the differences in business functions.

[0095] Figure 6 4 is a schematic diagram of main modules of a parameter verification device according to an embodiment of the present invention.

[0096] The parameter verification device 600 of the embodiment of the present invention mainly includes: a receiving module 601 , an acquisition module 602 , and a verification module 603 .

[0097] The receiving module 601 is used to receive input parameters of the business logic through a predefined abstract business object.

[0098] The parameter verification device 600 may also include a business base class definition module, which is used to: define an abstract business base class, which is the parent class of the subclass to which the abstract business object belongs; wherein the abstract business base class includes a business method for determining whether a parameter is legal, a business method for setting detailed information of illegal parameters, a business method for obtaining a verification field, and a field in a data format for storing information on illegal parameters.

[0099] The acquisition module 602 is used to intercept the business logic through the aspect before the business logic is executed, and when the method parameters of the business logic include abstract business objects, obtain the list of fields to be checked of the input parameters.

[0100] In one embodiment, the acquisition module 602 can be specifically used to: call the business method of obtaining verification fields in the abstract business base class to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection, thereby obtaining a list of fields to be verified for the input parameters.

[0101] In another embodiment, the acquisition module 602 can be specifically used to: call the business method for obtaining verification fields that is customized in the subclass to which the abstract business object belongs, so as to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection; filter the obtained fields according to the customized filtering rules of the subclass to which the abstract business object belongs, and obtain a list of fields to be checked for the input parameters based on the filtered fields.

[0102] The verification module 603 is used to verify each field in the to-be-verified field list according to the parameter verification rule corresponding to the abstract business object, so as to obtain the input parameter verification result of the business logic.

[0103] In one implementation, the verification module 603 may be specifically used to: call a business method in an abstract business base class to determine whether a parameter is legal, so as to perform a first verification, or perform a first verification and a second verification according to configuration information in the annotation;

[0104] The first check includes: checking whether each field in the field list to be checked is empty; the second check includes: checking at least one of the following three of each field: maximum character length, minimum character length, and regular expression.

[0105] In another implementation, the verification module 603 may be specifically configured to verify whether each field in the list of fields to be verified complies with the custom verification rule according to the custom verification rule in the subclass to which the abstract business object belongs.

[0106] The parameter checking device 600 may further include an information recording module for calling a business method in an abstract business base class to set detailed information of illegal parameters, so as to record detailed information of illegal parameters that fail the check in a field of a data format for storing illegal parameter information.

[0107] In addition, the specific implementation content of the parameter verification device in the embodiment of the present invention has been described in detail in the parameter verification method described above, so the repeated content will not be described again here.

[0108] Figure 7 An exemplary system architecture 700 to which the parameter verification method or parameter verification device according to the embodiment of the present invention can be applied is shown.

[0109] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, 703, network 704 and server 705. Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0110] Users can use terminal devices 701, 702, and 703 to interact with server 705 through network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0111] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.

[0112] The server 705 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using the terminal devices 701, 702, and 703. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information and product information) to the terminal device.

[0113] It should be noted that the parameter verification method provided in the embodiment of the present invention can be executed by the server 705 or the terminal devices 701, 702, 703, and accordingly, the parameter verification device can be set in the server 705 or the terminal devices 701, 702, 703.

[0114] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0115] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device or server suitable for implementing an embodiment of the present application. Figure 8 The terminal device or server shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0116] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0117] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.

[0118] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present application are executed.

[0119] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries a 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 of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0120] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order 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 flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0121] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a receiving module 601, an acquisition module 602, and a verification module 603. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the receiving module 601 may also be described as "a module for receiving input parameters of business logic through predefined abstract business objects".

[0122] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: receiving input parameters of business logic through predefined abstract business objects; intercepting the business logic through aspects before the business logic is executed, and obtaining a list of fields to be checked for the input parameters when the method parameters of the business logic include the abstract business object; checking each field in the list of fields to be checked according to the parameter checking rules corresponding to the abstract business object to obtain the input parameter checking result of the business logic.

[0123] According to the technical solution of the embodiment of the present invention, the input parameters of the business logic are received through a predefined abstract business object; the business logic is intercepted through the aspect before the business logic is executed, and when the method parameters of the business logic include the abstract business object, the list of fields to be checked of the input parameters is obtained; according to the parameter verification rules corresponding to the abstract business object, each field in the list of fields to be checked is verified to obtain the input parameter verification result of the business logic. The parameter verification logic does not invade the business code, and the parameter verification logic and the business logic are loosely coupled. When obtaining the list of fields to be checked for the input parameters, and verifying each field in the list of fields to be checked, the customized business methods or rules in the subclass to which the abstract business object belongs can be used, which has good development versatility, reusability, and scalability, and simplifies the development cost and workload of parameter verification.

[0124] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A parameter verification method, characterized in that: include: Receive input parameters of business logic through predefined abstract business objects; intercepting the business logic through a section before the business logic is executed, and when the method parameters of the business logic include the abstract business object, obtaining the list of fields to be checked of the input parameters through the business method in the base class or subclass to which the abstract business object belongs; Verify each field in the list of fields to be verified according to the parameter verification rule corresponding to the abstract business object to obtain the input parameter verification result of the business logic; The step of obtaining the list of fields to be checked of the input parameter through the business method in the base class or subclass to which the abstract business object belongs includes: Calling a custom business method for obtaining verification fields in the subclass to which the abstract business object belongs, so as to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection; The acquired fields are screened according to the self-defined screening rules of the subclass to which the abstract business object belongs, and a list of fields to be checked of the input parameters is obtained according to the screened fields; The step of verifying each field in the list of fields to be verified according to the parameter verification rule corresponding to the abstract business object comprises: According to the custom verification rule in the subclass to which the abstract business object belongs, each field in the list of fields to be verified is verified to see whether it complies with the custom verification rule.

2. The method according to claim 1, characterized in that Before the step of receiving the input parameters of the business logic through the predefined abstract business object, include: Define an abstract service base class, which is the parent class of the subclass to which the abstract service object belongs; The abstract business base class includes a business method for determining whether a parameter is legal, a business method for setting detailed information of illegal parameters, a business method for obtaining a verification field, and a field in a data format for storing information of illegal parameters.

3. The method according to claim 2, characterized in that The step of obtaining the list of fields to be checked of the input parameter through the business method in the base class or subclass to which the abstract business object belongs includes: The business method for obtaining verification fields in the abstract business base class is called to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection, thereby obtaining a list of fields to be verified of the input parameter.

4. The method according to claim 1 or 3, characterized in that: The step of verifying each field in the list of fields to be verified according to the parameter verification rule corresponding to the abstract business object comprises: Calling a business method in the abstract business base class for determining whether a parameter is legal, so as to perform a first check, or perform both the first check and the second check, according to the configuration information in the annotation; Among them, the first check includes: checking whether each field in the list of fields to be checked is empty; the second check includes: checking at least one of the following three of each field: maximum character length, minimum character length, and regular expression.

5. The method according to claim 2, characterized in that: After the step of verifying each field in the list of fields to be verified, the following steps are included: The business method for setting the detailed information of illegal parameters in the abstract business base class is called to record the detailed information of illegal parameters that fail the verification in the field of the data format for storing illegal parameter information.

6. A parameter verification device, characterized in that: include: A receiving module, used for receiving input parameters of business logic through predefined abstract business objects; an acquisition module, used to intercept the business logic through a section before the business logic is executed, and when the method parameters of the business logic include the abstract business object, obtain the list of fields to be checked of the input parameters through the business method in the base class or subclass to which the abstract business object belongs; A verification module, used to verify each field in the to-be-verified field list according to the parameter verification rule corresponding to the abstract business object, so as to obtain the input parameter verification result of the business logic; The acquisition module is also used for: Calling a custom business method for obtaining verification fields in the subclass to which the abstract business object belongs, so as to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection; The acquired fields are screened according to the self-defined screening rules of the subclass to which the abstract business object belongs, and a list of fields to be checked of the input parameters is obtained according to the screened fields; The verification module is also used for: According to the custom verification rule in the subclass to which the abstract business object belongs, each field in the list of fields to be verified is verified to see whether it complies with the custom verification rule.

7. The device according to claim 6, characterized in that It also includes a business base class definition module for: Define an abstract service base class, which is the parent class of the subclass to which the abstract service object belongs; The abstract business base class includes a business method for determining whether a parameter is legal, a business method for setting detailed information of illegal parameters, a business method for obtaining a verification field, and a field in a data format for storing information of illegal parameters.

8. The device according to claim 7, characterized in that The acquisition module is also used for: The business method for obtaining verification fields in the abstract business base class is called to obtain all annotated fields in the subclass to which the abstract business object belongs through JAVA reflection, thereby obtaining a list of fields to be verified of the input parameter.

9. The device according to claim 6 or 8, characterized in that The verification module is also used for: Calling a business method in the abstract business base class for determining whether a parameter is legal, so as to perform a first check, or perform both the first check and the second check, according to the configuration information in the annotation; Among them, the first check includes: checking whether each field in the list of fields to be checked is empty; the second check includes: checking at least one of the following three of each field: maximum character length, minimum character length, and regular expression.

10. The device according to claim 7, characterized in that It also includes an information recording module for: The business method for setting the detailed information of illegal parameters in the abstract business base class is called to record the detailed information of illegal parameters that fail the verification in the field of the data format for storing illegal parameter information.

11. An electronic device, characterized in that: include: one or more processors; a memory 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 are enabled to implement the method according to any one of claims 1 to 5.

12. 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 5 is implemented.

Citation Information

Patent Citations

  • Method for implementing exception framework on the basis of cloud computing

    CN103246514A

  • Software interface parameter validation method

    CN105677326A

  • Method and device for simplifying application program language

    CN106598573A

  • Parameter verification method and device

    CN108132880A