Information acquisition method and device, electronic equipment and readable storage medium
By using reflection and aspect-oriented programming techniques in Java applications, the problem that enumeration fields cannot be directly used for front-end interface rendering and display was solved, and the unified acquisition of Chinese descriptions of enumeration types was achieved, reducing development and maintenance costs.
Patent Information
- Application Number
- CN202110690717.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-22
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2041-06-22
AI Technical Summary
In Java applications, the lack of Chinese descriptions for enumeration fields makes them unsuitable for direct use in front-end interface rendering and display, resulting in a large workload and high development costs.
We use reflection technology to intercept returned objects, obtain Chinese description information of enumeration type fields, and use aspect-oriented programming to uniformly intercept service interfaces, adapting returned objects of different structures and reducing development workload.
It enables a unified retrieval of Chinese descriptions for enumeration types, reducing development and maintenance costs, avoiding the need for different code to handle return objects with different structures, and improving development efficiency.
Smart Images

Figure CN115509505B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computers, and in particular to an information acquisition method and device, electronic equipment and a readable storage medium. BACKGROUND
[0002] Backend services of various types of applications are developed using Java-related frameworks of object-oriented programming languages in large quantities, and provide data services and business capabilities for different types of front-end applications such as World Wide Web (WEB) and Application (APP) through HyperText Transfer Protocol (HTTP) interfaces. In the return object of the service interface provided by the Java application, there are many fields using enumeration types, such as user type enumeration (the enumeration value is a normal user and a special user). The enumeration field lacks corresponding Chinese descriptions and cannot be directly used for rendering and display of the front-end interface.
[0003] At present, in order to enable the enumeration field to be directly used for rendering and display of the front-end interface, a Chinese description needs to be given to each enumeration value as a parameter through a constructor method, and code for taking out the Chinese description in the enumeration type is added to the return object. When the structure of the return object is different, the code for taking out the Chinese description in the enumeration type is also different. When the interface business logic is very simple but the return object structure is very complex, the amount of added code will far exceed the business logic code; or when an enumeration appears in the return objects of many interfaces, changes in the enumeration value will cause a large amount of code changes. This results in a large amount of development work and high development cost. SUMMARY
[0004] To solve at least one of the above technical problems, the embodiments of the present application provide an information acquisition method and device, electronic equipment and a readable storage medium, which solve the problem of high development cost in the current method of enabling the enumeration field to be directly used for rendering and display of the front-end interface.
[0005] To achieve the above purpose, in a first aspect, the embodiments of the present application provide an information acquisition method, comprising:
[0006] intercepting a return object;
[0007] acquiring a field in the return object and a type of the field using a reflection technology;
[0008] in a case where the field includes a target field, acquiring Chinese description information of an enumeration type field in the target field, the target field including the enumeration type field.
[0009] Optionally, the intercepting the return object comprises:
[0010] intercept the return object using aspect programming technology, the return object being a response based on a front-end business request.
[0011] Optionally, before the step of obtaining the Chinese description information of the enumeration type field in the target field, the method further comprises:
[0012] establishing a target code for obtaining the Chinese description information;
[0013] In the case that the field includes a target field, the step of obtaining the Chinese description information of the enumeration type field in the target field comprises:
[0014] In the case that the type of the target field is an enumeration type, calling the target code to obtain the Chinese description information of the target field;
[0015] In the case that the type of the target field is a target type, calling an iterator to traverse the target field, recursively using reflection technology to determine the enumeration type field in the target type, and calling the target code to obtain the Chinese description information of the enumeration type field in the target type, wherein the target type includes an array / list / hash type;
[0016] In the case that the type of the target field is a custom type, recursively using reflection technology to determine the enumeration type field in the custom type, and calling the target code to obtain the Chinese description information of the enumeration type field in the custom type.
[0017] Optionally, before the step of obtaining the Chinese description information of the enumeration type field in the target field, the method further comprises:
[0018] adding a first field in the return object;
[0019] After the step of obtaining the Chinese description information of the enumeration type field in the target field, the method further comprises:
[0020] taking the Chinese description information as the content of the first field.
[0021] Optionally, the step of taking the Chinese description information as the content of the first field comprises:
[0022] adding a suffix to the Chinese description information, and taking the Chinese description information with the added suffix as the content of the first field;
[0023] or,
[0024] adding a prefix to the Chinese description information, and taking the Chinese description information with the added prefix as the content of the first field.
[0025] In a second aspect, an embodiment of the present application provides an information acquisition device, comprising:
[0026] A first processing module is configured to intercept a return object;
[0027] A first acquisition module is configured to acquire a field in the return object and a type of the field by using a reflection technology;
[0028] A second acquisition module is configured to acquire Chinese description information of an enumeration type field in a target field in a case where the field includes the target field, and the target field includes the enumeration type field.
[0029] Optionally, the first processing module comprises:
[0030] The return object is intercepted by using an aspect programming technology, and the return object is a response based on a front-end business request.
[0031] Optionally, before the second acquisition module, the device further comprises:
[0032] Target code for acquiring the Chinese description information is established;
[0033] The second acquisition module comprises:
[0034] In a case where the type of the target field is an enumeration type, the target code is called to acquire the Chinese description information of the target field;
[0035] In a case where the type of the target field is a target type, an iterator is called to traverse the target field, the reflection technology is recursively used to determine an enumeration type field in the target type, and the target code is called to acquire Chinese description information of the enumeration type field in the target type, wherein the target type includes an array / list / hash type.
[0036] In a case where the type of the target field is a custom type, the reflection technology is recursively used to determine an enumeration type field in the custom type, and the target code is called to acquire Chinese description information of the enumeration type field in the custom type.
[0037] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor, a memory, a computer program stored in the memory and executable on the processor, and the computer program is executed by the processor to implement the steps in the information acquisition method according to the first aspect.
[0038] In a fourth aspect, an embodiment of the present application provides a readable storage medium, and the readable storage medium stores a program, and the program is executed by a processor to implement the steps in the information acquisition method according to the first aspect.
[0039] In the embodiments of the present application, the information acquisition method comprises intercepting a return object, using a reflection technology to acquire a field in the return object and a type of the field. In the case that the field comprises a target field, the Chinese description information of an enumeration type field in the target field is acquired, and the target field comprises the enumeration type field. By using the reflection technology, the code for taking out the enumeration type Chinese description can be adapted to return objects of different structures, i.e., the Chinese description of return objects of different structures can be acquired by using the same code. Compared with the prior art, different codes for taking out the enumeration type Chinese description need to be written for the structures of return objects of different structures, which reduces the development workload and development cost. BRIEF DESCRIPTION OF DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings in the specification are described as follows. Obviously, the following drawings are only some embodiments of the present application, and for those skilled in the art, other drawings can be obtained without creative labor on the basis of the drawings.
[0041] Figure 1 is one of the flowcharts of the information interaction method provided by the embodiments of the present application;
[0042] Figure 2 is the second flowchart of the information interaction method provided by the embodiments of the present application;
[0043] Figure 3 is a structural schematic diagram of the information interaction device provided by the embodiments of the present application;
[0044] Figure 4 is a structural schematic diagram of the electronic device provided by the embodiments of the present application. DETAILED DESCRIPTION
[0045] The technical solutions in the embodiments of the present application will be described clearly and completely in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments. On the basis of the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the protection scope of the present application.
[0046] In the prior art, in the return object of a service interface provided by a Java application, there are many fields using enumeration types, such as a user type enumeration (values are type 1 and type 2). When the enumeration field is serialized into a json or xml format interface return value, it can only be converted into the code name corresponding to the enumeration value (for example, type 1) without a corresponding Chinese description, and therefore cannot be directly used for rendering and display of a front-end interface. In order to display the enumeration type as a Chinese description that can be understood by a user and directly used for rendering and display of a front-end interface, two ways can be adopted, that is, front-end application conversion processing and back-end application conversion processing.
[0047] The processing mode of the front-end application conversion processing is that the front-end application maintains a mapping relationship table of full enumeration and Chinese description according to an agreed enumeration type. When rendering an interface, a code is written according to the enumeration value (for example, type 1) in the return value of the back-end interface to manually obtain the Chinese description from the mapping relationship table for display. When the value of the back-end enumeration is newly added, modified or deleted, the front-end must also update the code synchronously, and the WEB and H5 front-end applications need to be re-deployed online. The APP front-end application also needs to be repackaged and published, and a new version needs to be uploaded to the application market of each channel.
[0048] Therefore, the front-end application conversion processing has the following problems:
[0049] 1. The enumeration type field needs to be manually processed to be displayed, which causes the front-end to be unable to directly use the data returned by the back-end service interface for some ready-made plug-ins and components, and the data needs to be transmitted to the component after the enumeration field is manually processed.
[0050] 2. When the Chinese description information in the enumeration type field is changed, the APP front-end application needs to be re-released, updated and uploaded to the application market of each channel, and there is a long audit period for uploading to the IOS application store, and the update cost is very high.
[0051] 3. The WEB, H5 and APP front-end applications of the same system all need to independently maintain a full enumeration value and Chinese description mapping table. The APP application needs to be actively updated by the user, and if the user does not update the APP, the enumeration field in the business data will be inconsistent in the WEB and H5 application display results. At the same time, the development workload will significantly increase with the increase in the number of enumeration fields, and the development and maintenance cost is high.
[0052] The processing mode of the backend application conversion processing is as follows: first, when creating an enumeration type field, each enumeration value is input through a constructor method parameter with a Chinese description, which is stored in an enumeration class in a string type field. Then, a string type field is additionally added to each enumeration field in the return object for storing the enumeration corresponding Chinese description. Finally, when constructing the return object, the code needs to be manually written according to the structure of the return object to process each enumeration field, take out the Chinese description in the enumeration class, and set it to the additional field in the return object. The structure of the return object is different, and the code for taking out the enumeration type Chinese description is also different. This processing scheme needs to add a piece of non-reusable code for all interfaces with enumeration fields to parse the return object and set the Chinese description. When the interface business logic is very simple but the return object structure is very complex, the amount of code for processing enumeration values will far exceed the business logic code. When an enumeration appears in the return object of many interfaces, the enumeration value change will cause a large amount of code change.
[0053] Therefore, the backend application conversion processing has the following problems:
[0054] 1. A piece of conversion code needs to be written for each interface with enumeration fields in the return value, which strongly depends on the structure of the return object and cannot be reused. When the return object structure is very complex, the amount of conversion code will even far exceed the current interface business logic code. This significantly increases the development cost and slows down the development progress.
[0055] 2. When the same enumeration is used in a large number of interfaces, the enumeration needs to be changed, which involves the code of all related interfaces. This significantly increases the maintenance cost.
[0056] To solve at least one of the above technical problems, an information acquisition method is provided, which comprises Figure 1 , including:
[0057] Step 101, intercepting a return object;
[0058] Step 102, using a reflection technology to acquire a field in the return object and a type of the field;
[0059] Step 103, in a case where the field includes a target field, acquiring Chinese description information of an enumeration type field in the target field, the target field including the enumeration type field.
[0060] Specifically, when the back-end application creates the enumeration type code, each enumeration value is stored in a string type field of the enumeration type through the Chinese description information in the constructor method parameter. When the back-end application responds based on the front-end business request, the response based on the front-end business request is intercepted, that is, the return object is returned, and the JAVA reflection technology is used to obtain the field in the return object and the type of the field. The target field is the field that needs to obtain the Chinese description information for front-end interface rendering and display, and the target field includes the enumeration type field.
[0061] As an example, the Chinese information of the enumeration type field in the target field is obtained from the intercepted return object.
[0062] In the embodiment of the application, the information obtaining method includes intercepting a return object, using reflection technology to obtain fields in the return object and the types of the fields. In the case that the fields include target fields, the Chinese description information of the enumeration type field in the target field is obtained, and the target field includes the enumeration type field. By using the reflection technology, the code for taking out the enumeration type Chinese description can be adapted to different structures of the return object, that is, the Chinese description of the return object with different structures can be obtained by using the same code. Compared with the prior art, different codes for taking out the enumeration type Chinese description need to be written for the structures of the return object with different structures, which reduces the development workload and development cost.
[0063] In addition, the reflection technology can be used to adapt to all enumeration type fields, and when the enumeration type changes, only the internal structure of the enumeration type field needs to be adjusted, without the need to adjust the mapping relationship table or the conversion code of all interfaces. Thus, the conversion code change range is reduced, and the maintenance cost is further reduced.
[0064] Optionally, the intercepted return object includes:
[0065] The return object is intercepted by using aspect programming technology, and the return object is a response based on a front-end business request. The JAVA aspect programming technology is used to uniformly intercept and proxy the service interface, and then the Chinese description information of the enumeration type field in the target field is obtained, which can further reduce the development workload.
[0066] Optionally, before the step of obtaining the Chinese description information of the enumeration type field in the target field, the method further includes:
[0067] Establishing target code for obtaining the Chinese description information;
[0068] The step of obtaining the Chinese description information of the enumeration type field in the target field in the case that the fields include target fields includes:
[0069] In the case that the type of the target field is an enumeration type, calling the target code to obtain Chinese description information of the target field;
[0070] In a case where the type of the target field is a target type, calling an iterator to traverse the target field, recursively using reflection technology to determine an enumeration type field in the target type, and calling the target code to obtain Chinese description information of the enumeration type field in the target type, wherein the target type includes an array / list / hash type;
[0071] In the case that the type of the target field is a user-defined type, the reflection technology is recursively used to determine the enumeration type field in the user-defined type, and the target code is called to obtain Chinese description information of the enumeration type field in the user-defined type.
[0072] Specifically, the target code is used to retrieve the Chinese description information in the target field. Because the embodiments of this application use Java launch technology, the target code can adapt to return objects of all structures and fields of all enumeration types. Even if the enumeration type changes, only the internal structure of the enumeration type needs to be adjusted, without adjusting the target code. Therefore, the target code has the effect of being coded once and used forever.
[0073] In an embodiment of the present application, when the type of the target field is an enumeration type, the target code is directly called to obtain the Chinese description information of the target field.
[0074] Target types include arrays, lists, and hashes, which may also contain enumeration fields. If the target field is of the target type, an iterator is called to traverse the target field, recursively using reflection to identify the enumeration fields within the target type. The target code is then called to retrieve the Chinese descriptions of these enumeration fields. An iterator, also known as a cursor, is a software design pattern used in programming. It is an interface that can iterate over container objects (such as linked lists or arrays), freeing the designer from the implementation details of memory allocation for the container objects. Different languages implement iterators differently. Some object-oriented languages, such as Java, have iterator features built into the language, seamlessly integrating them. This is known as an implicit iterator. Recursion is a common Java technique, and can be simply understood as a self-calling function. If the target field is of the target type, the corresponding iterator is used to traverse the objects in the container, recursively processing each object using Java reflection, and then the target code is called to retrieve the Chinese descriptions of the target fields.
[0075] The custom type is a type defined by the user, and the custom type can also include an enumeration type. In the case where the type of the target field is a custom type, the JAVA reflection technology is used recursively to process, and the target code is called to obtain the Chinese description information of the target field.
[0076] The basic data type and its wrapper type string cannot include an enumeration type, and in the case where the type of the target field is a basic data type and its wrapper type string, it is directly skipped without processing.
[0077] Optionally, before the step of obtaining the Chinese description information of the enumeration type field in the target field, the method further includes:
[0078] adding a first field in the return object;
[0079] After the step of obtaining the Chinese description information of the enumeration type field in the target field, the method further includes:
[0080] storing the Chinese description information as the content of the first field.
[0081] Specifically, in the return object, for the enumeration type field, a first field is added for storing the Chinese description information obtained by using the target code. The type of the first field can be a string type. After obtaining the Chinese description information, the Chinese description information is stored in the first field.
[0082] Optionally, the step of storing the Chinese description information as the content of the first field includes:
[0083] adding a suffix to the Chinese description information, and storing the Chinese description information with the added suffix as the content of the first field. Alternatively, adding a prefix to the Chinese description information, and storing the Chinese description information with the added prefix as the content of the first field.
[0084] Specifically, in the return object, a first field for storing Chinese description can be additionally added for each enumeration field E, and is named as F in a fixed form. For example, in the form of "E name + Desc suffix", for the user type enumeration userType, a userTypeDesc field is created. Alternatively, a prefix can be added to the Chinese description information, and the Chinese description information with the added prefix is stored as the content of the first field. The naming rule of the first field is used to agree that the enumeration field name is searched according to the enumeration field name during reflection processing, so as to facilitate the search.
[0085] In order to better illustrate the information acquisition method provided by the application, the method provided by the application is described below with a complete example.
[0086] Referring to Figure 2, the first step: create an enumeration type, when creating an enumeration type code, each enumeration value is described in Chinese by the constructor method parameter, stored in an enumeration type of a string type field. And create the target code for getting Chinese description.
[0087] The second step: in the interface return object, for each enumeration field E, an additional first field is added, the type of the first field is a string type, used to store the Chinese description information of the enumeration type. In order to facilitate the search of the first field, the suffix can be added to the Chinese description information, and the Chinese description information after adding the suffix is used as the content of the first field. Or, add a prefix to the Chinese description information, and the Chinese description information after adding the prefix is used as the content of the first field. Taking the added suffix Desc as an example, for the user type enumeration userType, a userTypeDesc is created as the content of the first field.
[0088] The third step: using aspect programming (such as Aspect, Spring AOP) to intercept and proxy all service interfaces to get the return object of the interface.
[0089] The fourth step: using Java reflection technology to get all fields in the return object and judge the type
[0090] 1) If it is a basic data type and its wrapper class, string type, skip and do not process
[0091] 2) If it is an enumeration type, call the target code to get the Chinese description, and set it to the field named "E+desc"
[0092] 3) If it is an array, list, hash table, use the corresponding iterator to traverse the objects in the container, and recursively use the reflection technology to process each object
[0093] 4) If it is a custom wrapper type, such as User, recursively use the reflection technology to process
[0094] Until the Chinese description of all enumeration fields in the return object is set to the corresponding first field.
[0095] The fifth step: return the return object to the front end.
[0096] The embodiment of the application uses Java reflection technology to convert enumeration to Chinese description, so that the code can adapt to all different structures of the return object, and at the same time, using aspect programming technology to proxy all service interfaces, and uniformly adding enumeration conversion Chinese capability to the interface. Eliminate all interfaces of the non reusable enumeration conversion code, with the effect of once coding permanent availability.
[0097] In addition, the method provided by the embodiment of the present application can update the entire system immediately as long as the backend application is updated. Various front-end applications do not need to be republished, and the problem of inconsistent display of WEB and H5 applications and APP applications does not exist. Meanwhile, the front end obtains the processed data through an interface, and the processed data can be directly transmitted into a general plug-in or component for use.
[0098] The embodiment of the present application provides an information acquisition device 200, referring to Figure 3 , comprising:
[0099] The first processing module 201 is configured to intercept a return object.
[0100] The first acquisition module 202 is configured to acquire a field in the return object and a type of the field by using a reflection technology.
[0101] The second acquisition module 203 is configured to acquire Chinese description information of an enumeration type field in a target field in a case where the field includes the target field, and the target field includes the enumeration type field.
[0102] Optionally, the first processing module 201 comprises:
[0103] The return object is intercepted by using an aspect programming technology, and the return object is a response based on a front-end business request.
[0104] Optionally, before the second acquisition module 203, the device further comprises:
[0105] Target code for acquiring the Chinese description information is established.
[0106] The second acquisition module 203 comprises:
[0107] In a case where the type of the target field is an enumeration type, the target code is called to acquire the Chinese description information of the target field.
[0108] In a case where the type of the target field is a target type, an iterator is called to traverse the target field, the reflection technology is recursively used to determine an enumeration type field in the target type, and the target code is called to acquire Chinese description information of the enumeration type field in the target type, wherein the target type includes an array / list / hash type.
[0109] In a case where the type of the target field is a custom type, the reflection technology is recursively used to determine an enumeration type field in the custom type, and the target code is called to acquire Chinese description information of the enumeration type field in the custom type.
[0110] Optionally, the second acquisition module 203 further comprises:
[0111] adding a first field in the return object;
[0112] taking the Chinese description information as content of the first field.
[0113] Optionally, the step of taking the Chinese description information as content of the first field comprises:
[0114] adding a suffix to the Chinese description information, and taking the Chinese description information with the added suffix as content of the first field;
[0115] Alternatively,
[0116] adding a prefix to the Chinese description information, and taking the Chinese description information with the added prefix as content of the first field.
[0117] The information obtaining module 200 can implement each process that can be implemented by the information obtaining method embodiment in the present application, and achieve the same beneficial effects. To avoid repetition, details are not described herein.
[0118] An electronic device is provided in the present application. As shown in Figure 4 The electronic device 300 comprises a processor 301, a memory 302, and a computer program stored in the memory 302 and executable on the processor. Each component in the electronic device 300 is coupled together through a bus system 303. It can be understood that the bus system 303 is used to realize the connection and communication between the components.
[0119] The processor 301 is configured to intercept a return object.
[0120] The processor 301 is configured to obtain a field in the return object and a type of the field using a reflection technology.
[0121] In a case where the field comprises a target field, the processor 301 is configured to obtain Chinese description information of an enumeration type field in the target field, the target field comprising the enumeration type field.
[0122] The processor 301 is further configured to intercept the return object using an aspect programming technology, the return object being a response based on a front-end business request.
[0123] The processor 301 is further configured to establish a target code for obtaining the Chinese description information.
[0124] The step of obtaining the Chinese description information of the enumeration type field in the target field in the case where the field comprises the target field comprises:
[0125] In a case where the type of the target field is an enumeration type, the processor 301 is configured to call the target code to obtain the Chinese description information of the target field.
[0126] In a case where the type of the target field is a target type, an iterator is invoked to traverse the target field, a reflection technique is recursively used to determine an enumeration type field in the target type, and the target code is invoked to obtain Chinese description information of the enumeration type field in the target type, wherein the target type includes an array / list / hash type;
[0127] In a case where the type of the target field is a custom type, a reflection technique is recursively used to determine an enumeration type field in the custom type, and the target code is invoked to obtain Chinese description information of the enumeration type field in the custom type.
[0128] The processor 301 is further configured to add a first field in the returned object;
[0129] The Chinese description information is taken as content of the first field.
[0130] The processor 301 is further configured to add a suffix to the Chinese description information, and the Chinese description information after the suffix is added is taken as content of the first field.
[0131] Alternatively,
[0132] A prefix is added to the Chinese description information, and the Chinese description information after the prefix is added is taken as content of the first field.
[0133] The electronic device 300 provided by the embodiment of the present application can realize each process that can be realized by the information acquisition method embodiment of the present application, and achieve the same beneficial effects. To avoid repetition, details are not described here.
[0134] The embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program. The computer program is executed by a processor to realize each process of the information acquisition method embodiment and achieve the same technical effects. To avoid repetition, details are not described here. The computer readable storage medium includes a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and the like.
[0135] The embodiments of the present application are described above in combination with the drawings, but the present application is not limited to the above-described specific embodiments. The above-described specific embodiments are only illustrative, rather than limiting. Those skilled in the art can make many forms under the inspiration of the present application without departing from the scope of the present application and the protection scope of the claims.
Claims
1. An information acquisition method characterized by comprising: The method comprises the following steps: intercepting a return object; acquiring a field in the return object and a type of the field by using a reflection technology; in a case where the field comprises a target field, the target field being a field for which Chinese description information needs to be acquired for front-end interface display, acquiring Chinese description information of an enumeration type field in the target field, the target field comprising an enumeration type field; the intercepting the return object comprises: intercepting the return object by using an aspect programming technology, the return object being a response based on a front-end business request; before the acquiring the Chinese description information of the enumeration type field in the target field, the method further comprises: establishing a target code for acquiring the Chinese description information; the acquiring the Chinese description information of the enumeration type field in the target field in a case where the field comprises the target field comprises: in a case where a type of the target field is an enumeration type, calling the target code to acquire the Chinese description information of the target field; in a case where the type of the target field is a target type, calling an iterator to traverse the target field, recursively using the reflection technology to determine an enumeration type field in the target type, and calling the target code to acquire the Chinese description information of the enumeration type field in the target type, wherein the target type comprises an array / list / hash type; in a case where the type of the target field is a custom type, recursively using the reflection technology to determine an enumeration type field in the custom type, and calling the target code to acquire the Chinese description information of the enumeration type field in the custom type.
2. The method of claim 1, wherein, before the acquiring the Chinese description information of the enumeration type field in the target field, the method further comprises: adding a first field in the return object; after the acquiring the Chinese description information of the enumeration type field in the target field, the method further comprises: taking the Chinese description information as content of the first field.
3. The method of claim 2, wherein, the taking the Chinese description information as the content of the first field comprises: adding a suffix to the Chinese description information, and taking the Chinese description information with the added suffix as the content of the first field; or adding a prefix to the Chinese description information, and taking the Chinese description information with the added prefix as the content of the first field. The device comprises:
4. An information acquisition apparatus characterized by comprising: a first processing module configured to intercept a return object; a first acquiring module configured to acquire a field in the return object and a type of the field by using a reflection technology; a second acquiring module configured to, in a case where the field comprises a target field, acquire Chinese description information of an enumeration type field in the target field, the target field being a field for which Chinese description information needs to be acquired for front-end interface display, the target field comprising an enumeration type field; the first processing module comprises: intercepting the return object by using an aspect programming technology, the return object being a response based on a front-end business request; the device further comprises: a target code for acquiring the Chinese description information; the second acquiring module comprises: In the case that the type of the target field is an enumeration type, the target code is invoked to obtain the Chinese description information of the target field; In the case that the type of the target field is a target type, an iterator is invoked to traverse the target field, a reflection technique is recursively used to determine an enumeration type field in the target type, and the target code is invoked to obtain the Chinese description information of the enumeration type field in the target type, wherein the target type includes an array / list / hash type; In the case that the type of the target field is a custom type, a reflection technique is recursively used to determine an enumeration type field in the custom type, and the target code is invoked to obtain the Chinese description information of the enumeration type field in the custom type.
5. An electronic device, comprising: A processor, a memory, a computer program stored on the memory and capable of running on the processor, wherein the computer program is executed by the processor to implement the steps in the information acquisition method according to any one of claims 1 to 3.
6. A readable storage medium characterized by, A readable storage medium, wherein a program is stored on the readable storage medium, and the program is executed by a processor to implement the steps in the information acquisition method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Method for automatically complementing Chinese value through English enumeration
CN112882843A