Customizing return response methods, devices, equipment, and storage media based on annotations

The interface annotations are obtained through interceptors and reflection mechanisms and the response values are customized, which solves the problem that response classes cannot be shared in computer systems, and realizes the sharing and management of response classes, which facilitates the separate modification of database table structure.

CN113986996BActive Publication Date: 2025-08-12HANGZHOU DBAPPSECURITY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111354083.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-13
Publication Date
2025-08-12
Estimated Expiration
2041-11-13

AI Technical Summary

Technical Problem

In computer systems, the request response classes of multiple interfaces are highly similar, which makes the response classes unable to be shared and difficult to manage. Moreover, multiple classes need to be modified simultaneously when modifying the database table structure.

Method used

The interface response value is intercepted by a preset interceptor, and the interface annotation is obtained using the reflection mechanism to determine whether the target annotation exists, and the response value is customized to the specific fields in the annotation to realize the sharing of the response class.

Benefits of technology

It realizes the sharing of response classes, is easy to manage, reduces the workload of database table structure modification, and improves system flexibility and maintenance efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113986996B_ABST
    Figure CN113986996B_ABST
Patent Text Reader

Abstract

The present application relates to a method, apparatus, device and storage medium for customizing return responses based on annotations, wherein the method comprises: intercepting an interface response value on an interface through a preset interceptor, and obtaining the interface annotation corresponding to the interface response value through a reflection mechanism; judging whether a target annotation exists in the interface annotation through a verification method; if a target annotation exists, obtaining the target response value from the interface response value according to a specific field in the target annotation, and returning the target response value; if the target annotation does not exist, returning the interface response value. Through the present application, the problem that response classes cannot be shared and are difficult to manage in the prior art is solved, and the effect of being able to share response classes in the interface layer, thereby facilitating management, is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for customizing a return response based on annotations. Background Art

[0002] With the development of computer services, there will be a large number of interfaces in computer systems. Each interface corresponds to different requirements, and it is necessary to define the corresponding response class structure according to the requirements to implement the interface function.

[0003] Usually, for the security of the interface, a corresponding response class is defined for each interface according to different requirements. However, in the same module structure of a computer, due to similar requirements, the request response classes of multiple interfaces will become highly similar, which will result in a large number of similar response classes in the system. Moreover, the response classes cannot be shared and are difficult to manage.

[0004] There is currently no effective solution to the problem that response classes cannot be shared and are difficult to manage in related technologies. Summary of the Invention

[0005] In this embodiment, a method, apparatus, device and storage medium for customizing return responses based on annotations are provided to solve the problem in related technologies that response classes cannot be shared and are difficult to manage.

[0006] First, in this embodiment, a method for customizing a return response based on annotations is provided, including:

[0007] Intercept the interface response value on the interface through a preset interceptor, and obtain the interface annotation corresponding to the interface response value through the reflection mechanism;

[0008] By using a verification method, it is determined whether the target annotation exists in the interface annotation;

[0009] If the target annotation exists, obtaining the target response value from the interface response value according to the specific field in the target annotation, and returning the target response value;

[0010] If the target annotation does not exist, the interface response value is returned.

[0011] In some embodiments, the annotation-based customized return response method further includes:

[0012] The interceptor is preset in the interface layer.

[0013] In some embodiments, obtaining a target response value from the interface response value according to a specific field in the target annotation and returning the target response value includes:

[0014] Parsing the specific field in the target annotation to obtain the target field;

[0015] According to the target field and the specific field, a corresponding response value is obtained from the interface response value, and a corresponding response structure is generated;

[0016] Assign the corresponding response value to the response structure to obtain the target response value, and return the target response value.

[0017] In some of the embodiments, the target annotation includes a json annotation and a jsons annotation, wherein the jsons annotation includes multiple json annotations.

[0018] In some embodiments, parsing the specific field in the target annotation to obtain the target field includes:

[0019] When the target annotation is a json annotation, the specific field in the json annotation is parsed to obtain the target field;

[0020] When the target annotation is a jsons annotation, the jsons annotation is traversed to obtain the json annotation, and then the specific field in the json annotation is parsed to obtain the target field.

[0021] In some embodiments, the annotation-based customized return response method further includes:

[0022] After the interface receives the request, it performs interface logic processing on the request to obtain the interface response value.

[0023] In a second aspect, in this embodiment, a customized return response device based on annotations is provided, comprising: an interception module, a verification module, and a response module;

[0024] The interception module is used to intercept the interface response value on the interface through a preset interceptor, and obtain the interface annotation corresponding to the interface response value through a reflection mechanism;

[0025] The verification module is used to determine whether the target annotation exists in the interface annotation through a verification method;

[0026] The response module is configured to obtain a target response value from the interface response value according to a specific field in the target annotation when the target annotation exists, and return the target response value, or;

[0027] Used to return the interface response value when the target annotation does not exist.

[0028] In some of the embodiments, the interception module is further used to preset the interceptor in the interface layer.

[0029] In a third aspect, a computer device is provided in this embodiment, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the annotation-based custom return response method described in the first aspect above is implemented.

[0030] In a fourth aspect, a storage medium is provided in this embodiment, on which a computer program is stored. When the program is executed by a processor, the annotation-based customized return response method described in the first aspect is implemented.

[0031] Compared with the related art, the annotation-based customized return response method, apparatus, device and storage medium provided in this embodiment intercept the interface response value on the interface through a preset interceptor, and obtain the interface annotation corresponding to the interface response value through a reflection mechanism; through a verification method, it is determined whether there is a target annotation in the interface annotation; if the target annotation exists, the target response value is obtained from the interface response value according to a specific field in the target annotation, and the target response value is returned; if the target annotation does not exist, the interface response value is returned, which solves the problem that response classes cannot be shared and are difficult to manage, and achieves the effect of being able to share response classes and facilitate management.

[0032] The details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0034] Figure 1 A hardware structure block diagram of a terminal that customizes a return response method based on annotations in one embodiment;

[0035] Figure 2 This is a flowchart of a method for customizing a return response based on annotations in one embodiment;

[0036] Figure 3 is a flowchart of step S221 in one embodiment;

[0037] Figure 4 A flowchart of a method for customizing a return response based on annotations in a preferred embodiment;

[0038] Figure 5 A structural block diagram of an annotation-based customized return response device in one embodiment.

[0039] In the figure: 510, interception module; 520, verification module; 530, response module. DETAILED DESCRIPTION

[0040] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.

[0041] Unless otherwise defined, the technical terms or scientific terms involved in this application should have the general meaning understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "an", "a", "the", "these" and the like in this application do not indicate quantitative restrictions, and they can be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "plurality" involved in this application refers to two or more. "And / or" describes the relationship between related objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A exists alone, A and B exist simultaneously, and B exists alone. Generally, the character " / " indicates that the related objects are in an "or" relationship. The terms "first," "second," "third," etc. used in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.

[0042] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. For example, running on a terminal, Figure 1 This is a hardware structure diagram of the terminal based on the annotation-based custom return response method of this embodiment. Figure 1 As shown, the terminal may include one or more ( Figure 1Only one is shown) a processor 102 and a memory 104 for storing data, wherein the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.

[0043] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the annotation-based custom return response method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0044] The transmission device 106 is used to receive or send data via a network. The network may include a wireless network provided by the terminal's telecommunications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0045] In this embodiment, a custom return response method based on annotations is provided. Figure 2 This is the corresponding flow chart of this embodiment, such as Figure 2 As shown, the method includes the following steps:

[0046] Step S210: intercepting the interface response value on the interface through a preset interceptor, and obtaining the interface annotation corresponding to the interface response value through a reflection mechanism.

[0047] Specifically, the reflection mechanism refers to dynamically obtaining the attributes of a class or object through the class bytecode file during the program's runtime. After intercepting the interface response value on the interface, the reflection mechanism can be used to obtain the annotation on the interface corresponding to the interface response value.

[0048] Step S220: Determine whether the target annotation exists in the interface annotation by using a verification method.

[0049] Specifically, in the above interceptor, a verification method is used to determine whether the target annotation exists in the interface annotation.

[0050] If the target annotation exists, step S221 is executed to obtain the target response value from the interface response value according to the specific field in the target annotation, and return the target response value.

[0051] Specifically, by parsing the specific field content in the target annotation, the target response value of the interface is obtained from the intercepted interface response value, and the target response value is returned.

[0052] If the target annotation does not exist, execute step S222 and return the interface response value.

[0053] Specifically, if the target annotation does not exist, the intercepted interface response value is not processed and the interface response value is directly returned.

[0054] The above steps intercept the interface response value on the interface through the preset interceptor, and obtain the interface annotation corresponding to the interface response value through the reflection mechanism; through the verification method, determine whether the target annotation exists in the interface annotation; if the target annotation exists, obtain the target response value from the interface response value according to the specific field in the target annotation, and return the target response value; if the target annotation does not exist, return the interface response value.

[0055] The existing method defines a corresponding response class for each interface according to different requirements. However, in the same module structure of a computer, the request response classes of multiple interfaces are highly similar, which will result in a large number of similar response classes in the system. These response classes cannot be shared, and when the database table structure is modified, these large number of similar classes need to be modified synchronously, which is difficult to manage. This embodiment provides an effective supplement on the basis of the existing technology. Through the above steps, the preset interceptor uniformly intercepts the interface response values of all interfaces. At this time, the interface response value includes a large number of identical or similar response classes. Then, according to the annotation information on the interface corresponding to the interface response value, the response classes in the interface response value are distinguished, and the target response corresponding to the returned interface is customized, so that the original large number of identical or similar response classes can share the response class structure, and the target response value returned from the response class structure can be used directly. Furthermore, through the sharing of response classes implemented in this embodiment, when the database table structure is modified, there is no need to synchronously modify all similar classes. Only one response class structure needs to be modified, thereby solving the problem in the existing technology that response classes cannot be shared and are difficult to manage.

[0056] In some embodiments, the method further comprises:

[0057] Preset the interceptor in the interface layer.

[0058] Specifically, at the interface layer, the HandlerMethodReturnValueHandler interface of the Spring framework is used to process the return value, thereby implementing the interceptor preset at the interface layer.

[0059] In some of the embodiments, the target response value is obtained from the interface response value according to the specific field in the target annotation, and the target response value is returned, such as Figure 3 As shown, Figure 2 Step S221 in the embodiment includes the following steps:

[0060] Step S310: parse the specific field in the target annotation to obtain the target field.

[0061] Specifically, the specific field refers to the field that defines the attributes of the class in the target annotation, and can filter the interface response value. By parsing the content of the specific field, the target field of the response interface is obtained.

[0062] Furthermore, specific fields can be include and / or filter fields, and corresponding specific fields can be selected according to specific needs. The fields defined in the include and filter fields are separated by commas, and the defined fields are also target fields. The include field includes the target field, and the filter field excludes the target field. The filter field has a higher priority than the include field. That is to say, when both include and filter fields exist in the target annotation, if the same target field is included, the filter exclusion process is performed with the filter having the highest priority.

[0063] Step S320: Obtain a corresponding response value from the interface response value according to the target field and the specific field, and generate a corresponding response structure.

[0064] Specifically, based on the target fields and the corresponding processing methods for specific fields, the corresponding response values in the interface response are traversed through the reflection mechanism and the corresponding response structure is automatically generated. For example, if the include field contains three target fields a, b, and c, a response structure containing a, b, and c is automatically generated. If the filter field also includes target field a, target field a is erased from the above response structure, resulting in a response structure containing target fields b and c.

[0065] Step S330: assign the corresponding response value to the response structure to obtain the target response value, and return the target response value.

[0066] Specifically, the corresponding response value is assigned to the response structure, the data structure is reorganized, and the corresponding target response value of the interface is obtained through custom annotations.

[0067] Through this embodiment, when there is a target annotation in the interface, the specific field in the target annotation is parsed to obtain the target field, and based on the target field and the corresponding specific field, the corresponding target response value of the interface is obtained from the intercepted interface response value, so that the target response value can be customized according to the annotation and the interface.

[0068] In some of the embodiments, the target annotation includes a json annotation and a jsons annotation, wherein the jsons annotation includes multiple json annotations.

[0069] Specifically, in the interface layer, you can use json annotations to customize the return response, or you can use jsons annotations to modify the interface. The jsons annotation is a data structure that can contain multiple levels of json annotations.

[0070] In some embodiments, parsing a specific field in a target annotation to obtain the target field includes:

[0071] When the target annotation is a json annotation, the specific field in the json annotation is parsed, the target field.

[0072] When the target annotation is a jsons annotation, the jsons annotation is traversed to obtain the json annotation, and then the specific field in the json annotation is parsed to obtain the target field.

[0073] Specifically, if specific fields such as filter and include are included in a json annotation, if the target annotation is a json annotation, the specific fields are directly parsed to obtain the target field. If the target annotation is a jsons annotation, the jsons annotation array is first traversed to find the array containing the json annotation, and then the specific fields are parsed to obtain the target field.

[0074] Through this embodiment, according to whether the target annotation is a jsons annotation or a json annotation, corresponding processing is performed to obtain a specific field, and the specific field is further parsed to obtain the target field from the target annotation.

[0075] In some embodiments, the method further comprises:

[0076] After the interface receives the request, it performs interface logic processing on the request to obtain the interface response value.

[0077] Specifically, according to the method, address and other information defined in the request, interface logic processing is performed to obtain an interface response value.

[0078] The present embodiment is described and illustrated below through preferred embodiments.

[0079] Figure 4 This is a flowchart of the annotation-based custom return response method of this preferred embodiment. Figure 4 As shown, the method includes the following steps:

[0080] Step S410: After the interface receives the request, the interface performs interface logic processing on the request to obtain an interface response value.

[0081] Specifically, according to the method, address and other information defined in the request, interface logic processing is performed to obtain an interface response value.

[0082] Step S420: intercept the interface response value on the interface through a preset interceptor, and obtain the interface annotation corresponding to the interface response value through a reflection mechanism.

[0083] Specifically, the specific field refers to the field that defines the attributes of the class in the target annotation, and can filter the interface response value. By parsing the content of the specific field, the target field of the response interface is obtained.

[0084] Step S430: Determine whether the target annotation exists in the interface annotation by using a verification method.

[0085] Specifically, verification is performed through the supportsReturnType method in the HandlerMethodReturnValueHandler interface. The above target annotations include json annotations and\or jsons annotations, where the jsons annotation is a data structure and can contain multi-level json annotations.

[0086] If the target annotation does not exist, execute step S431; if the target annotation exists, execute step S440;

[0087] Step S431, returning the interface response value.

[0088] Step S440: Determine whether the target annotation is a json annotation or a jsons annotation. If it is a jsons annotation, execute step S441, then execute step S442. If it is a json annotation, execute step S442.

[0089] Specifically, in the interface layer, json annotations are used to customize the return response, and jsons annotations can also be used to modify the interface.

[0090] Step S441, traverse the jsons annotation to obtain the json annotation.

[0091] Specifically, since the jsons annotation can contain multiple levels of json annotations, the data structure in the jsons annotation is first traversed to find the array containing the json annotation.

[0092] Step S442: parse the specific field in the json annotation to obtain the target field.

[0093] Specifically, specific fields can be include and / or filter fields. You can select corresponding specific fields according to specific needs. The fields defined in the include and filter fields are separated by commas. The defined fields are also target fields. The include field includes the target field, and the filter field excludes the target field. The filter field has a higher priority than the include field. That is to say, when both include and filter fields exist in the target annotation, if the same target field is included, the filter exclusion process is performed with the filter having the highest priority.

[0094] Step S450: Obtain a corresponding response value from the interface response value according to the target field and the specific field, and generate a corresponding response structure.

[0095] Specifically, according to the acquired target field and the corresponding processing method of the specific field, the corresponding response value in the interface response value is traversed and acquired through the reflection mechanism, and the corresponding response structure is automatically generated.

[0096] Step S460: assign the corresponding response value to the response structure to obtain the target response value, and return the target response value.

[0097] Specifically, the corresponding response value is assigned to the response structure, the data structure is reorganized, and the corresponding target response value of the interface is obtained through custom annotations.

[0098] Through this preferred embodiment, the interface response value is first obtained according to the request, and then the interface response value on the interface is intercepted by the interceptor preset in the interface layer, and then the interface response value is filtered according to the filter and include fields in the interface annotation, and the response value that needs to be returned by the corresponding interface is customized, so that the response class can be reused. There is no need to define a new response structure for each interface. Instead, the corresponding response structure can be automatically generated according to the specific fields in the annotation, the response value to be returned is assigned to the response structure, and then the corresponding target response value is returned.

[0099] It should be noted that the steps shown in the above process or the flowcharts in the accompanying drawings can be executed in a computer system, such as a set of computer-executable instructions. Moreover, although the flowcharts show a logical order, in some cases, the steps shown or described can be executed in a different order. For example, between step S431 and step S440, step S440 can be executed first, and then step S431.

[0100] In this embodiment, a device for customizing a return response based on annotations is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the details that have been described will not be repeated. The terms "module", "unit", "sub-unit", etc. used below can be a combination of software and / or hardware that implements the predetermined functions. Although the devices described in the following embodiments are preferably implemented in software, implementation by hardware, or a combination of software and hardware, is also possible and conceivable.

[0101] Figure 5 This is a structural diagram of the annotation-based custom return response device of this embodiment. Figure 5 As shown, the device includes: an interception module 510, a verification module 520 and a response module 530, wherein:

[0102] The interception module 510 is used to intercept the interface response value on the interface through a preset interceptor, and obtain the interface annotation corresponding to the interface response value through a reflection mechanism.

[0103] The verification module 520 is used to determine whether the target annotation exists in the interface annotation through a verification method.

[0104] The response module 530 is used to obtain the target response value from the interface response value according to the specific field in the target annotation when the target annotation exists, and return the target response value, or to return the interface response value when the target annotation does not exist.

[0105] Through the device provided by this embodiment, a preset interceptor uniformly intercepts the interface response values of all interfaces. At this time, the interface response values include a large number of identical or similar response classes. Then, according to the annotation information on the interface corresponding to the interface response value, the response classes in the interface response value are distinguished, and the target response corresponding to the return interface is customized, so that a large number of identical or similar response classes can share the response class structure, and the target response value returned from the response class structure can be used directly. Furthermore, through the sharing of response classes in this embodiment, when the database table structure is modified, only one response class structure needs to be modified, thereby solving the problem in the prior art that response classes cannot be shared and are difficult to manage.

[0106] In some of the embodiments, the interception module 510 may also be used to preset the interceptor in the interface layer.

[0107] In some of the embodiments, the target annotation in the verification module 520 includes a json annotation and a jsons annotation, wherein the jsons annotation includes multiple json annotations.

[0108] In some embodiments, the response module 530 may also be used to:

[0109] Parse the specific fields in the target annotation to obtain the target fields;

[0110] According to the target field and specific field, obtain the corresponding response value from the interface response value and generate the corresponding response structure;

[0111] Assign the corresponding response value to the response structure, obtain the target response value, and return the target response value.

[0112] In some embodiments, the response module 530 may also be used to:

[0113] When the target annotation is a json annotation, parse the specific fields in the json annotation to obtain the target field;

[0114] When the target annotation is a jsons annotation, the jsons annotation is traversed to obtain the json annotation, and then the specific field in the json annotation is parsed to obtain the target field.

[0115] In some of the embodiments, the apparatus further comprises: a processing module;

[0116] The processing module is used to perform interface logic processing on the request after the interface receives the request and obtain the interface response value.

[0117] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.

[0118] This embodiment further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0119] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0120] It should be noted that, for specific examples in this embodiment, reference may be made to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.

[0121] In addition, in conjunction with the annotation-based custom return response method provided in the above embodiments, this embodiment may also provide a storage medium for implementation. The storage medium stores a computer program; when the computer program is executed by a processor, it implements any of the annotation-based custom return response methods in the above embodiments.

[0122] It should be understood that the specific embodiments described herein are only used to explain this application and are not used to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0123] Obviously, the accompanying drawings are merely examples or embodiments of the present application. A person skilled in the art can also apply the present application to other similar situations based on these drawings without inventive effort. Furthermore, it is understandable that, although the work involved in this development process may be complex and lengthy, certain design, manufacturing, or production changes based on the technical content disclosed in this application are merely routine technical means for a person skilled in the art and should not be considered to constitute a deficiency in the disclosure of the present application.

[0124] The term "embodiment" as used in this application refers to specific features, structures, or characteristics described in conjunction with the embodiment that can be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily mean that the embodiment is the same, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is understood, either explicitly or implicitly, by those skilled in the art that the embodiments described in this application can be combined with other embodiments when there is no conflict.

[0125] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of patent protection. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.

Claims

1. A custom return response method based on annotations, characterized in that: include: The interface response value on the interface is intercepted by the preset interceptor, and the interface annotation corresponding to the interface response value is obtained through the reflection mechanism; By using a verification method, it is determined whether the target annotation exists in the interface annotation; If the target annotation exists, the target response value is obtained from the interface response value according to the specific field in the target annotation, and the target response value is returned; wherein, the target response value is obtained from the interface response value according to the specific field in the target annotation, and the target response value is returned, including: parsing the specific field in the target annotation to obtain the target field; according to the target field and the specific field, obtaining the corresponding response value from the interface response value, and generating a corresponding response structure; assigning the corresponding response value to the response structure, reorganizing the data structure, obtaining the target response value, and returning the target response value; the target annotation includes a json annotation and a jsons annotation, and the jsons annotation includes multiple json annotations; wherein, the specific field includes an include field and / or a filter field, and the filter field has a higher priority than the include field; If the target annotation does not exist, the interface response value is returned.

2. The annotation-based custom return response method according to claim 1, characterized in that: Also includes: The interceptor is preset in the interface layer.

3. The annotation-based custom return response method according to claim 1 is characterized in that: The parsing of the specific field in the target annotation to obtain the target field includes: When the target annotation is a json annotation, the specific field in the json annotation is parsed to obtain the target field; When the target annotation is a jsons annotation, the jsons annotation is traversed to obtain the json annotation, and then the specific field in the json annotation is parsed to obtain the target field.

4. The annotation-based custom return response method according to claim 1, characterized in that: Also includes: After the interface receives the request, it performs interface logic processing on the request to obtain the interface response value.

5. A custom return response device based on annotations, characterized in that: The device includes: an interception module, a verification module and a response module; The interception module is used to intercept the interface response value on the interface through a preset interceptor, and obtain the interface annotation corresponding to the interface response value through a reflection mechanism; The verification module is used to determine whether the target annotation exists in the interface annotation through a verification method; The response module is configured to obtain a target response value from the interface response value according to a specific field in the target annotation when the target annotation exists, and return the target response value, wherein the obtaining the target response value from the interface response value according to the specific field in the target annotation and returning the target response value comprises: parsing the specific field in the target annotation to obtain the target field; obtaining a corresponding response value from the interface response value according to the target field and the specific field, and generating a corresponding response structure; assigning the corresponding response value to the response structure, reorganizing the data structure, obtaining the target response value, and returning the target response value; the target annotation comprises a json annotation and a jsons annotation, the jsons annotation comprises a plurality of the json annotations, the specific field comprises an include field and / or a filter field, and the filter field has a higher priority than the include field, or; Used to return the interface response value when the target annotation does not exist.

6. The annotation-based custom return response device according to claim 5, characterized in that: The interception module is further used to preset the interceptor in the interface layer.

7. A computer device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the annotation-based customized return response method according to any one of claims 1 to 4.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the annotation-based customized return response method according to any one of claims 1 to 4 are implemented.