A method, device, equipment and storage medium for generating field assignment code
By automatically generating field assignment code, the low efficiency and accuracy problems caused by manual writing are solved, and accurate field assignment between the client and server is achieved.
Patent Information
- Application Number
- CN202011463498.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-11
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-12-11
AI Technical Summary
In application development, since the representation of fields for the same function in client code and server code may be different, manual writing of field assignment codes is inefficient and difficult to guarantee accuracy, which can easily lead to inaccurate field assignments.
By obtaining the field list of the server and client codes, the field identification information is matched based on the preset matching rules, the field correspondence is established, the assignment relationship is determined, and the automated field assignment code is generated to realize the field assignment.
It improves the efficiency and accuracy of field assignment code generation and ensures the accuracy of the field assignment process between the client and the server.
Smart Images

Figure CN114625348B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing, and in particular to a method, device, equipment and storage medium for generating a field assignment code. Background Art
[0002] During application development, the representation of fields for the same function in the client code or server code may be different. In order to avoid client crashes caused by fields in data packets from the server not being parsed by the client, an intermediate layer needs to be set between the client and the server to implement field assignment between the two.
[0003] Currently, developers need to manually write field assignment codes as an intermediate layer to implement field assignment between the server and the client. Obviously, the manual writing method makes the generation efficiency of field assignment codes low and the accuracy cannot be guaranteed. Therefore, in actual applications, it is easy to cause inaccurate field assignment problems. Summary of the invention
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a method, device, equipment and storage medium for generating field assignment codes, which can automatically generate field assignment codes, improve the generation efficiency of field assignment codes, and improve the accuracy of field assignment based on the generated field assignment codes.
[0005] In a first aspect, the present disclosure provides a method for generating a field assignment code, the method comprising:
[0006] Obtain a field list corresponding to a first type instance and a second type instance having a mapping relationship, respectively; wherein the first type instance and the second type instance belong to a server code and a client code of the same application, respectively, and the field list is used to store field identification information of fields in the corresponding type instance, and the field identification information includes a field name and / or field annotation information;
[0007] Based on a preset matching rule, the field identification information in the field lists corresponding to the first type instance and the second type instance are matched, and a field correspondence relationship is established between the fields corresponding to the successfully matched field identification information;
[0008] Determine a field assignment relationship corresponding to the field correspondence relationship; wherein the field assignment relationship is used to characterize the assignment relationship between fields in the field correspondence relationship;
[0009] Based on the field assignment relationship, a field assignment code is generated; wherein the field assignment code is used to be deployed on the client of the application to implement field assignment.
[0010] In an optional implementation manner, the field identification information further includes a field type, and determining a field value assignment relationship corresponding to the field correspondence relationship includes:
[0011] Determining a field value assignment method for the field correspondence based on the field type of the field in the field correspondence;
[0012] Based on the field assignment method, a field assignment relationship corresponding to the field correspondence relationship is generated.
[0013] In an optional implementation manner, the fields in the field correspondence relationship include server fields and client fields, and determining the field value assignment method for the field correspondence relationship based on the field types of the fields in the field correspondence relationship includes:
[0014] Determine whether the field types of the server field and the client field in the field correspondence are consistent;
[0015] If it is determined that the field types of the server-side field and the client-side field are consistent, a direct assignment method is determined as the field assignment method of the field correspondence relationship; the direct assignment method is used to indicate direct assignment of a field;
[0016] If it is determined that the field types of the server field and the client field are inconsistent, an indirect assignment method is determined based on the field types of the server field and the client field, and the indirect assignment method is determined as the field assignment method of the field correspondence relationship; the indirect assignment method is used to indicate that the field assignment is implemented through a preset algorithm.
[0017] In an optional implementation manner, the fields in the field correspondence are pre-configured with a first assignment method and a second assignment method, and the first assignment method has a higher priority than the second assignment method;
[0018] The determining of the field value assignment relationship corresponding to the field correspondence relationship includes:
[0019] Determine the first assignment method having a higher priority than the second assignment method as the field assignment method of the field correspondence relationship;
[0020] Based on the field assignment method, a field assignment relationship of the field correspondence relationship is generated.
[0021] In an optional implementation manner, after matching the field identification information in the field lists corresponding to the first type instance and the second type instance respectively based on the preset matching rule, the method further includes:
[0022] If it is detected that the matching results of the field identification information in the field lists corresponding to the first type instance and the second type instance respectively meet the error reporting condition, an error reporting is performed; the error reporting condition is used to characterize the abnormal matching situation of the field identification information.
[0023] In an optional implementation manner, after generating the field assignment code based on the field assignment relationship corresponding to the field correspondence relationship, the method further includes:
[0024] Based on the field correspondence, field visibility in the first type instance and the second type instance is adjusted.
[0025] In an optional implementation manner, after generating the field assignment code based on the field assignment relationship corresponding to the field correspondence relationship, the method further includes:
[0026] Detect whether there is a no-argument constructor in the first type instance and the second type instance;
[0027] If it does not exist, a no-parameter constructor is added to the first type instance and the second type instance respectively.
[0028] In a second aspect, the present disclosure further provides a device for generating a field assignment code, the device comprising:
[0029] an acquisition module, used to acquire a field list corresponding to a first type instance and a second type instance having a mapping relationship, respectively; wherein the first type instance and the second type instance belong to a server code and a client code of the same application, respectively, and the field list is used to store field identification information of fields in the corresponding type instance, wherein the field identification information includes a field name and / or field annotation information;
[0030] A matching module, configured to match the field identification information in the field lists corresponding to the first type instance and the second type instance respectively based on a preset matching rule, and establish a field correspondence relationship between the fields corresponding to the field identification information that successfully matches;
[0031] A determination module, used to determine a field assignment relationship corresponding to the field correspondence relationship; wherein the field assignment relationship is used to characterize the assignment relationship between the fields in the field correspondence relationship;
[0032] A generation module is used to generate a field assignment code based on the field assignment relationship; wherein the field assignment code is used to be deployed on the client of the application, and based on the value of the specified field from the server of the application, the field corresponding to the specified field in the client is assigned a value.
[0033] In a third aspect, the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device implements the above method.
[0034] In a fourth aspect, the present disclosure provides a device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the computer program.
[0035] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:
[0036] The disclosed embodiment provides a method for generating a field assignment code. First, a list of fields corresponding to a first type instance and a second type instance having a mapping relationship is obtained. Then, based on a preset matching rule, the field identification information in the field list corresponding to the first type instance and the second type instance is matched, and a field correspondence is established between the fields corresponding to the successfully matched field identification information. Secondly, the field assignment relationship corresponding to the field correspondence relationship is determined. Finally, based on the field assignment relationship, a field assignment code is generated for deployment on the client of an application, and the value of a specified field on the server is assigned to the field corresponding to the specified field in the client. The disclosed embodiment automatically realizes the generation of field assignment codes, improves the efficiency of generating field assignment codes, and improves the accuracy of field assignment based on the generated field assignment code. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0039] Figure 1 A flowchart of a method for generating a field assignment code provided in an embodiment of the present disclosure;
[0040] Figure 2 A schematic diagram of the structure of a device for generating a field assignment code provided in an embodiment of the present disclosure;
[0041] Figure 3 A schematic diagram of the structure of a field assignment code generation device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0042] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0043] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0044] In actual applications, if there are fields with assignment relationships between the client code and the server code in the application, in order to avoid adjustments at the code level, it is usually necessary to set up an intermediate layer to implement code assignment between the server and the client.
[0045] At present, the middle layer is usually implemented by programmers manually writing field assignment codes. Obviously, the efficiency is low, and the accuracy of the manually written field assignment codes cannot be guaranteed, which may lead to a decrease in the accuracy of code assignment based on the manually written field assignment codes.
[0046] To this end, the embodiment of the present disclosure provides a method for generating a field assignment code. First, a list of fields corresponding to a first type instance and a second type instance having a mapping relationship is obtained. Then, based on a preset matching rule, the field identification information in the list of fields corresponding to the first type instance and the second type instance is matched, and a field correspondence is established between the fields corresponding to the successfully matched field identification information. Secondly, the field assignment relationship corresponding to the field correspondence relationship is determined. Finally, based on the field assignment relationship, a field assignment code is generated for deployment on the client of an application, and the value of a specified field on the server is assigned to the field corresponding to the specified field in the client. The embodiment of the present disclosure automatically realizes the generation of field assignment codes, improves the efficiency of generating field assignment codes, and improves the accuracy of field assignment based on the generated field assignment code.
[0047] Based on this, the present disclosure provides a method for generating a field assignment code, referring to Figure 1 , is a flow chart of a method for generating a field assignment code provided by an embodiment of the present disclosure, the method comprising:
[0048] S101: Obtain a list of fields corresponding to the first type instance and the second type instance having a mapping relationship.
[0049] Among them, the first type instance and the second type instance belong to the server code and client code of the same application respectively, and the field list is used to store field identification information of the fields in the corresponding type instance, and the field identification information includes field name and / or field annotation information.
[0050] In the disclosed embodiments, a type instance, which may also be referred to as a class instance, is a unit for implementing application functions, and generally includes a plurality of fields. The disclosed embodiments pre-set a mapping relationship between a first type instance and a second type instance in the server code and the client code of the same application, to indicate the need to generate a field assignment relationship between the first type instance and the second type instance. In practical applications, mapping relationships between multiple pairs of type instances can be set from the server code and the client code of the same application, and the mapping relationships between the multiple pairs of type instances can be stored in a configuration file for use in the generation of field assignment codes. Among them, the first type instance and the second type instance can be any pair of mapping relationships among the multiple pairs of type instances.
[0051] In the embodiment of the present disclosure, after determining the first type instance and the second type instance having a mapping relationship, the field identification information of the field is obtained from the first type instance and the second type instance respectively, and then the field identification information is stored in the field list of the corresponding type instance. The field identification information may include information such as field name and field annotation information for describing field characteristics. The field annotation information includes relevant information of the field, such as variable information related to the field. In addition, the field identification information may also include field type, etc.
[0052] In an optional implementation, ASM dynamic bytecode technology may be used to collect field identification information of fields in the first type instance and the second type instance, and store the information in a corresponding field list.
[0053] It is worth noting that the embodiments of the present disclosure do not limit the manner of obtaining the field identification information of the fields in the type instance.
[0054] S102: Based on a preset matching rule, match the field identification information in the field lists corresponding to the first type instance and the second type instance respectively, and establish a field correspondence relationship between the fields corresponding to the successfully matched field identification information.
[0055] In an embodiment of the present disclosure, after obtaining the field lists corresponding to the first type instance and the second type instance respectively, the field identification information in the field lists of the first type instance and the second type instance is matched based on the preset matching rules to obtain the successfully matched fields, and a field correspondence relationship is established between the successfully matched fields.
[0056] In an optional implementation, if it is detected that the matching results of the field identification information in the field lists corresponding to the first type instance and the second type instance respectively meet the error reporting condition, an error reporting is performed. The error reporting condition is used to characterize the abnormal matching of the field identification information.
[0057] In actual applications, the error reporting condition may be that there is no successfully matched field identification information. If it is detected that there is no successfully matched field identification information in the field lists corresponding to the first type instance and the second type instance, respectively, it can be explained that there is an error in the first type instance or the second type instance, or the mapping relationship between the first type instance and the second type instance is incorrectly set. Therefore, the error reporting condition can remind the user to manually check the error. In addition, the error reporting condition can also be that the proportion of successfully matched field identification information to the total number is less than a threshold, etc., where the threshold can be set based on demand.
[0058] In an optional implementation, a traversal can be performed based on the field list corresponding to the first type instance to find field identification information in the field list corresponding to the second type instance that matches the field identification information in the field list corresponding to the first type instance, thereby establishing a field correspondence relationship between the fields corresponding to the successfully matched field identification information.
[0059] For example, assuming that the field identification information of field A in the field list belonging to the first type instance and the field identification information of field B in the field list belonging to the second type instance successfully match based on the preset matching rules, a field correspondence relationship is established between field A and field B.
[0060] In the disclosed embodiment, the preset matching rule may be a rule for matching based on whether the field names of the fields are consistent, a rule for matching based on the similarity of the field annotation information of the fields, or a rule for matching based on a combination of the field name and the field annotation information.
[0061] In addition, if the field identification information includes the field type, the preset matching rule may also be a matching rule combining the field type, field name and field annotation information.
[0062] In an optional implementation, special matching rules may also be pre-set in the configuration file, such as setting rules for successful matching between fields with specific characteristics based on field assignment requirements, so that by matching the field identification information in the field lists corresponding to the first type instance and the second type instance respectively, the field correspondence that needs to implement field assignment can be fully determined.
[0063] S103: Determine the field assignment relationship corresponding to the field correspondence relationship.
[0064] The field assignment relationship is used to characterize the assignment relationship between the fields in the field correspondence relationship.
[0065] In the embodiment of the present disclosure, after determining the field correspondence, it is determined how to assign values to the fields in the field correspondence. Specifically, by determining a field assignment method for the field correspondence, and then determining the field assignment relationship corresponding to the field correspondence based on the field assignment method, it is used to characterize the assignment relationship between the fields in the field correspondence.
[0066] In an optional implementation, if the field identification information includes the field name, field annotation information and field type, a field assignment method can be determined for the field correspondence based on the field type of the field in the field correspondence. Then, based on the field assignment method, a field assignment relationship corresponding to the field correspondence is generated.
[0067] In practical applications, the field type affects the assignment method between fields. For example, the field correspondence includes integer type fields and string type fields. Assuming that you need to assign a value to a string type field based on the value of the integer type field, you need to determine the field assignment method corresponding to the field correspondence based on the numerical conversion method between the integer type and the string type.
[0068] In an optional implementation, assuming that the field correspondence includes a correspondence between a server field and a client field, before determining the field assignment method corresponding to the field, first determine whether the field types of the client field and the server field are consistent; if the field types of the client field and the server field are consistent, the direct assignment method can be determined as the field assignment method of the field correspondence, indicating that direct assignment can be performed between the client field and the server field.
[0069] If it is determined that the field types of the client field and the server field are inconsistent, an indirect assignment method is determined based on the field types of the client field and the server field, and the indirect assignment method is determined as the field assignment method of the field correspondence relationship, which is used to indicate that the field assignment between the client field and the server field is implemented through a preset algorithm.
[0070] In an optional implementation, an indirect assignment method may be pre-set in a configuration file, for example, a method for assigning values between fields with specific characteristics may be set based on field assignment requirements, so that field assignments can also be implemented between different field types.
[0071] In addition, other special assignment methods can be set in the configuration file to ensure that fields with field correspondence in various first type instances and second type instances can all implement field assignment. For example, for some fields in a heterogeneous structure that require special conversion, the embodiment of the present disclosure can set corresponding special assignment methods for these fields in the configuration file to implement method forwarding, etc.
[0072] In another optional implementation, the fields in the field correspondence may be pre-configured with at least two assignment methods, for example, including a first assignment method and a second assignment method, and the first assignment method has a higher priority than the second assignment method. The disclosed embodiment may determine the first assignment method having a higher priority than the second assignment method as the field assignment method of the field correspondence, and then generate the field assignment relationship of the field correspondence based on the field assignment method.
[0073] For example, the first assignment method is a special assignment method pre-set in the configuration file, and the second assignment method is a direct assignment method based on the default field type. If at least the above two assignment methods are configured for any field correspondence, the special assignment method with a higher priority preset in the configuration file will be determined as the field assignment method for the field correspondence to ensure special field assignment requirements.
[0074] S104: Generate a field assignment code based on the field assignment relationship.
[0075] The field assignment code is used to be deployed on the client of the application to implement field assignment.
[0076] In the disclosed embodiment, for each pair of type instances having a mapping relationship, the field assignment relationships corresponding to the field correspondence relationships contained therein are determined. Then, based on each field assignment relationship, a field assignment code is generated to implement field assignment.
[0077] In an optional implementation, ASM dynamic bytecode technology can be used to generate field assignment codes based on field assignment relationships. The present disclosure does not limit other implementations.
[0078] In actual applications, the method for generating the field assignment code provided by the embodiment of the present disclosure can be completed in the installation package compilation stage of the application. That is, in the process of packaging the application, not only the installation package of the application is generated, but also the method for generating the field assignment code of the embodiment of the present disclosure is executed to generate the field assignment code, and the field assignment code can be added to the installation package of the application.
[0079] In the disclosed embodiment, after the user installs the installation package of the application with the field assignment code, the field assignment code is equivalent to the middle layer of data interaction between the client and the server. It can assign values to the fields corresponding to the specified fields in the client based on the values of the specified fields from the server of the application, and can also assign values to the fields corresponding to the specified fields in the server based on the values of the specified fields in the client.
[0080] In the method for generating field assignment codes provided by the embodiments of the present disclosure, first, a list of fields corresponding to the first type instance and the second type instance having a mapping relationship is obtained, and then, based on a preset matching rule, the field identification information in the list of fields corresponding to the first type instance and the second type instance is matched, and a field correspondence is established between the fields corresponding to the successfully matched field identification information. Secondly, the field assignment relationship corresponding to the field correspondence relationship is determined, and finally, based on the field assignment relationship, a field assignment code is generated for deployment on the client of the application, and the value of the specified field on the server is assigned to the field corresponding to the specified field in the client. The embodiments of the present disclosure automatically realize the generation of field assignment codes, improve the generation efficiency of field assignment codes, and improve the accuracy of field assignment based on the generated field assignment code.
[0081] In an optional implementation, in order to ensure that the generated field assignment code can run normally after being deployed, the embodiment of the present disclosure can adjust the field visibility of the fields involved in the field assignment code so that the field visibility of each field is visible, so that no error will be reported when the field assignment code is running.
[0082] Specifically, in the embodiments of the present disclosure, based on determining the field correspondence relationship, the visibility of the fields in the first type instance and the second type instance may be adjusted so that the fields in the field correspondence relationship are visible.
[0083] In another optional implementation, since there is no parameterless constructor in the type instance involved in the field assignment code, the field assignment code cannot run normally. For this reason, in the embodiment of the present disclosure, before executing the field assignment code, it is first detected whether there is a parameterless constructor in the type instance involved. If not, a parameterless constructor is added to the type instance to ensure the normal operation of the field assignment code. Among them, the parameterless constructor is used to initialize certain variables and is called when the corresponding type instance is loaded. If the parameterless constructor cannot be found during the code running process, the compiler will report an error.
[0084] Specifically, in the embodiment of the present disclosure, it can be detected whether there is a parameterless constructor in the first type instance and the second type instance; if not, a parameterless constructor is added to the first type instance and the second type instance respectively.
[0085] The disclosed embodiment adjusts the field visibility of the fields related to the field assignment code in the source code of the application and adds a parameterless constructor to the related type instance to ensure that the generated field assignment code can run normally after being deployed.
[0086] Based on the same inventive concept as the above method embodiment, the present disclosure also provides a device for generating a field assignment code, referring to Figure 2 , is a schematic diagram of a structure of a device for generating a field assignment code provided in an embodiment of the present disclosure, the device comprising:
[0087] The acquisition module 201 is used to acquire a field list corresponding to a first type instance and a second type instance having a mapping relationship, respectively; wherein the first type instance and the second type instance belong to the server code and the client code of the same application, respectively, and the field list is used to store field identification information of fields in the corresponding type instance, and the field identification information includes field name and / or field annotation information;
[0088] A matching module 202, configured to match the field identification information in the field lists corresponding to the first type instance and the second type instance respectively based on a preset matching rule, and establish a field correspondence relationship between the fields corresponding to the successfully matched field identification information;
[0089] The determination module 203 is used to determine the field assignment relationship corresponding to the field correspondence relationship; wherein the field assignment relationship is used to represent the assignment relationship between the fields in the field correspondence relationship;
[0090] The generation module 204 is used to generate a field assignment code based on the field assignment relationship; wherein the field assignment code is used to be deployed on the client of the application, and based on the value of the specified field from the server of the application, the field corresponding to the specified field in the client is assigned a value.
[0091] In an optional implementation manner, the field identification information further includes a field type, and the determination module includes:
[0092] A first determination submodule, configured to determine a field value assignment method for the field correspondence relationship based on a field type of a field in the field correspondence relationship;
[0093] The first generating submodule is used to generate a field assignment relationship corresponding to the field correspondence relationship based on the field assignment method.
[0094] In an optional implementation manner, the fields in the field correspondence relationship include a server field and a client field, and the first determination submodule includes:
[0095] A second determination submodule is used to determine whether the field types of the server field and the client field in the field correspondence are consistent;
[0096] A third determination submodule is used to determine a direct assignment method as a field assignment method of the field correspondence relationship when the second determination submodule determines that the field types of the server field and the client field are consistent; the direct assignment method is used to indicate direct assignment of a field;
[0097] The fourth determination submodule is used to determine an indirect assignment method based on the field types of the server field and the client field when the second determination submodule determines that the field types of the server field and the client field are inconsistent, and determine the indirect assignment method as the field assignment method of the field correspondence relationship; the indirect assignment method is used to indicate that the field assignment is implemented through a preset algorithm.
[0098] In an optional implementation manner, the fields in the field correspondence are pre-configured with a first assignment method and a second assignment method, and the first assignment method has a higher priority than the second assignment method;
[0099] The determining module comprises:
[0100] a fifth determining submodule, configured to determine the first assignment method having a higher priority than the second assignment method as the field assignment method of the field correspondence;
[0101] The second generating submodule is used to generate the field assignment relationship of the field correspondence relationship based on the field assignment method.
[0102] In an optional implementation, the device further includes:
[0103] An error reporting module is used to perform an error reporting when it is detected that the matching results of the field identification information in the field lists corresponding to the first type instance and the second type instance respectively meet the error reporting conditions; the error reporting conditions are used to characterize the abnormal matching of the field identification information.
[0104] In an optional implementation, the device further includes:
[0105] A visibility adjustment module is used to adjust the field visibility in the first type instance and the second type instance based on the field correspondence.
[0106] In an optional implementation, the device further includes:
[0107] A detection module, used for detecting whether there is a no-parameter constructor in the first type instance and the second type instance;
[0108] An adding module is used to add a no-parameter constructor to the first type instance and the second type instance respectively when the detection module detects that there is no no-parameter constructor in the first type instance and the second type instance.
[0109] In the device for generating field assignment codes provided by the embodiments of the present disclosure, first, a list of fields corresponding to the first type instance and the second type instance having a mapping relationship is obtained, and then, based on a preset matching rule, the field identification information in the list of fields corresponding to the first type instance and the second type instance is matched, and a field correspondence is established between the fields corresponding to the successfully matched field identification information. Secondly, the field assignment relationship corresponding to the field correspondence relationship is determined, and finally, based on the field assignment relationship, a field assignment code is generated for deployment on the client of the application, and the value of the specified field on the server is assigned to the field corresponding to the specified field in the client. The embodiments of the present disclosure automatically realize the generation of field assignment codes, improve the generation efficiency of field assignment codes, and improve the accuracy of field assignment based on the generated field assignment code.
[0110] In addition, the disclosed embodiment adjusts the field visibility of fields related to the field assignment code in the source code of the application and adds a parameterless constructor to the related type instance to ensure that the generated field assignment code can run normally after being deployed.
[0111] In addition to the above-mentioned method and apparatus, the embodiments of the present disclosure also provide a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device implements the method for generating a field assignment code described in the embodiments of the present disclosure.
[0112] In addition, the present disclosure also provides a device for generating a field assignment code, see Figure 3 As shown, it may include:
[0113] Processor 301, memory 302, input device 303 and output device 304. The number of processors 301 in the field assignment code generation device can be one or more. Figure 3 In some embodiments of the present disclosure, the processor 301, the memory 302, the input device 303 and the output device 304 may be connected via a bus or other means, wherein: Figure 3 The example of connecting through bus is taken in the following.
[0114] The memory 302 can be used to store software programs and modules. The processor 301 executes various functional applications and data processing of the field assignment code generation device by running the software programs and modules stored in the memory 302. The memory 302 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc. In addition, the memory 302 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. The input device 303 can be used to receive input digital or character information, and generate signal input related to user settings and function control of the field assignment code generation device.
[0115] Specifically in this embodiment, the processor 301 will load the executable files corresponding to the processes of one or more applications into the memory 302 according to the following instructions, and the processor 301 will run the applications stored in the memory 302, thereby realizing the various functions of the above-mentioned field assignment code generation device.
[0116] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0117] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for generating a field assignment code, characterized in that: The method comprises: Obtain a field list corresponding to a first type instance and a second type instance having a mapping relationship, respectively; wherein the first type instance and the second type instance belong to a server code and a client code of the same application, respectively, and the field list is used to store field identification information of fields in the corresponding type instance, and the field identification information includes a field name and / or field annotation information; Based on a preset matching rule, the field identification information in the field lists corresponding to the first type instance and the second type instance are matched, and a field correspondence relationship is established between the fields corresponding to the successfully matched field identification information; Determine a field assignment relationship corresponding to the field correspondence relationship; wherein the field assignment relationship is used to characterize the assignment relationship between fields in the field correspondence relationship; Based on the field assignment relationship, a field assignment code is generated; wherein the field assignment code is used to be deployed on the client of the application, and based on the value of the specified field from the server of the application, a field in the client corresponding to the specified field is assigned a value.
2. The method according to claim 1, characterized in that The field identification information also includes a field type, and the determining of a field value assignment relationship corresponding to the field correspondence relationship includes: Determining a field value assignment method for the field correspondence based on the field type of the field in the field correspondence; Based on the field assignment method, a field assignment relationship corresponding to the field correspondence relationship is generated.
3. The method according to claim 2, characterized in that The fields in the field correspondence relationship include server fields and client fields, and the field assignment method for the field correspondence relationship is determined based on the field types of the fields in the field correspondence relationship, including: Determine whether the field types of the server field and the client field in the field correspondence are consistent; If it is determined that the field types of the server-side field and the client-side field are consistent, a direct assignment method is determined as the field assignment method of the field correspondence relationship; the direct assignment method is used to indicate direct assignment of a field; If it is determined that the field types of the server field and the client field are inconsistent, an indirect assignment method is determined based on the field types of the server field and the client field, and the indirect assignment method is determined as the field assignment method of the field correspondence relationship; the indirect assignment method is used to indicate that the field assignment is implemented through a preset algorithm.
4. The method according to claim 1, characterized in that: The fields in the field correspondence are pre-configured with a first assignment method and a second assignment method, and the first assignment method has a higher priority than the second assignment method; The determining of the field value assignment relationship corresponding to the field correspondence relationship includes: Determine the first assignment method having a higher priority than the second assignment method as the field assignment method of the field correspondence relationship; Based on the field assignment method, a field assignment relationship of the field correspondence relationship is generated.
5. The method according to claim 1, characterized in that After matching the field identification information in the field lists corresponding to the first type instance and the second type instance respectively based on the preset matching rule, the method further includes: If it is detected that the matching results of the field identification information in the field lists corresponding to the first type instance and the second type instance respectively meet the error reporting condition, an error reporting is performed; the error reporting condition is used to characterize the abnormal matching situation of the field identification information.
6. The method according to claim 1, characterized in that After generating the field assignment code based on the field assignment relationship corresponding to the field correspondence relationship, the method further includes: Based on the field correspondence, field visibility in the first type instance and the second type instance is adjusted.
7. The method according to claim 1, characterized in that After generating the field assignment code based on the field assignment relationship corresponding to the field correspondence relationship, the method further includes: Detect whether there is a no-argument constructor in the first type instance and the second type instance; If it does not exist, a no-parameter constructor is added to the first type instance and the second type instance respectively.
8. A device for generating a field assignment code, characterized in that: The device comprises: an acquisition module, used to acquire a field list corresponding to a first type instance and a second type instance having a mapping relationship, respectively; wherein the first type instance and the second type instance belong to a server code and a client code of the same application, respectively, and the field list is used to store field identification information of fields in the corresponding type instance, wherein the field identification information includes a field name and / or field annotation information; A matching module, configured to match the field identification information in the field lists corresponding to the first type instance and the second type instance respectively based on a preset matching rule, and establish a field correspondence relationship between the fields corresponding to the field identification information that successfully matches; A determination module, used to determine a field assignment relationship corresponding to the field correspondence relationship; wherein the field assignment relationship is used to characterize the assignment relationship between the fields in the field correspondence relationship; A generation module is used to generate a field assignment code based on the field assignment relationship; wherein the field assignment code is used to be deployed on the client of the application, and based on the value of the specified field from the server of the application, the field corresponding to the specified field in the client is assigned a value.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device implements the method according to any one of claims 1 to 7.
10. A device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Method and apparatus for automatic analysis of communication data between server and client
CN105141630A
Code generation method and apparatus
CN108509201A
