Method for acquiring specified parameters based on user-defined annotation, readable storage medium and program product
By building custom annotation functions and AOP sections, hierarchical reference and secure acquisition of annotations are achieved, and the existing annotation methods are solved, which are costly, non-supported reuse and poor security, and efficient, secure and flexible interface parameter management is achieved.
Patent Information
- Application Number
- CN202411875858.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2044-12-18
AI Technical Summary
The existing annotation methods are costly, do not support reuse, and have poor security, making it difficult to meet the flexible management and security requirements of interface parameters in microservice architecture.
By building custom annotation functions and AOP sections, hierarchical references of annotations are implemented. Only when the introduced class parameters in the interface method reference annotation function are the same, the method of obtaining external class parameters will be executed, thereby improving safety and efficiency.
It realizes safe and efficient acquisition of annotations, reduces management costs, improves code readability and scalability, and supports the reuse of parameter information and flexible configuration.
Smart Images

Figure CN119938132A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of custom annotations, and in particular to a method for obtaining specified parameters based on custom annotations, a readable storage medium and a program product. Background Art
[0002] In microservice architecture services, annotations have become a widely accepted practice to simplify interface definition and parameter processing. Annotations provide a concise and intuitive way to mark code, making interface definitions clearer and parameter configuration more flexible. This metadata-based approach reduces the need for hard coding while improving the readability and maintainability of the code. Therefore, in the evolution of microservice architecture, it has become a trend to define interfaces using annotations, which enables developers to more efficiently manage and expand interactions between services.
[0003] In the prior art, both SpringMVC and Swagger frameworks provide support for annotation functions, but they have the following disadvantages: (1) serious code redundancy and high management cost. Both SpringMVC annotations and Swagger annotations are for a single request method. For example, the corresponding parameters for saving and updating user information are the same. Using SpringMVC annotations and Swagger annotations requires writing parameter information and related annotation configurations twice. If fields are added to the page, the two interfaces also need to be adjusted synchronously, which results in high management costs. (2) poor code scalability and insufficient security. If the server provides an interface for saving enterprise information, the enterprise name for business A is company_name, and for business B is enterprise_name. Both SpringMVC annotations and Swagger annotations cannot meet the need to use a single interface to simultaneously complete the docking of the two businesses, resulting in poor scalability. In addition, the fields in the database and the attributes of the class in Java are one-to-one corresponding. When retrieving data, the entire table may be read. If not processed, unnecessary data fields will be returned to the business end, resulting in security issues.
[0004] Therefore, it is necessary to provide a method, a computer-readable storage medium and a computer program product for obtaining annotation information that supports parameter information reuse, has low management cost and high security. Summary of the invention
[0005] In view of the above analysis, the embodiments of the present invention aim to provide a method for obtaining specified parameters based on custom annotations, a readable storage medium and a program product, so as to solve the problems of high cost, lack of support for reuse and poor security of existing annotation methods.
[0006] In a first aspect, an embodiment of the present invention provides a method for obtaining specified parameters based on a custom annotation, including:
[0007] Constructing a custom annotation function, the custom annotation function includes: an interface method reference annotation function, an interface parameter reference annotation group function, and an interface parameter reference annotation function;
[0008] The interface method reference annotation function includes a reference class parameter, the reference class parameter is used to specify a user operation interface, the interface parameter reference annotation group function includes at least one interface parameter reference annotation function, which is used to represent different operations on the same reference class parameter, and the interface parameter reference annotation function is used to define the attribute value of each operation field;
[0009] Based on business needs, set the HTTP request path corresponding to the target method, the reference class parameters in the interface method reference annotation function, the interface parameter reference annotation group function, and the attribute values of each operation field in the interface parameter reference annotation function;
[0010] The entry point of the AOP aspect is set based on the HTTP request path, and the attribute values of each operation field in the interface parameter reference annotation function in the external class corresponding to the target method are obtained based on the entry point, and the parameter values of each operation field in the target method are obtained according to the attribute values, and the parameter values are submitted to the backend to implement business operations.
[0011] Based on the further improvement of the above method, the operation field includes:
[0012] The reference class parameter field is consistent with the reference class parameter in the interface method reference annotation function and is used to specify the user operation interface;
[0013] The parent class field is used to indicate whether to use the field value of the parent class. The default value is no.
[0014] The parameter input field is used to indicate whether parameters need to be passed in. The default value is yes.
[0015] Required input parameter, used to indicate that the input parameter field must be filled in, the default is No;
[0016] Input parameter field name, used to indicate the name of the input parameter field, which is empty by default;
[0017] Input parameter field description, used to indicate the description information of the input parameter field, which is empty by default;
[0018] Output parameter field, used to indicate whether the output parameter field needs to be output, the default is yes;
[0019] Output parameter field name, used to indicate the name of the output parameter field, the default value is empty;
[0020] Output parameter field description, used to indicate the description information of the output parameter field, and is empty by default.
[0021] Based on the further improvement of the above method, the attribute value of each operation field in the interface parameter reference annotation function is set based on business requirements, including:
[0022] According to business needs, determine whether it is necessary to use the parent class field value. If necessary, set the parent class field in the interface parameter reference annotation function to yes and indicate the target parent class field; determine whether it is necessary to use input parameter fields, required input parameter items, and output parameter fields. If necessary, set the corresponding fields to yes; determine whether it is necessary to use input parameter field naming, input parameter field description, output parameter field naming, or output parameter field description. If necessary, fill in the corresponding variable values according to the business needs.
[0023] Based on the further improvement of the above method, the method of obtaining the attribute values of each operation field in the interface parameter reference annotation function in the external class corresponding to the target method based on the entry point includes:
[0024] Obtain an interface method reference annotation function, and identify a reference class parameter in the interface method reference annotation function as a first reference class parameter;
[0025] Based on the first reference class parameter, an external class corresponding to the reference class parameter is obtained, and a custom annotation function in the external class is obtained;
[0026] Traverse and obtain all the interface parameter reference annotation group functions and interface parameter reference annotation functions in the custom annotation function to form a target annotation information set, and determine whether the target annotation information set includes the interface parameter reference annotation group function. If not, no processing is performed; if included, determine whether the reference class parameters in each interface parameter reference annotation group function are the same as the first reference class parameter. If the same, obtain the attribute value of each operation field in each interface parameter reference annotation function in the interface parameter reference annotation group function. If not, no processing is performed.
[0027] Based on the further improvement of the above method, the step of obtaining the parameter values of each operation field in the target method according to the attribute value and submitting the parameter values to the backend to implement the business operation includes:
[0028] Obtain data from the target method based on the input parameter field value and the attribute value named by the input parameter field in the interface parameter reference annotation function. If the attribute value of the required input parameter item is yes, the corresponding data obtained is used as the first data set. If not, an exception is thrown and returned to the client.
[0029] Instantiate the external class corresponding to the first reference class parameter, set the parameter value in the external class using the reflection mechanism and the first data set, and then submit it to the backend to implement the business operation.
[0030] Based on the further improvement of the above method, the setting of the AOP aspect entry point based on the HTTP request path includes: defining a pointcut expression based on the @Pointcut annotation, wherein the expression is:
[0031] ("(execution(*com.*.*controller..*.*(..)))").
[0032] Based on the further improvement of the above method, the @Retention attribute value of the interface method reference annotation function @JsonGroup, the interface parameter reference annotation group function @JsonIncludes, and the interface parameter reference annotation group function @JsonInclude is ElementType.METHOD, and the @Target attribute value is RetentionPolicy.RUNTIME.
[0033] As a further improvement on the above method, @Aspect is used to declare the target object as an aspect class.
[0034] In a second aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute a method for obtaining specified parameters based on custom annotations as described in any one of the first aspects.
[0035] In a third aspect, an embodiment of the present invention provides a computer program product, comprising program code instructions. When the program product is executed by a computer, the program code instructions enable the computer to execute a method for obtaining specified parameters based on custom annotations as described in any one of the first aspects.
[0036] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects:
[0037] 1. The present invention provides a method, a readable storage medium and a program product for obtaining specified parameters based on custom annotations. By constructing custom annotation functions and AOP aspects, hierarchical reference of annotations is realized. The method for obtaining external class parameters will only be executed when the introduced class parameters in the interface method reference annotation function are the same. Therefore, the technical solution proposed by the present invention is safer than the solution of directly obtaining parameters in the prior art.
[0038] 2. The present invention provides a method, a readable storage medium and a program product for obtaining specified parameters based on custom annotations. The parent class field given in the interface parameter reference annotation function is used to realize external class parameter inheritance. Compared with the prior art SpringMVC annotation and Swagger annotation methods of obtaining parameters, the technical solution of the present invention is more efficient in obtaining external class parameter values; in addition, the required input parameters, input parameter fields, output parameter fields, etc. given in the interface parameter reference annotation function further limit the method of obtaining parameter values, which allows developers to implement code configuration more flexibly, and the configuration information and code logic can be directly obtained through the values of each field, which is more readable.
[0039] 3. The present invention provides a method, a readable storage medium and a program product for obtaining specified parameters based on custom annotations, and realizes management based on reference class parameters in each annotated function, with simple operation and low use cost.
[0040] In the present invention, the above-mentioned technical solutions can also be combined with each other to achieve more preferred combination solutions. Other features and advantages of the present invention will be described in the subsequent description, and some advantages can become obvious from the description, or can be understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained through the contents particularly pointed out in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The accompanying drawings are only used for the purpose of illustrating specific embodiments and are not to be considered as limiting the present invention. In the entire drawings, the same reference symbols represent the same components;
[0042] Figure 1 This is an example diagram of a method for obtaining specified parameters based on custom annotations in an embodiment of the present invention. DETAILED DESCRIPTION
[0043] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.
[0044] A specific embodiment of the present invention discloses a method for obtaining specified parameters based on custom annotations, such as Figure 1 As shown, including:
[0045] S1: Construct a custom annotation function, the custom annotation function includes: an interface method reference annotation function, an interface parameter reference annotation group function, and an interface parameter reference annotation function;
[0046] Among them, the interface method reference annotation function includes reference class parameters, the reference class parameters are used to specify the user operation interface, the interface parameter reference annotation group function includes at least one interface parameter reference annotation function, which is used to represent different operations on the same reference class parameter, and the interface parameter reference annotation function is used to define the attribute values of each operation field.
[0047] For the interface method reference annotation function @JsonGroup, it is defined as follows:
[0048]
[0049]
[0050] When in use, the operation object (such as an interface, class, etc.) can be directly specified by value, for example: @JsonGroup(value=UserDTO.Add.class), which means that the associated class UserDTO.Add.class in the @JsonGroup annotation is used, and then the input parameter, output parameter and other information are automatically obtained based on the method proposed in the present invention.
[0051] For the interface parameter reference annotation group function @JsonIncludes, it is used to obtain the variable name of the parameter. It is a collection of interface parameter reference annotation functions @JsonInclude and is defined as follows:
[0052]
[0053] For the interface parameter reference annotation function @JsonInclude, the present invention extends the @RequestParam annotation and the @ApiImplicitParam annotation, supports the naming of incoming parameters and outgoing parameters, and defines the reference class. The operation fields of the interface parameter reference annotation function include: a reference class parameter field, which is consistent with the reference class parameter in the interface method reference annotation function and is used to specify the user operation interface; a parent class field, which is used to indicate whether the field value of the parent class is used, and the default is no; an input parameter field, which is used to indicate whether the input parameter needs to be passed in, and the default is yes; an input parameter mandatory item, which is used to indicate that the input parameter field must be filled in, and the default is no; an input parameter field naming, which is used to indicate the name of the input parameter field, and the default is empty; an input parameter field description, which is used to indicate the description information of the input parameter field, and the default is empty; an output parameter field, which is used to indicate whether the output parameter field needs to be output, and the default is yes; an output parameter field naming, which is used to indicate the name of the output parameter field, and the default is empty; an output parameter field description, which is used to indicate the description information of the output parameter field, and the default is empty. Specifically, the interface parameter reference annotation function @JsonInclude is defined as follows:
[0054]
[0055]
[0056] Understandably, when setting the annotation function, you need to set the @Retention attribute value and the @Target attribute value. The @Retention meta-annotation is used to specify the retention policy of the annotation, that is, at what level the annotation information is available. It has three possible values:
[0057] RetentionPolicy.SOURCE: Annotations are retained only in the source code and are discarded at compile time. These annotations are not available at runtime and are usually used for compile-time processing, such as compile-time annotation processors.
[0058] RetentionPolicy.CLASS: The annotation is retained in the compiled bytecode file but is not available at runtime. This is the default retention policy and is suitable for most annotations because they do not need to exist at runtime;
[0059] RetentionPolicy.RUNTIME: Annotations are available at runtime, that is, they are loaded into the JVM and can be read through reflection. This is suitable for scenarios where annotation information needs to be checked at runtime.
[0060] The @Target meta-annotation is used to specify the Java element type to which the annotation can be applied. It has the following possible values:
[0061] ElementType.CONSTRUCTOR: the annotation can be applied to the constructor;
[0062] ElementType.FIELD: annotations can be applied to fields;
[0063] ElementType.LOCAL_VARIABLE: the annotation can be applied to local variables (supported by Java 8 and later);
[0064] ElementType.METHOD: annotations can be applied to methods;
[0065] ElementType.PARAMETER: annotations can be applied to parameters;
[0066] ElementType.TYPE: the annotation can be applied to a type (class, interface, enumeration);
[0067] ElementType.PACKAGE: The annotation can be applied to a package (needs to be declared in the package-info.java file);
[0068] ElementType.MODULE: the annotation can be applied to modules (supported by Java 9 and later);
[0069] ElementType.ANNOTATION_TYPE: Annotation can be applied to annotation type;
[0070] ElementType.TYPE_PARAMETER: the annotation can be applied to type parameters (supported by Java 8 and later);
[0071] ElementType.TYPE_USE : An annotation can be applied to type use (supported by Java 8 and later).
[0072] The attribute values of @Retention and @Target can be set according to business requirements. Preferably, the present invention sets the @Retention attribute value of the interface parameter reference annotation group function @JsonInclude to ElementType.METHOD and the @Target attribute value to RetentionPolicy.RUNTIME.
[0073] S2: Based on business needs, set the HTTP request path corresponding to the target method, the reference class parameters in the interface method reference annotation function, the interface parameter reference annotation group function, and the attribute values of each operation field in the interface parameter reference annotation function.
[0074] The business requirements include the user's operation interface (for example, the request path, which is used to specify the access path), which is achieved by setting the HTTP request path. For example, if the target operation interface is " / user / add", it can be set as @PostMapping (value = " / user / add") in the program code.
[0075] The method of setting the attribute values of each operation field in the interface parameter reference annotation function based on business needs includes: judging whether the parent class field value needs to be used according to business needs, and if so, setting the parent class field in the interface parameter reference annotation function to yes, and indicating the target parent class field; judging whether the input parameter field, the input parameter required items, and the output parameter field need to be used, and if so, setting the corresponding field to yes; judging whether the input parameter field name, the input parameter field description, the output parameter field name or the output parameter field description need to be used, and if so, filling in the corresponding variable value according to the business needs.
[0076] Business requirements also include specifying the reference class parameters in the interface method reference annotation function and the interface parameter reference annotation group function based on business requirements, so as to obtain the specified parameter value.
[0077] For example,
[0078]
[0079]
[0080] S3: Set the entry point of the AOP aspect based on the HTTP request path, obtain the attribute values of each operation field in the interface parameter reference annotation function in the external class corresponding to the target method based on the entry point, and obtain the parameter values of each operation field in the target method based on the attribute values, and submit the parameter values to the backend to implement business operations.
[0081] AOP (Aspect-Oriented Programming) is a programming paradigm that allows developers to add new functions or behaviors without changing existing code. These functions or behaviors are called "aspects". AOP is often used to unify the processing of functions, such as transaction management, logging, permission checking and other functions. Annotation-based AOP is the most commonly used implementation method in Spring AOP. It simplifies the AOP configuration process and makes the use of AOP more intuitive and convenient.
[0082] The present invention makes the reuse of interface parameters based on custom annotation functions effective by designing AOP aspects, including four steps of defining entry points, defining pre-contents, defining post-contents and making aspects effective.
[0083] For defining the entry point, use the @Pointcut annotation provided by Spring AOP technology. For example, if the target operation interface is specified as " / user / add" in the business requirements, which indicates an HTTP hyperlink, to obtain the parameters under the link, all controller interfaces (that is, all requests containing the com and controller path keywords in the code) need to be set as entry points. Specifically, the pointcut expression is defined based on the @Pointcut annotation, and the expression is:
[0084] ("(execution(*com.*.*controller..*.*(..)))").
[0085] For defining the pre-content, use the @Before("point()") annotation provided by Spring AOP technology. The content of point() is the entry point defined in the previous step. Based on the entry point, obtain the custom direct and parameter initialization. Specifically, the attribute values of each operation field in the interface parameter reference annotation function in the external class corresponding to the target method based on the entry point are obtained, including:
[0086] Obtain an interface method reference annotation function, and identify a reference class parameter in the interface method reference annotation function as a first reference class parameter;
[0087] Based on the first reference class parameter, an external class corresponding to the reference class parameter is obtained, and a custom annotation function in the external class is obtained;
[0088] Traverse and obtain all the interface parameter reference annotation group functions and interface parameter reference annotation functions in the custom annotation function to form a target annotation information set, and determine whether the target annotation information set includes the interface parameter reference annotation group function. If not, no processing is performed; if included, determine whether the reference class parameters in each interface parameter reference annotation group function are the same as the first reference class parameter. If the same, obtain the attribute value of each operation field in each interface parameter reference annotation function in the interface parameter reference annotation group function. If not, no processing is performed.
[0089] For defining post-content, use the @After("point()") annotation provided by Spring AOP technology, where the point() content is the entry point defined in the previous step. The difference between post-content and pre-content is that in the last step, after generating an external class instance of the referenced class through the reflection mechanism, the outHave, outField, and outRemark attributes are assigned. Specifically, the parameter values of each operation field in the target method are obtained based on the attribute values, and the parameter values are submitted to the backend to implement the business operation, including:
[0090] Obtain data from the target method based on the input parameter field value and the attribute value named by the input parameter field in the interface parameter reference annotation function. If the attribute value of the required input parameter item is yes, the corresponding data obtained is used as the first data set. If not, an exception is thrown and returned to the client.
[0091] Instantiate the external class corresponding to the first reference class parameter, set the parameter value in the external class using the reflection mechanism and the first data set, and then submit it to the backend to implement the business operation.
[0092] To make the aspect effective, first use the @Aspect annotation provided by SpringAOP technology on the class corresponding to the entry point to mark the current class as an aspect. Then use the @EnableAspectJAutoProxy annotation provided by SpringAOP technology on the startup class, which allows the Spring container to automatically create a proxy object for the aspect class marked by the @Aspect annotation, so that the advice defined in the aspect can be woven into the method of the target object.
[0093] Another specific embodiment of the present invention provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute any of the methods described above for obtaining specified parameters based on custom annotations. In this article, one or more computer-readable non-transitory storage media may include one or more semiconductor-based or other integrated circuits (ICs) (e.g., field programmable gate arrays (FPGAs) or application-specific ICs (ASICs)), hard disk drives (HDDs), hybrid hard disk drives (HHDs), optical disks, optical disk drives (ODDs), magneto-optical disks, magneto-optical disk drives, floppy disks, floppy disk drives (FDDs), magnetic tapes, solid-state drives (SSDs), RAM drives, and any other suitable computer-readable non-transitory storage media. Computer-readable non-transitory storage media may be volatile, non-volatile, or a combination of volatile and non-volatile.
[0094] Another specific embodiment of the present invention provides a computer program product, including program code instructions. When the program product is executed by a computer, the program code instructions enable the computer to execute any of the methods described above for obtaining specified parameters based on custom annotations.
[0095] Compared with the prior art, the present embodiment provides a method for obtaining specified parameters based on custom annotations, a readable storage medium and a program product. By constructing custom annotation functions and AOP aspects, hierarchical references of annotations are realized. Only when the introduced class parameters in the interface method reference annotation function are the same, the method for obtaining external class parameters will be executed. Therefore, the technical solution proposed in the present invention is safer than the prior art solution for directly obtaining parameters. The parent class field given in the interface parameter reference annotation function is used to realize external class parameter inheritance. Compared with the prior art SpringMVC annotation and Swagger annotation parameter acquisition methods, the technical solution of the present invention is more efficient in obtaining external class parameter values. In addition, the required input parameters, input parameter fields, output parameter fields, etc. given in the interface parameter reference annotation function further limit the method for obtaining parameter values, which allows developers to implement code configuration more flexibly, and the configuration information and code logic can be directly obtained through the values of each field, which is more readable. Management is realized based on the reference class parameters in each annotation function, which is simple to operate and has low cost.
[0096] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any technician familiar with the technical field within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention.
Claims
1. A method for obtaining specified parameters based on custom annotations, characterized in that: include: Constructing a custom annotation function, the custom annotation function includes: an interface method reference annotation function, an interface parameter reference annotation group function, and an interface parameter reference annotation function; The interface method reference annotation function includes a reference class parameter, the reference class parameter is used to specify a user operation interface, the interface parameter reference annotation group function includes at least one interface parameter reference annotation function, which is used to represent different operations on the same reference class parameter, and the interface parameter reference annotation function is used to define the attribute value of each operation field; Based on business needs, set the HTTP request path corresponding to the target method, the reference class parameters in the interface method reference annotation function, the interface parameter reference annotation group function, and the attribute values of each operation field in the interface parameter reference annotation function; The entry point of the AOP aspect is set based on the HTTP request path, and the attribute values of each operation field in the interface parameter reference annotation function in the external class corresponding to the target method are obtained based on the entry point, and the parameter values of each operation field in the target method are obtained according to the attribute values, and the parameter values are submitted to the backend to implement business operations.
2. According to a method for obtaining specified parameters based on custom annotations according to claim 1, it is characterized in that: The operation field includes: The reference class parameter field is consistent with the reference class parameter in the interface method reference annotation function and is used to specify the user operation interface; The parent class field is used to indicate whether to use the field value of the parent class. The default value is no. The parameter input field is used to indicate whether parameters need to be passed in. The default value is yes. Required input parameter, used to indicate that the input parameter field must be filled in, the default is No; Input parameter field name, used to indicate the name of the input parameter field, which is empty by default; Input parameter field description, used to indicate the description information of the input parameter field, which is empty by default; Output parameter field, used to indicate whether the output parameter field needs to be output, the default is yes; Output parameter field name, used to indicate the name of the output parameter field, the default value is empty; Output parameter field description, used to indicate the description information of the output parameter field, and is empty by default.
3. According to the method for obtaining specified parameters based on custom annotations according to claim 2, it is characterized in that: The setting of the attribute values of each operation field in the interface parameter reference annotation function based on business requirements includes: According to business needs, determine whether it is necessary to use the parent class field value. If necessary, set the parent class field in the interface parameter reference annotation function to yes and indicate the target parent class field; determine whether it is necessary to use input parameter fields, required input parameter items, and output parameter fields. If necessary, set the corresponding fields to yes; determine whether it is necessary to use input parameter field naming, input parameter field description, output parameter field naming, or output parameter field description. If necessary, fill in the corresponding variable values according to the business needs.
4. A method for obtaining specified parameters based on custom annotations according to claim 3, characterized in that: The method of obtaining the attribute values of each operation field in the interface parameter reference annotation function in the external class corresponding to the target method based on the entry point includes: Obtain an interface method reference annotation function, and identify a reference class parameter in the interface method reference annotation function as a first reference class parameter; Based on the first reference class parameter, an external class corresponding to the reference class parameter is obtained, and a custom annotation function in the external class is obtained; Traverse and obtain all the interface parameter reference annotation group functions and interface parameter reference annotation functions in the custom annotation function to form a target annotation information set, and determine whether the target annotation information set includes the interface parameter reference annotation group function. If not, no processing is performed; if included, determine whether the reference class parameters in each interface parameter reference annotation group function are the same as the first reference class parameter. If the same, obtain the attribute value of each operation field in each interface parameter reference annotation function in the interface parameter reference annotation group function. If not, no processing is performed.
5. A method for obtaining specified parameters based on custom annotations according to claim 4, characterized in that: The acquiring the parameter values of each operation field in the target method according to the attribute value, and submitting the parameter values to the backend to implement the business operation, includes: Obtain data from the target method based on the input parameter field value and the attribute value named by the input parameter field in the interface parameter reference annotation function. If the attribute value of the required input parameter item is yes, the corresponding data obtained is used as the first data set. If not, an exception is thrown and returned to the client. Instantiate the external class corresponding to the first reference class parameter, set the parameter value in the external class using the reflection mechanism and the first data set, and then submit it to the backend to implement the business operation.
6. A method for obtaining specified parameters based on custom annotations according to claim 5, characterized in that: The step of setting the AOP section entry point based on the HTTP request path includes: defining a pointcut expression based on the @Pointcut annotation, wherein the expression is: ("(execution(*com.*.*controller..*.*(..)))").
7. A method for obtaining specified parameters based on custom annotations according to claim 6, characterized in that: include: The @Retention attribute value of the interface method reference annotation function @JsonGroup, the interface parameter reference annotation group function @JsonIncludes, and the interface parameter reference annotation group function @JsonInclude is ElementType.METHOD, and the @Target attribute value is RetentionPolicy.RUNTIME.
8. A method for obtaining specified parameters based on custom annotations according to claim 7, characterized in that: include: Use @Aspect to declare the target object as an aspect class.
9. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute a method for obtaining specified parameters based on custom annotations according to any one of claims 1 to 8.
10. A computer program product comprising program code instructions, which, when the program product is executed by a computer, cause the computer to perform the method of at least one of claims 1 to 8.
Citation Information
Patent Citations
Method, device, equipment and storage medium for obtaining parameter name and local variable name
CN108628635A
Interface data filtering method and device, computer equipment and readable storage medium
CN115270196A
Automatic annotation method, terminal equipment and computer readable storage medium
CN115878163A
Code annotation information generation method and device, equipment and storage medium
CN116594683A
Business log processing method and device, electronic equipment and computer readable medium
CN116932339A