Data verification method, device, computer equipment and storage medium
Patent Information
- Application Number
- CN202010214522.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-24
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2040-03-24
Smart Images

Figure CN111475331B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data verification, and in particular to a data verification method, device, computer equipment and storage medium. Background Art
[0002] In back-end development, it is usually necessary to perform length verification on the field data contained in the database input parameters to prevent the field data from overflowing in length. General databases implement length verification on field data based on back-end Java code. If the field data contains many fields, a large amount of repeated code for length verification of the fields needs to be written to continuously perform if-else judgments on each field in the field data, thereby implementing length verification on the field data. This length verification method requires developers to write complex and redundant code, which is labor-intensive and inefficient. Summary of the invention
[0003] The main purpose of this application is to provide a data verification method, device, computer equipment and storage medium, aiming to solve the technical problems that the existing method of length verification of field data in the database requires developers to write complicated and redundant codes, which is labor-intensive and has low work efficiency.
[0004] The present application proposes a data verification method, which comprises the following steps:
[0005] Create an interface corresponding to the preset custom annotation;
[0006] A max attribute corresponding to the maximum byte length of the field and a message attribute corresponding to the field error are defined in the interface, so as to add the max attribute and the message attribute in the custom annotation to obtain the corresponding target annotation;
[0007] Adding the target annotation in each designated field, wherein the designated field includes field data to be input into the target database, and the number of the designated fields includes one or more;
[0008] According to the target annotation, a length check is performed on each of the designated fields, and a corresponding check result is generated.
[0009] Optionally, the step of performing length verification on each of the designated fields according to the target annotation and generating a corresponding verification result includes:
[0010] Acquire an implementation class of an interface corresponding to the target annotation, and calculate the byte length of a first designated field according to the implementation class of the interface, wherein the first designated field is any one of all the designated fields;
[0011] Determining whether the byte length of the first designated field is less than the maximum byte length;
[0012] If the byte length of the first designated field is less than the maximum byte length, it is determined that the byte length of the first designated field passes the check.
[0013] Optionally, after the step of determining whether the byte length of the first designated field is less than the maximum byte length, the step further includes:
[0014] If the byte length of the first designated field is greater than the maximum byte length, it is determined that the byte length of the first designated field fails to pass the verification, and error description information corresponding to the first designated field is generated;
[0015] Performing a marking process on the first designated field to obtain a marked first designated field;
[0016] The first designated field after the mark and the error description information are displayed.
[0017] Optionally, the step of obtaining an implementation class of an interface corresponding to the target annotation and calculating the byte length of the first designated field according to the implementation class of the interface includes:
[0018] Parsing the target annotation to obtain the implementation class of the interface;
[0019] Input the implementation class of the interface into a pre-created virtual processor to obtain the logic of the target annotation;
[0020] The byte length of the first designated field is calculated according to the logic of the target annotation.
[0021] Optionally, the step of inputting the implementation class of the interface into a pre-created virtual processor to obtain the logic of the target annotation includes:
[0022] Loading the implementation class of the interface through the class loader in the virtual processor;
[0023] After successfully loading the implementation class of the interface, obtaining an instance of the target annotation from the implementation class of the interface;
[0024] According to the instance of the target annotation, the logic of the target annotation is obtained through the Java reflection mechanism.
[0025] Optionally, the step of calculating the byte length of the first designated field according to the logic of the target annotation includes:
[0026] According to the logic of the target annotation, determining whether there are Chinese characters in the first designated field, wherein the number of the Chinese characters includes one or more;
[0027] If yes, obtain the encoding method corresponding to the Chinese character;
[0028] According to the encoding method, calling the Java bytecode algorithm to calculate the first byte length of the Chinese character;
[0029] Filter out other characters except the Chinese characters in the first designated field, and calculate the second character length corresponding to the other characters;
[0030] The sum of the first byte length and the second character length is calculated to obtain the byte length of the first designated field.
[0031] Optionally, after the step of obtaining the implementation class of the interface corresponding to the target annotation and calculating the byte length of the first designated field according to the implementation class of the interface, the method further comprises:
[0032] Obtaining the byte length of each of the first specified fields;
[0033] Calculate the sum of the byte lengths of all the designated characters according to the byte length of each of the first designated fields;
[0034] Determine whether the sum of the byte lengths is greater than a preset standard length threshold;
[0035] If the sum of the byte lengths is greater than a preset standard length threshold, abnormal information corresponding to the specified character is generated and displayed.
[0036] The present application also provides a data verification device, comprising:
[0037] Create a module to create an interface corresponding to the preset custom annotation;
[0038] A definition module, used to define a max attribute corresponding to the maximum byte length of a field and a message attribute corresponding to a field error in the interface, so as to add the max attribute and the message attribute in the custom annotation to obtain a corresponding target annotation;
[0039] An adding module, used for adding the target annotation in each designated field, wherein the designated field includes field data to be input into the target database, and the number of the designated fields includes one or more;
[0040] The verification module is used to perform length verification processing on each of the specified fields according to the target annotation and generate a corresponding verification result.
[0041] The present application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0042] The present application also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0043] The data verification method, device, computer equipment and storage medium provided in this application have the following beneficial effects:
[0044] The data verification method, device, computer equipment and storage medium provided in the present application create an interface corresponding to a preset custom annotation; define a max attribute corresponding to the maximum byte length of the field and a message attribute corresponding to the field error in the interface, so as to add the max attribute and the message attribute in the custom annotation to obtain the corresponding target annotation; add the target annotation in each specified field, wherein the specified field includes field data to be input into the target database, and the number of the specified fields includes one or more; according to the target annotation, perform length verification processing on each of the specified fields, and generate corresponding verification results. The present application adds the generated target annotation to each specified field that needs to be input into the target database, so as to quickly and conveniently perform length verification processing on each of the above-mentioned specified fields according to the above-mentioned target annotation, thereby avoiding the writing and use of a large number of judgment codes for field length verification that are repeated but cannot be abstractly reused, effectively improving the efficiency of length verification of the specified field, and reducing the verification workload of length verification of the specified field. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 It is a flowchart of a data verification method according to an embodiment of the present application;
[0046] Figure 2 It is a structural schematic diagram of a data verification device according to an embodiment of the present application;
[0047] Figure 3 It is a schematic diagram of the structure of a computer device according to an embodiment of the present application.
[0048] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0049] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0050] It should be noted that all directional indications in the embodiments of the present application (such as up, down, left, right, front, back, etc.) are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly. The connection can be a direct connection or an indirect connection.
[0051] Reference Figure 1 , a data verification method according to an embodiment of the present application includes:
[0052] S1: Create an interface corresponding to the preset custom annotation;
[0053] S2: defining a max attribute corresponding to the maximum byte length of the field and a message attribute corresponding to the field error in the interface, so as to add the max attribute and the message attribute in the custom annotation to obtain the corresponding target annotation;
[0054] S3: adding the target annotation in each designated field, wherein the designated field includes field data to be input into the target database, and the number of the designated fields includes one or more;
[0055] S4: According to the target annotation, a length check is performed on each of the designated fields, and a corresponding check result is generated.
[0056] As described in the above steps S1 to S4, the execution subject of the embodiment of the present method is a data verification device. In practical applications, the data verification device can be implemented by a virtual device, such as a software code, or by a physical device written or integrated with relevant execution codes, and can interact with customers through keyboards, mice, remote controls, touch pads or voice control devices. The data verification device provided in this embodiment can accurately implement the length verification of the field to be input into the target database, thereby effectively preventing the target database from overflowing the data length. Specifically, first create an interface corresponding to a preset custom annotation. Among them, the above custom annotation can be an annotation template written by a developer according to the actual need to verify the length of the field and input into the data verification device, and the custom annotation does not include interface information. In addition, the name of the above interface can be specifically ByteLength. Then define the max attribute corresponding to the maximum byte length of the field and the message attribute corresponding to the field error in the above interface to achieve the addition of the above max attribute and the above message attribute in the above custom annotation to obtain the corresponding target annotation. Among them, the above-mentioned max attribute is used to store the maximum byte length of the field that needs to be length-checked, and the above-mentioned message attribute is used to store the error code or error description information corresponding to the field error. In addition, the above-mentioned maximum byte length can be set according to actual needs, and is not specifically limited here. For example, it can be set to 30. After obtaining the above-mentioned target annotation, the above-mentioned target annotation will be added to each specified field. Among them, the above-mentioned specified field refers to the field data to be input into the target database, the number of the above-mentioned specified fields includes one or more, and the above-mentioned target database can be specifically an Oracle database. Finally, according to the above-mentioned target annotation, each of the above-mentioned specified fields is length-checked and a corresponding verification result is generated. Among them, when the above-mentioned target annotation is added to each specified field, the target annotation will automatically take effect, and the corresponding length verification processing will be performed on each specified field according to the logic of the target annotation and the verification result will be obtained. This embodiment adds the generated target annotation to each specified field to quickly and conveniently perform length verification on each of the above specified fields according to the above target annotation, avoiding the writing and use of a large number of repeated but non-abstract and reused judgment codes for field length verification, effectively improving the efficiency of the length verification of the specified field and reducing the verification workload of the length verification of the specified field.
[0057] Furthermore, in one embodiment of the present application, the above step S4 includes:
[0058] S40: Acquire an implementation class of an interface corresponding to the target annotation, and calculate the byte length of a first designated field according to the implementation class of the interface, wherein the first designated field is any one of all the designated fields;
[0059] S41: Determine whether the byte length of the first designated field is less than the maximum byte length;
[0060] S42: If the byte length of the first designated field is less than the maximum byte length, determine that the byte length of the first designated field passes the check.
[0061] As described in the above steps S40 to S42, the above step of performing length verification processing on each of the above designated fields according to the above target annotation and generating the corresponding verification result may specifically include: first obtaining the implementation class of the interface corresponding to the target annotation, and calculating the byte length of the first designated field according to the implementation class of the above interface, wherein the above first designated field is any one of all the above designated fields. In addition, the logic of the above target annotation can be obtained according to the implementation class of the above interface, and then the byte length of the first designated field is calculated using the Java bytecode algorithm according to the logic of the target annotation. After obtaining the byte length of the above first designated field, it is determined whether the byte length of the above first designated field is less than the above maximum byte length. If it is less than the above maximum byte length, it indicates that the first designated field does not have a byte length overflow, and then a verification result can be obtained to determine that the byte length of the above first designated field passes the verification.
[0062] Furthermore, in an embodiment of the present application, after the above step S41, the following steps are included:
[0063] S43: If the byte length of the first designated field is greater than the maximum byte length, determine that the byte length of the first designated field fails to pass the check, and generate error description information corresponding to the first designated field;
[0064] S44: marking the first designated field to obtain a marked first designated field;
[0065] S45: Display the first designated field after the mark and the error description information.
[0066] As described in the above steps S43 to S45, in the process of determining whether the byte length of the above-mentioned first designated field is less than the above-mentioned maximum byte length, there may also be a special case where the byte length of the first designated field is greater than the above-mentioned maximum byte length. In this case, a corresponding error reporting process will be performed for this special case. Specifically, if the byte length of the above-mentioned first designated field is greater than the above-mentioned maximum byte length, indicating that the byte length of the first designated field has overflowed, a verification result will be generated to determine that the byte length of the above-mentioned first designated field has not passed the verification, and an error description information corresponding to the first designated field will be generated. Among them, the above-mentioned error description information can be generated by calling the e.getBindingResult().getFieldError().getDefaultMessage() method. Then, the above-mentioned first designated field is marked to obtain the marked first designated field. Among them, the above-mentioned marked first designated field with an exception can be thrown by calling the e.getBindingResult().getFieldError().getField() method. Finally, the first designated field after the above mark and the above error description information are displayed so that the user can clearly know the abnormal field that failed the check and the corresponding error description information, and it is convenient for the user to perform corresponding repair processing on the abnormal field in the case of byte length overflow.
[0067] Furthermore, in an embodiment of the present application, the above step S40 includes:
[0068] S400: Parse the target annotation to obtain the implementation class of the interface;
[0069] S401: Input the implementation class of the interface into a pre-created virtual processor to obtain the logic of the target annotation;
[0070] S402: Calculate the byte length of the first designated field according to the logic of the target annotation.
[0071] As described in the above steps S400 to S402, the above step of obtaining the implementation class of the interface corresponding to the target annotation and calculating the byte length of the first designated field according to the implementation class of the interface may specifically include: first, the target annotation may be parsed to obtain the implementation class of the interface, so as to realize the detailed parsing of the target annotation, and facilitate the subsequent further length verification processing of the first designated field. Then the implementation class of the interface is input into the pre-created virtual processor to obtain the logic of the target annotation. Among them, the virtual processor has the function corresponding to the Java reflection mechanism, so that the logic of the target annotation can be obtained. Finally, the field length of the first designated field can be calculated according to the logic of the target annotation, so that the field length of the first designated field can be verified according to the maximum byte length corresponding to the max attribute, and then an accurate verification result can be obtained. In this embodiment, the logic of the target annotation is obtained by a pre-built virtual processor, and then the length verification processing of the designated field is realized by the logic of the target annotation, without writing a large amount of repeated code for length verification processing of the designated field, which reduces the development difficulty and greatly reduces the workload of developers.
[0072] Furthermore, in an embodiment of the present application, the above step S401 includes:
[0073] S4010: Loading the implementation class of the interface through the class loader in the virtual processor;
[0074] S4011: after successfully loading the implementation class of the interface, obtaining an instance of the target annotation from the implementation class of the interface;
[0075] S4012: According to the instance of the target annotation, the logic of the target annotation is obtained through the Java reflection mechanism.
[0076] As described in the above steps S4010 to S4012, the above Java reflection mechanism is in the running state, for any class, all the properties and methods of this class can be known; for any object, any method and property of it can be called; this dynamically obtained information and the function of dynamically calling the method of the object are called the reflection mechanism of the Java language. The above step of inputting the implementation class of the above interface into the pre-created virtual processor to obtain the logic of the above target annotation may specifically include: firstly, the implementation class of the above interface is loaded by the class loader in the above virtual processor, wherein the class name string of the implementation class of the above interface is in the full name form, that is, the package name + class name. Then, after successfully loading the implementation class of the interface, the instance of the target annotation is obtained from the implementation class of the interface, wherein the instance of the target annotation can be obtained from the implementation class of the above interface through the isAnnotationPresent method, and the above isAnnotationPresent method is the calling object method under the interface corresponding to the implementation class of the above interface. Finally, according to the instance of the above target annotation, the logic of the above target annotation is obtained through the Java reflection mechanism, that is, the logic of the target annotation is obtained in the DAO layer, so that the byte length of the above first specified field can be accurately calculated according to the logic of the target annotation. Therefore, the field length of the first specified field can be quickly and conveniently verified according to the maximum byte length corresponding to the above max attribute, and then an accurate verification result can be obtained, avoiding the writing of a large amount of repetitive code for length verification of the specified field, which greatly reduces the workload of developers.
[0077] In one embodiment of the present application, the above step S402 includes:
[0078] S4020: judging whether there are Chinese characters in the first designated field according to the logic of the target annotation, wherein the number of the Chinese characters includes one or more;
[0079] S4021: If yes, obtain the encoding method corresponding to the Chinese character;
[0080] S4022: According to the encoding method, calling a Java bytecode algorithm to calculate the first byte length of the Chinese character;
[0081] S4023: Filter out other characters except the Chinese characters in the first designated field, and calculate the second character length corresponding to the other characters;
[0082] S4024: Calculate the sum of the first byte length and the second character length to obtain the byte length of the first designated field.
[0083] As described in steps S4020 to S4024, there may be multiple types of characters in the first designated field, such as Chinese characters, English characters, etc. The step of calculating the byte length of the first designated field according to the logic of the target annotation may specifically include: first, judging whether there are Chinese characters in the first designated field according to the logic of the target annotation, wherein the number of the Chinese characters includes one or more. If there are Chinese characters in the first designated field, the encoding method corresponding to the Chinese characters is obtained. The encoding method may specifically include UTF-8 encoding method, unicode encoding method or GBK encoding method. Then, according to the encoding method, the Java bytecode algorithm is called to calculate the first byte length of the Chinese characters. According to the Java bytecode algorithm, one Chinese character in the UTF-8 encoding method corresponds to 3 bytes, and one Chinese character in the unicode encoding method or GBK encoding method corresponds to 2 bytes. For example, if the first designated field contains 2 Chinese characters in the UTF-8 encoding method and 1 Chinese character in the GBK encoding method, the first byte length can be calculated to be 2*3+2=8. After calculating the first byte length, select characters other than the Chinese characters in the first designated field, and calculate the second character length corresponding to the characters other than the Chinese characters. Finally, calculate the sum of the first byte length and the second character length to obtain the byte length of the first designated field. This embodiment can call the logic of the target annotation, i.e., Java's bytecode algorithm, based on the Chinese characters in the first designated field to accurately calculate the first byte length corresponding to the Chinese characters in the first designated field and the second character length corresponding to other characters, and then accurately calculate the byte length of the first designated field, so that the field length of the first designated field can be accurately verified later, effectively improving the accuracy of the generated verification result.
[0084] Furthermore, in an embodiment of the present application, after the above step S40, the following steps are included:
[0085] S46: Obtain the byte length of each of the first designated fields;
[0086] S47: Calculate the sum of the byte lengths of all the designated characters according to the byte length of each of the first designated fields;
[0087] S48: Determine whether the sum of the byte lengths is greater than a preset standard length threshold;
[0088] S49: If the total byte length is greater than a preset standard length threshold, abnormal information corresponding to the specified character is generated and displayed.
[0089] As described in the above steps S46 to S49, after completing the calculation of the byte length of each first designated field, it is necessary to further verify whether the character data to be input into the target database, that is, whether the sum of the byte lengths of all the above first designated fields will exceed the maximum standard length defined by the target database table, so as to ensure that the character data subsequently input into the target database can operate normally in the target database. Specifically, first obtain the byte length of each of the first designated fields, and calculate the sum of the byte lengths of all the above designated characters according to the byte length of each of the above first designated fields. Then determine whether the sum of the byte lengths is greater than the preset standard length threshold. Among them, the preset standard length threshold can be the maximum standard length defined by the target database table in the target database that the first designated field needs to enter, for example, it can be set to 4000. If the sum of the byte lengths is greater than the preset standard length threshold, an abnormal information corresponding to the specified character will be generated and displayed, wherein the abnormal information is specifically information that the sum of the byte lengths of all the above designated characters has overflowed in length compared with the standard length threshold. By displaying the abnormal information to the user, the user can clearly know the abnormal situation of the above-mentioned specified characters, so that the user can perform corresponding repair processing according to the abnormal situation later.
[0090] Reference Figure 2 In one embodiment of the present application, a data verification device is also provided, including:
[0091] Create module 1, used to create an interface corresponding to the preset custom annotation;
[0092] Definition module 2, used to define in the interface a max attribute corresponding to the maximum byte length of the field and a message attribute corresponding to the field error, so as to add the max attribute and the message attribute in the custom annotation to obtain the corresponding target annotation;
[0093] An adding module 3, used for adding the target annotation in each designated field, wherein the designated field includes field data to be input into the target database, and the number of the designated fields includes one or more;
[0094] The verification module 4 is used to perform length verification processing on each of the specified fields according to the target annotation and generate a corresponding verification result.
[0095] In this embodiment, the implementation process of the functions and effects of the creation module, definition module, addition module and verification module in the above-mentioned data verification device is specifically described in the implementation process of the corresponding steps S1 to S4 in the above-mentioned data verification method, and will not be repeated here.
[0096] Furthermore, in one embodiment of the present application, the verification module includes:
[0097] A first acquisition submodule is used to acquire an implementation class of an interface corresponding to the target annotation, and calculate a byte length of a first designated field according to the implementation class of the interface, wherein the first designated field is any one of all the designated fields;
[0098] A first judging submodule, used to judge whether the byte length of the first designated field is less than the maximum byte length;
[0099] The first determination submodule is used to determine whether the byte length of the first designated field passes the verification if the byte length of the first designated field is less than the maximum byte length.
[0100] In this embodiment, the implementation process of the functions and effects of the first acquisition submodule, the first judgment submodule and the first determination submodule in the above-mentioned data verification device is specifically described in the implementation process of the corresponding steps S40 to S42 in the above-mentioned data verification method, and will not be repeated here.
[0101] Furthermore, in one embodiment of the present application, the verification module includes:
[0102] a second determination submodule, configured to determine that the byte length of the first designated field fails to pass the check if the byte length of the first designated field is greater than the maximum byte length, and to generate error description information corresponding to the first designated field;
[0103] a marking submodule, configured to mark the first designated field to obtain a marked first designated field;
[0104] The first display submodule is used to display the first designated field after the mark and the error description information.
[0105] In this embodiment, the implementation process of the functions and effects of the second determination submodule, the marking submodule and the first display submodule in the above-mentioned data verification device is specifically described in the implementation process of the corresponding steps S43 to S45 in the above-mentioned data verification method, and will not be repeated here.
[0106] Furthermore, in one embodiment of the present application, the first acquisition submodule includes:
[0107] A parsing unit, used for parsing the target annotation to obtain an implementation class of the interface;
[0108] An input unit, used to input the implementation class of the interface into a pre-created virtual processor to obtain the logic of the target annotation;
[0109] A calculation unit is used to calculate the byte length of the first designated field according to the logic of the target annotation.
[0110] In this embodiment, the implementation process of the functions and effects of the parsing unit, input unit and calculation unit in the above-mentioned data verification device is specifically detailed in the implementation process of the corresponding steps S400 to S402 in the above-mentioned data verification method, and will not be repeated here.
[0111] Furthermore, in one embodiment of the present application, the input unit includes:
[0112] A loading subunit, used for loading the implementation class of the interface through the class loader in the virtual processor;
[0113] A first acquisition subunit is used to acquire an instance of the target annotation from the implementation class of the interface after successfully loading the implementation class of the interface;
[0114] The second acquisition subunit is used to acquire the logic of the target annotation through the Java reflection mechanism according to the instance of the target annotation.
[0115] In this embodiment, the implementation process of the functions and effects of the loading subunit, the first acquisition subunit and the second acquisition subunit in the above-mentioned data verification device is specifically described in the implementation process of the corresponding steps S4010 to S4012 in the above-mentioned data verification method, and will not be repeated here.
[0116] Furthermore, in one embodiment of the present application, the above-mentioned calculation unit includes:
[0117] a judgment subunit, configured to judge whether Chinese characters exist in the first designated field according to the logic of the target annotation, wherein the number of the Chinese characters includes one or more;
[0118] A third acquisition subunit is used to obtain the encoding method corresponding to the Chinese character;
[0119] A first calculation subunit, configured to calculate the first byte length of the Chinese character by calling a Java bytecode algorithm according to the encoding method;
[0120] a second calculating subunit, configured to filter out other characters except the Chinese characters in the first designated field, and calculate a second character length corresponding to the other characters;
[0121] The third calculation subunit is used to calculate the sum of the first byte length and the second character length to obtain the byte length of the first designated field.
[0122] In this embodiment, the implementation process of the functions and effects of the judgment subunit, the third acquisition subunit, the first calculation subunit, the second calculation subunit and the third calculation subunit in the above-mentioned data verification device is specifically described in the implementation process of the corresponding steps S4020 to S4024 in the above-mentioned data verification method, and will not be repeated here.
[0123] Furthermore, in one embodiment of the present application, the verification module includes:
[0124] A second acquisition submodule, used to acquire the byte length of each of the first specified fields;
[0125] A calculation submodule, used for calculating the sum of the byte lengths of all the designated characters according to the byte length of each of the first designated fields;
[0126] A second judgment submodule is used to judge whether the sum of the byte lengths is greater than a preset standard length threshold;
[0127] The second display submodule is used to generate and display abnormal information corresponding to the specified character if the total byte length is greater than a preset standard length threshold.
[0128] In this embodiment, the implementation process of the functions and effects of the second acquisition submodule, calculation submodule, second judgment submodule and second display submodule in the above-mentioned data verification device is specifically described in the implementation process of the corresponding steps S46 to S49 in the above-mentioned data verification method, and will not be repeated here.
[0129] Reference Figure 3 In an embodiment of the present application, a computer device is also provided. The computer device may be a server, and its internal structure may be as follows: Figure 3 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor designed for the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as custom annotations, max attributes, message attributes and target annotations. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a data verification method is implemented.
[0130] The above processor executes the steps of the above data verification method:
[0131] Create an interface corresponding to the preset custom annotation;
[0132] A max attribute corresponding to the maximum byte length of the field and a message attribute corresponding to the field error are defined in the interface, so as to add the max attribute and the message attribute in the custom annotation to obtain the corresponding target annotation;
[0133] Adding the target annotation in each designated field, wherein the designated field includes field data to be input into the target database, and the number of the designated fields includes one or more;
[0134] According to the target annotation, a length check is performed on each of the designated fields, and a corresponding check result is generated.
[0135] Those skilled in the art will understand that Figure 3 The structure shown in is merely a block diagram of a portion of the structure related to the present application scheme, and does not constitute a limitation on the devices and computer equipment to which the present application scheme is applied.
[0136] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, a data verification method is implemented, specifically:
[0137] Create an interface corresponding to the preset custom annotation;
[0138] A max attribute corresponding to the maximum byte length of the field and a message attribute corresponding to the field error are defined in the interface, so as to add the max attribute and the message attribute in the custom annotation to obtain the corresponding target annotation;
[0139] Adding the target annotation in each designated field, wherein the designated field includes field data to be input into the target database, and the number of the designated fields includes one or more;
[0140] According to the target annotation, a length check is performed on each of the designated fields, and a corresponding check result is generated.
[0141] In summary, the data verification method, device, computer equipment and storage medium provided in the embodiments of the present application create an interface corresponding to a preset custom annotation; define a max attribute corresponding to the maximum byte length of the field and a message attribute corresponding to the field error in the interface to implement adding the max attribute and the message attribute in the custom annotation to obtain the corresponding target annotation; add the target annotation in each specified field, wherein the specified field includes field data to be input into the target database, and the number of the specified fields includes one or more; according to the target annotation, perform length verification processing on each of the specified fields and generate corresponding verification results. The embodiment of the present application adds the generated target annotation to each specified field that needs to be input into the target database, so as to realize quick and convenient length verification processing on each of the above specified fields according to the above target annotation, avoids the writing and use of a large number of repeated but non-abstract and reused judgment codes for field length verification, effectively improves the efficiency of length verification of the specified field, and reduces the verification workload of length verification of the specified field.
[0142] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0143] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.
[0144] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A data verification method, characterized in that: include: Create an interface corresponding to the preset custom annotation; A max attribute corresponding to the maximum byte length of the field and a message attribute corresponding to the field error are defined in the interface, so as to add the max attribute and the message attribute in the custom annotation to obtain the corresponding target annotation; the max attribute is used to store the maximum byte length of the field that needs to be length-checked, and the message attribute is used to store the error code or error description information corresponding to the field error; Adding the target annotation in each designated field, wherein the designated field includes field data to be input into the target database, and the number of the designated fields includes one or more; According to the target annotation, a length check is performed on each of the specified fields, and a corresponding check result is generated; The step of performing length verification processing on each of the designated fields according to the target annotation and generating a corresponding verification result includes: Acquire an implementation class of an interface corresponding to the target annotation, and calculate the byte length of a first designated field according to the implementation class of the interface, wherein the first designated field is any one of all the designated fields; Determining whether the byte length of the first designated field is less than the maximum byte length; If the byte length of the first designated field is less than the maximum byte length, determining that the byte length of the first designated field passes verification; The step of obtaining the implementation class of the interface corresponding to the target annotation and calculating the byte length of the first designated field according to the implementation class of the interface includes: Parsing the target annotation to obtain the implementation class of the interface; Input the implementation class of the interface into a pre-created virtual processor to obtain the logic of the target annotation; Calculate the byte length of the first designated field according to the logic of the target annotation; The step of calculating the byte length of the first designated field according to the logic of the target annotation comprises: According to the logic of the target annotation, determining whether there are Chinese characters in the first designated field, wherein the number of the Chinese characters includes one or more; If yes, obtain the encoding method corresponding to the Chinese character; According to the encoding method, calling the Java bytecode algorithm to calculate the first byte length of the Chinese character; Filter out other characters except the Chinese characters in the first designated field, and calculate the second character length corresponding to the other characters; The sum of the first byte length and the second character length is calculated to obtain the byte length of the first designated field.
2. The data verification method according to claim 1, characterized in that: After the step of determining whether the byte length of the first designated field is less than the maximum byte length, the method further comprises: If the byte length of the first designated field is greater than the maximum byte length, it is determined that the byte length of the first designated field fails to pass the verification, and error description information corresponding to the first designated field is generated; Performing a marking process on the first designated field to obtain a marked first designated field; The first designated field after the mark and the error description information are displayed.
3. The data verification method according to claim 1, characterized in that: The step of inputting the implementation class of the interface into a pre-created virtual processor to obtain the logic of the target annotation includes: Loading the implementation class of the interface through the class loader in the virtual processor; After successfully loading the implementation class of the interface, obtaining an instance of the target annotation from the implementation class of the interface; According to the instance of the target annotation, the logic of the target annotation is obtained through the Java reflection mechanism.
4. The data verification method according to claim 1, characterized in that: After the step of obtaining the implementation class of the interface corresponding to the target annotation and calculating the byte length of the first designated field according to the implementation class of the interface, the method further comprises: Obtaining the byte length of each of the first specified fields; Calculate the total byte length of all the designated fields according to the byte length of each of the first designated fields; Determine whether the sum of the byte lengths is greater than a preset standard length threshold; If the sum of the byte lengths is greater than a preset standard length threshold, abnormal information corresponding to the specified field is generated and displayed.
5. A data verification device, characterized in that: include: Create a module to create an interface corresponding to the preset custom annotation; A definition module, used to define a max attribute corresponding to the maximum byte length of a field and a message attribute corresponding to a field error in the interface, so as to add the max attribute and the message attribute in the custom annotation to obtain a corresponding target annotation; the max attribute is used to store the maximum byte length of the field that needs to be length-checked, and the message attribute is used to store an error code or error description information corresponding to the field error; An adding module, used for adding the target annotation in each designated field, wherein the designated field includes field data to be input into the target database, and the number of the designated fields includes one or more; A verification module, used to perform length verification processing on each of the specified fields according to the target annotation, and generate a corresponding verification result; The verification module comprises: A first acquisition submodule is used to acquire an implementation class of an interface corresponding to the target annotation, and calculate a byte length of a first designated field according to the implementation class of the interface, wherein the first designated field is any one of all the designated fields; A first judging submodule, used to judge whether the byte length of the first designated field is less than the maximum byte length; A first determination submodule, configured to determine that the byte length of the first designated field passes verification if the byte length of the first designated field is less than the maximum byte length; The first acquisition submodule includes: A parsing unit, used for parsing the target annotation to obtain an implementation class of the interface; An input unit, used to input the implementation class of the interface into a pre-created virtual processor to obtain the logic of the target annotation; a calculation unit, configured to calculate the byte length of the first designated field according to the logic of the target annotation; The computing unit comprises: a judgment subunit, configured to judge whether Chinese characters exist in the first designated field according to the logic of the target annotation, wherein the number of the Chinese characters includes one or more; A third acquisition subunit is used to acquire the encoding method corresponding to the Chinese character if the Chinese character exists in the first designated field; A first calculation subunit is used to calculate the first byte length of the Chinese character by calling a Java bytecode algorithm according to the encoding method; a second calculating subunit, configured to filter out other characters except the Chinese characters in the first designated field, and calculate a second character length corresponding to the other characters; The third calculation subunit is used to calculate the sum of the first byte length and the second character length to obtain the byte length of the first designated field.
6. A computer device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
7. A storage medium having a computer program stored thereon, characterized in that: The computer program When the program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
