A management method, system, device and storage medium for a JavaBean validation class
Through custom annotations and global attribute management, a unified verification interface and interface is generated, the problem of dispersed JavaBean verification rules is solved, and efficient communication between fast viewing and front-end data verification is achieved.
Patent Information
- Application Number
- CN202211049541.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-30
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2042-08-30
AI Technical Summary
When using Spring Boot for web project development, JavaBean verification rules are spread across multiple modules, making it difficult for developers to quickly find and verify, and the Controller cannot meet the need to only perform data verification without performing other operations.
Custom annotations specify package paths and JavaBean objects, scan and save verification specifications into global properties, generate a unified verification interface, and dynamically create object verification interface through the interface, supporting front-end data verification.
It improves the communication efficiency of front-end developers, facilitates and quickly views the verification rules of JavaBean objects, and avoids the problem of the verification rules not taking effect.
Smart Images

Figure CN115390814B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more specifically, to a management method, system, device and storage medium for JavaBean validation classes. Background Art
[0002] When developing a Web project using Spring Boot, it is necessary to ensure that the data input by the user is semantically correct by some means. In development, the Hibernate Validator dependency package is usually introduced to validate the attributes in the JavaBean. However, as the project code continues to increase, the number of JavaBeans to be validated is increasing, and they may be distributed in multiple modules, resulting in difficulty in finding the validation rules of a certain JavaBean when the user views them.
[0003] In the prior art, developers need to manually search for the specified JavaBean class in multiple modules and view the validation rules of each of its attributes. However, this method requires developers to know the locations of all the involved JavaBeans. In addition, there is no specific location to provide validation for the passing value format of the JavaBean, and it can only be verified through the implemented Controller interface. However, when developers only want to check whether the data passed by the front end can pass the validation and do not want to perform other operations, the Controller cannot meet the requirements. Summary of the Invention
[0004] Aiming at the above problems, the purpose of the present invention is to provide a management method, system, device and storage medium for JavaBean validation classes, which can uniformly process all JavaBean objects to be validated, facilitating developers to quickly view the JavaBean objects to be validated and their attribute specifications, and improving the communication efficiency between front-end and back-end developers.
[0005] To achieve the above object, the present invention is realized through the following technical solutions: A management method for JavaBean validation classes includes:
[0006] Define custom annotations to specify the package path to be scanned and the JavaBean objects to be scanned;
[0007] When the Spring Boot project starts, scan all JavaBean objects to be checked and the specified validation specifications on each of their attributes, and save them to global attributes;
[0008] Scan all Controller classes, obtain all interface information related to JavaBean objects, and save them to global attributes;
[0009] Obtain all JavaBean objects to be verified from the global attributes and generate a unified verification interface for them; generate an interface display interface and dynamically create an object verification interface according to the JavaBean object information.
[0010] Furthermore, the custom annotation is used to specify the package path to be scanned and the JavaBean objects to be scanned, including:
[0011] Custom annotations @EnableValidCheck and @ValidCheck, @EnableValidCheck is used to specify the package scanning path of the JavaBean class to be verified, and @ValidCheck is used to mark the JavaBean objects that are expected to be subject to verification management;
[0012] Apply the custom annotation to the specified positions respectively.
[0013] Furthermore, when the Spring Boot project starts, scan all JavaBean objects to be checked and the verification specifications specified on each of their attributes, and save them to the global attributes, including: When the Spring Boot project starts, obtain the basePackages value specified in the @EnableValidCheck annotation in the specific implementation class of ImportBeanDefinitionRegistrar. If no basePackages information is specified, use the package where the class referenced by @EnableValidCheck is located as the root path to be scanned;
[0014] Scan all JavaBean classes annotated with the @ValidCheck annotation in the specified package, and use the reflection mechanism to obtain all fields of the JavaBean object and the Bean Validation annotation information on each field, and save them to the global attributes.
[0015] Furthermore, scan all Controller classes, obtain all interface information related to JavaBean objects, and save them to the global attributes, including:
[0016] In a Spring Boot project, obtain the custom basePackages value in the @ComponentScan annotation, scan all classes annotated with the Controller or RestController annotation, and use the reflection mechanism to obtain all methods defined in the class with the @RequestMapping, @GetMapping, or @PostMapping annotation; use the reflection mechanism to obtain the parameter information on the method, find all JavaBean classes that have been recorded in the global attributes, and record whether the @Valid or @Validated information and the mapped URL address information are added to the method in the global attributes.
[0017] Furthermore, obtaining all JavaBean objects to be verified from the global attributes and generating a unified verification interface for them includes:
[0018] Use a unified @RequestMappingURL path for each JavaBean object to be verified stored in the global attributes, with the received value type being Map, and convert the Map to the corresponding Entity object according to the entity attribute during the request process;
[0019] Use the javax.validation.Validator to verify the data passed from the front end through programmatic verification and return the verification result.
[0020] Furthermore, generating the interface display interface and dynamically creating the object verification interface according to the JavaBean object information includes:
[0021] Dynamically generate the verification interface, generate the description and specification of the interface for each JavaBean object according to the storage result in the global attributes, and display the call interface of each JavaBean object and whether it has added the verification annotation at the same time.
[0022] Furthermore, the description and specification of the interface include: interface description information, field verification specification information, call interface information of the JavaBean object, and information on whether the @Valid or @Validated annotation is added.
[0023] Correspondingly, the present invention also discloses a management system for JavaBean verification classes, including:
[0024] A definition module for customizing annotations to specify the package path to be scanned and the JavaBean objects to be scanned;
[0025] An object scanning module, which is used to scan all JavaBean objects that need to be checked and the specified verification specifications on each of their attributes when the Spring Boot project starts, and save them into global attributes;
[0026] A class scanning module, which is used to scan all Controller classes, obtain all interface information related to JavaBean objects, and save them into global attributes;
[0027] An interface generation module, which is used to obtain all JavaBean objects to be verified from global attributes and generate a unified verification interface for them;
[0028] An interface creation module, which is used to generate an interface display interface and dynamically create an object verification interface according to JavaBean object information.
[0029] Correspondingly, the present invention discloses a management device for JavaBean verification classes, including:
[0030] A memory, which is used to store a management program for JavaBean verification classes;
[0031] A processor, which is used to implement the steps of the management method for JavaBean verification classes as described in any one of the above when executing the management program for JavaBean verification classes.
[0032] Correspondingly, the present invention discloses a readable storage medium, on which a management program for JavaBean verification classes is stored, and when the management program for JavaBean verification classes is executed by a processor, it implements the steps of the management method for JavaBean verification classes as described in any one of the above.
[0033] Compared with the prior art, the beneficial effects of the present invention are as follows: The present invention discloses a management method, system, device and storage medium for JavaBean verification classes, which can dynamically obtain all JavaBean objects that need to be verified, and generate verification interfaces for them respectively, so as to facilitate users to view the verification rules of all classes to be verified, and provide a way to directly verify the data correctness through the page interface. In addition, by scanning the interfaces that call JavaBean objects in all Controller classes, it can be checked whether verification annotations are added to the object when it is used, preventing the problem that the verification rules do not take effect.
[0034] The present invention uniformly processes all JavaBean objects to be verified, which can facilitate developers to quickly view the JavaBean objects to be verified and the specification of their attributes, and improve the communication efficiency between front-end and back-end developers. By scanning the interfaces of the corresponding JavaBean objects in the Controller class, it is possible to avoid the error that back-end developers forget to verify the JavaBean during the process of calling the JavaBean.
[0035] Thus, compared with the prior art, the present invention has prominent substantive features and significant progress, and the beneficial effects of its implementation are also obvious. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained according to the provided drawings.
[0037] Figure 1 It is a flowchart of the method for the specific implementation manner of the present invention.
[0038] Figure 2 It is a system structure diagram of the specific implementation manner of the present invention.
[0039] In the figure, 1, definition module; 2, object scanning module; 3, class scanning module; 4, interface generation module; 5, interface creation module. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0040] The core of the present invention is to provide a management method for JavaBean verification classes. In the prior art, developers need to manually search for the specified JavaBean classes in multiple modules and view the verification rules for each of their attributes. However, this method requires developers to know the locations of all the involved JavaBeans. In addition, there is no specific location to provide verification for the value passing format of the JavaBean, and it can only be verified through the implemented Controller interfaces. However, when developers only want to check whether the data passed from the front end can pass the verification and do not want to perform other operations, the Controller cannot meet the requirements.
[0041] The management method of the JavaBean verification class provided by the present invention is as follows. First, custom annotations are defined to specify the package path to be scanned and the JavaBean objects to be scanned. Then, when the Spring Boot project starts, all the JavaBean objects to be checked and the verification specifications specified on each of their attributes are scanned and saved in the global attributes. At the same time, all Controller classes are scanned to obtain all the interface information related to the JavaBean objects and save it in the global attributes. After the saving is completed, all the JavaBean objects to be verified are obtained from the global attributes, and a unified verification interface is generated for them. Finally, an interface display interface is generated, and an object verification interface is dynamically created according to the JavaBean object information. It can be seen that by uniformly processing the specifications of all the JavaBean objects to be verified, the present invention can facilitate developers to quickly view the JavaBean objects to be verified and their attribute specifications, improving the communication efficiency between front-end and back-end developers. By scanning the interfaces corresponding to the JavaBean objects in the Controller class, it is possible to avoid the error that back-end developers forget to verify the JavaBean during the process of calling the JavaBean.
[0042] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0043] Embodiment 1:
[0044] As Figure 1 shown, this embodiment provides a management method of a JavaBean verification class, including the following steps:
[0045] S1: Customize annotations to specify the package path to be scanned and the JavaBean objects to be scanned.
[0046] Specifically, define the custom annotations @EnableValidCheck and @ValidCheck required for the project. @EnableValidCheck is used to specify the package scan path of the JavaBean class to be verified, and @ValidCheck is used to mark the JavaBean objects for which verification management is desired. Apply the defined annotations to the specified positions respectively.
[0047] S2: When the Spring Boot project starts, scan all JavaBean objects that need to be checked and the validation specifications specified on each of their properties, and save them to global properties.
[0048] Specifically: When the Spring Boot project starts, obtain the value of basePackages specified in the @EnableValidCheck annotation in the specific implementation class of ImportBeanDefinitionRegistrar. If no basePackages information is specified, use the package where the class that references @EnableValidCheck is located as the root path to be scanned. Scan all JavaBean classes annotated with the @ValidCheck annotation under the specified package, and use the reflection mechanism to obtain all fields of the JavaBean object and the Bean Validation annotation information on each field.
[0049] S3: Scan all Controller classes, obtain all interface information related to JavaBean objects, and save them to global properties.
[0050] After step S2 is completed, continue to obtain the value of basePackages defined in the @ComponentScan annotation in Spring Boot, and scan all classes annotated with the Controller or RestController annotation under this package. Use the reflection mechanism to obtain all methods defined in this class with annotations such as @RequestMapping, @GetMapping, @PostMapping, etc., and then use the reflection mechanism to obtain the parameter information on this method. Find all the JavaBean classes that have been recorded in the previous step, and record whether the @Valid or @Validated annotation and the mapped URL address information are added to this method in global properties.
[0051] S4: Obtain all JavaBean objects that need to be validated from global properties and generate a unified validation interface for them.
[0052] Specifically, define a Controller class, define a method in this class to obtain all JavaBean objects that need to be validated from global properties, and generate a unified validation interface for them.
[0053] As an example, a unified @RequestMapping URL path is used for each JavaBean object to be verified stored in the global attributes. The received value type is Map. According to the entity attribute in the request process, the Map is converted into the corresponding Entity object, and the data passed by the front end is verified through programmatic verification using the javax.validation.Validator, and the verification result is returned.
[0054] S5: Generate an interface display interface, and dynamically create an object verification interface according to the JavaBean object information.
[0055] As an example, a verification interface interface is dynamically generated. According to the storage results in the global attributes in step S2, an interface interface is generated for each JavaBean object. The content includes interface descriptions, field verification specifications, call interfaces of JavaBean objects, and whether @Valid or @Validated annotations are added, etc. Developers can verify whether the passed values meet the verification conditions by passing information through the page.
[0056] This embodiment provides a management method for JavaBean verification classes, which can dynamically obtain all JavaBean objects to be verified, and generate verification interfaces for them respectively, so as to facilitate users to view the verification rules of all classes to be verified, and provide a way to directly verify the data correctness through the page interface. In addition, by scanning the interfaces that call JavaBean objects in all Controller classes, it can be seen whether a verification annotation is added to the object when it is used, preventing the problem that the verification rules do not take effect.
[0057] Embodiment 2:
[0058] Based on Embodiment 1, as Figure 2 shown, the present invention also discloses a management system for JavaBean verification classes, including: a definition module 1, an object scanning module 2, a class scanning module 3, an interface generation module 4, and an interface creation module 5.
[0059] The definition module 1 is used to customize annotations for specifying the package path to be scanned and the JavaBean objects to be scanned. The definition module 1 is specifically used for: customizing the annotations @EnableValidCheck and @ValidCheck, where @EnableValidCheck is used to specify the package scanning path of the JavaBean class to be verified, and @ValidCheck is used to mark the JavaBean objects for which verification management is desired; applying the custom annotations to the specified positions respectively.
[0060] The object scanning module 2 is used to scan all JavaBean objects that need to be checked and the specified validation specifications on each of their attributes when the Spring Boot project starts, and save them to the global attributes.
[0061] Specifically, the object scanning module 2 is used for:
[0062] When the Spring Boot project starts, obtain the value of basePackages specified in the @EnableValidCheck annotation in the specific implementation class of ImportBeanDefinitionRegistrar. If no basePackages information is specified, use the package where the class that references @EnableValidCheck is located as the root path to be scanned. Scan all JavaBean classes annotated with @ValidCheck in the specified package, and use the reflection mechanism to obtain all fields of the JavaBean object and the Bean Validation annotation information on each field, and save them to the global attributes.
[0063] The class scanning module 3 is used to scan all Controller classes, obtain all interface information related to JavaBean objects, and save them to the global attributes. Specifically, the class scanning module 3 is used for: obtain the self-defined value of basePackages in the @ComponentScan annotation in the Spring Boot project, scan all classes annotated with Controller or RestController, and use the reflection mechanism to obtain all methods defined in the class with @RequestMapping, @GetMapping, or @PostMapping annotations; use the reflection mechanism to obtain the parameter information on the method, find all JavaBean classes that have been recorded in the global attributes, and record whether the @Valid or @Validated information and the mapped URL address information are added to the method in the global attributes.
[0064] The interface generation module 4 is used to obtain all JavaBean objects that need to be validated from the global attributes and generate a unified validation interface for them. Specifically, the interface generation module 4 is used for: use a unified @RequestMapping URL path for each JavaBean object to be validated stored in the global attributes, receive a value of type Map, and convert the Map to the corresponding Entity object according to the entity attribute in the request process; use the javax.validation.Validator to perform programmatic validation on the data passed from the front end and return the validation result.
[0065] The interface creation module 5 is used to generate an interface display interface and dynamically create an object verification interface according to the JavaBean object information. Specifically, the interface creation module 5 is used to: dynamically generate a verification interface, generate a description and specification of the interface for each JavaBean object according to the storage results in the global attributes, and display the call interfaces of each JavaBean object and whether verification annotations are added to them.
[0066] This embodiment provides a management system for JavaBean verification classes, which realizes unified processing of all JavaBean objects to be verified, facilitates developers to quickly view the JavaBean objects to be verified and their attribute specifications, and improves the communication efficiency between front-end and back-end developers. By scanning the interfaces of the corresponding JavaBean objects in the Controller class, this system can avoid the error that back-end developers forget to verify JavaBean during the call process.
[0067] Embodiment Three:
[0068] This embodiment discloses a management device for JavaBean verification classes, including a processor and a memory; wherein, when the processor executes the management program for JavaBean verification classes saved in the memory, the following steps are implemented:
[0069] 1. Define custom annotations to specify the package path to be scanned and the JavaBean objects to be scanned.
[0070] 2. When the Spring Boot project starts, scan all JavaBean objects to be checked and the verification specifications specified for each of their attributes, and save them in the global attributes.
[0071] 3. Scan all Controller classes, obtain all interface information related to JavaBean objects, and save them in the global attributes.
[0072] 4. Obtain all JavaBean objects to be verified from the global attributes and generate a unified verification interface for them.
[0073] 5. Generate an interface display interface and dynamically create an object verification interface according to the JavaBean object information.
[0074] Furthermore, the management device for JavaBean verification classes in this embodiment may further include:
[0075] An input interface, which is used to obtain the management program of the JavaBean verification class imported from the outside world, and save the obtained management program of the JavaBean verification class to the memory. It can also be used to obtain various instructions and parameters transmitted by an external terminal device and transmit them to the processor, so that the processor can perform corresponding processing using the above various instructions and parameters. In this embodiment, the input interface may specifically include, but is not limited to, a USB interface, a serial interface, a voice input interface, a fingerprint input interface, a hard disk reading interface, etc.
[0076] An output interface, which is used to output various data generated by the processor to the terminal device connected thereto, so that other terminal devices connected to the output interface can obtain various data generated by the processor. In this embodiment, the output interface may specifically include, but is not limited to, a USB interface, a serial interface, etc.
[0077] A communication unit, which is used to establish a remote communication connection between the management device of the JavaBean verification class and an external server, so that the management device of the JavaBean verification class can mount the mirror file to the external server. In this embodiment, the communication unit may specifically include, but is not limited to, a remote communication unit based on wireless communication technology or wired communication technology.
[0078] A keyboard, which is used to obtain various parameter data or instructions input by the user by tapping the keycaps in real time.
[0079] A display, which is used to display in real time the relevant information of the short-circuit location process of the server power supply line.
[0080] A mouse, which can be used to assist the user in inputting data and simplify the user's operations.
[0081] Embodiment 4:
[0082] This embodiment also discloses a readable storage medium. The readable storage medium mentioned here includes a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable hard disk, a CD-ROM, or any other form of storage medium well-known in the technical field. The management program of the JavaBean verification class is stored in the readable storage medium. When the management program of the JavaBean verification class is executed by the processor, the following steps are implemented:
[0083] 1. Customize annotations to specify the package path to be scanned and the JavaBean objects to be scanned.
[0084] 2. When the Spring Boot project starts, scan all the JavaBean objects to be checked and the verification specifications specified on each of their attributes, and save them to the global attributes.
[0085] 3. Scan all Controller classes, obtain all interface information related to JavaBean objects, and save it in global properties.
[0086] 4. Obtain all JavaBean objects to be verified from global properties and generate a unified verification interface for them.
[0087] 5. Generate an interface display interface and dynamically create an object verification interface according to JavaBean object information.
[0088] In summary, the present invention can uniformly process all JavaBean objects to be verified, facilitating developers to quickly view the JavaBean objects to be verified and their attribute specifications, and improving the communication efficiency between front-end and back-end developers.
[0089] In the description of this specification, each embodiment is described in a progressive manner. The key point of each embodiment is to illustrate the differences from other embodiments. The same or similar parts among the embodiments can be referred to each other. For the methods disclosed in the embodiments, since they correspond to the systems disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method part.
[0090] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0091] In several embodiments provided by the present invention, it should be understood that the disclosed systems, systems, and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and there can be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of the systems or units can be in electrical, mechanical, or other forms.
[0092] The unit described as a separation component may or may not be physically separated. The component shown as a unit may or may not be a physical unit, that is, it may be located in one place or distributed across multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0093] In addition, in each embodiment of the present invention, each functional module can be integrated in a processing unit, or each module can exist physically alone, or two or more modules can be integrated in one unit.
[0094] Similarly, in each embodiment of the present invention, each processing unit can be integrated in a functional module, or each processing unit can exist physically, or two or more processing units can be integrated in a functional module.
[0095] The steps of the method or algorithm described in combination with the embodiments disclosed in this article can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be placed in a random access memory (RAM), memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, or any other form of storage medium well-known in the technical field.
[0096] Finally, it should also be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising one..." does not exclude the existence of additional identical elements in the process, method, article or device comprising the element.
[0097] The above has introduced in detail the management method, system, device and readable storage medium of the JavaBean verification class provided by the present invention. Specific examples are used in this article to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention. It should be pointed out that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.
Claims
1. A management method for a JavaBean validation class, characterized in that, Including: Custom annotations used to specify the package path to be scanned and the JavaBean objects to be scanned; When the Spring Boot project starts, scan all JavaBean objects that need to be checked and the validation specifications specified for each of their attributes, and save them in the global attributes; Scan all Controller classes, obtain all interface information related to JavaBean objects, and save them in the global attributes; Obtain all JavaBean objects to be validated from the global attributes and generate a unified validation interface for them; Generate an interface display interface and dynamically create an object validation interface according to the JavaBean object information; The custom annotation is used to specify the package path to be scanned and the JavaBean objects to be scanned, including: Custom annotations @EnableValidCheck and @ValidCheck, @EnableValidCheck is used to specify the package scan path of the JavaBean class to be validated, and @ValidCheck is used to mark the JavaBean objects that are expected to be managed for validation; Apply the custom annotations to the specified positions respectively; When the Spring Boot project starts, scan all JavaBean objects that need to be checked and the validation specifications specified for each of their attributes, and save them in the global attributes, including: When the Spring Boot project starts, obtain the value of basePackages specified in the @EnableValidCheck annotation in the specific implementation class of ImportBeanDefinitionRegistrar. If no basePackages information is specified, use the package where the class referenced by @EnableValidCheck is located as the root path to be scanned; Scan all JavaBean classes marked with the @ValidCheck annotation in the specified package, and use the reflection mechanism to obtain all fields of the JavaBean object and the Bean Validation annotation information for each field, and save them in the global attributes.
2. The management method of the JavaBean verification class according to claim 1, wherein, Scan all Controller classes, obtain all interface information related to JavaBean objects, and save them in the global attributes, including: In a Spring Boot project, obtain the custom basePackages value in the @ComponentScan annotation, scan all classes annotated with @Controller or @RestController, and use the reflection mechanism to obtain all methods defined in the class with @RequestMapping, @GetMapping, or @PostMapping annotations; use the reflection mechanism to obtain the parameter information on the method, find all JavaBean classes already recorded in the global properties, and record whether the @Valid or @Validated annotation is added to the method and the mapping URL address information in the global properties.
3. The management method of the JavaBean verification class according to claim 2, characterized in that Obtaining all JavaBean objects to be validated from the global properties and generating a unified validation interface for them includes: Using a unified @RequestMappingURL path for each JavaBean object to be validated stored in the global properties, with the received value type being Map, and converting the Map to the corresponding Entity object according to the entity property during the request process; Using the javax.validation.Validator to perform programmatic validation on the data passed from the front end and returning the validation result.
4. The management method of the JavaBean verification class according to claim 3, characterized in that, Generating an interface display interface and dynamically creating an object validation interface based on the JavaBean object information includes: Dynamically generating a validation interface interface, generating a description and specification of the interface for each JavaBean object according to the storage result in the global properties, and simultaneously displaying the call interface of each JavaBean object and whether the validation annotation is added.
5. The management method of the JavaBean verification class according to claim 4, characterized in that, The description and specification of the interface interface include: interface description information, field validation specification information, call interface information of the JavaBean object, and information on whether the @Valid or @Validated annotation is added.
6. A management system for JavaBean validation classes, characterized in that, Including: A definition module for customizing annotations to specify the package path to be scanned and the JavaBean objects to be scanned; An object scanning module for scanning all JavaBean objects to be checked and the validation specifications specified on each of their properties when the Spring Boot project starts and saving them to the global properties; A class scanning module for scanning all Controller classes, obtaining all interface information related to the JavaBean objects, and saving them to the global properties; An interface generation module for obtaining all JavaBean objects to be validated from the global properties and generating a unified validation interface for them; An interface creation module for generating an interface display interface and dynamically creating an object validation interface according to the JavaBean object information; The definition module is specifically used for: Custom annotations @EnableValidCheck and @ValidCheck. @EnableValidCheck is used to specify the package scanning path for the JavaBean classes to be validated, and @ValidCheck is used to annotate the JavaBean objects for which validation management is desired; Apply the custom annotations to the specified locations respectively; The object scanning module is specifically used for: When the Spring Boot project starts, obtain the basePackages value specified in the @EnableValidCheck annotation in the specific implementation class of ImportBeanDefinitionRegistrar. If no basePackages information is specified, use the package where the class that references @EnableValidCheck is located as the root path to be scanned; Scan all JavaBean classes annotated with the @ValidCheck annotation in the specified package, and use the reflection mechanism to obtain all fields of the JavaBean object and the Bean Validation annotation information on each field, and save them in the global properties.
7. A management device for a JavaBean validation class, characterized in that, Including: A memory for storing the management program of the JavaBean validation class; A processor for implementing the steps of the management method of the JavaBean validation class as described in any one of claims 1 to 5 when executing the management program of the JavaBean validation class.
8. A readable storage medium, characterized in that: The management program of the JavaBean validation class is stored on the readable storage medium, and when the management program of the JavaBean validation class is executed by the processor, the steps of the management method of the JavaBean validation class as described in any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
An interface parameter verification method and component
CN106991023A
Verification method based on Java Bean verification rule and related equipment
CN112989433A