CN113760360A - File generation method, device, equipment and storage medium - Google Patents

File generation method, device, equipment and storage medium Download PDF

Info

Publication number
CN113760360A
CN113760360A CN202110335326.XA CN202110335326A CN113760360A CN 113760360 A CN113760360 A CN 113760360A CN 202110335326 A CN202110335326 A CN 202110335326A CN 113760360 A CN113760360 A CN 113760360A
Authority
CN
China
Prior art keywords
field
annotation
read
entity class
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110335326.XA
Other languages
Chinese (zh)
Inventor
万江
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Tuoxian Technology Co Ltd
Original Assignee
Beijing Jingdong Tuoxian Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Tuoxian Technology Co Ltd filed Critical Beijing Jingdong Tuoxian Technology Co Ltd
Priority to CN202110335326.XA priority Critical patent/CN113760360A/en
Publication of CN113760360A publication Critical patent/CN113760360A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Library & Information Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the application discloses a file generation method, a device, equipment and a storage medium, wherein the file generation method comprises the following steps: acquiring a code to be operated; responding to a received running instruction for indicating to run the code to be run, and determining a field to be read required by running the code to be run based on the code to be run; determining annotation information matched with the field to be read from an annotation library; and generating a target file representing the corresponding relation between the field to be read and the description information based on the annotation information.

Description

File generation method, device, equipment and storage medium
Technical Field
The present application relates to the field of information technologies, and in particular, to a file generation method, apparatus, device, and storage medium.
Background
In order to facilitate code debugging, research and development personnel writing codes need to make necessary description on relevant fields in the written codes; in the related art, a form is usually constructed manually by a developer, and description information corresponding to related codes is filled in the form in sequence, so that the construction process of a description file corresponding to a related field is excessively dependent on the developer, and meanwhile, a large amount of time is usually spent for manual filling, so that the generation efficiency of the related description file is low.
Disclosure of Invention
In order to solve the foregoing technical problems, embodiments of the present application desirably provide a file generation method, apparatus, device, and storage medium, which can directly generate a target file representing a correspondence between a field to be acquired and description information based on annotation information matched with the field to be acquired, so as to reduce dependence of generation of a related description file on developers, and improve generation efficiency of the related description file.
In order to achieve the purpose, the technical scheme of the application is realized as follows:
the embodiment of the application provides a file generation method, which comprises the following steps:
acquiring a code to be operated;
responding to a received running instruction for indicating to run the code to be run, and determining a field to be read required by running the code to be run based on the code to be run;
determining annotation information matched with the field to be read from an annotation library;
and generating a target file representing the corresponding relation between the field to be read and the description information based on the annotation information.
An embodiment of the present application further provides a file generating apparatus, where the file generating apparatus includes: the device comprises an acquisition module, a determination module and a generation module, wherein:
the acquisition module is used for acquiring a code to be operated;
the determining module is used for responding to a received running instruction for indicating to run the code to be run, and determining a field to be read required by running the code to be run based on the code to be run;
the determining module is further used for determining annotation information matched with the field to be read from an annotation library;
and the generating module is used for generating a target file representing the corresponding relation between the field to be read and the description information based on the annotation information.
An embodiment of the present application further provides a file generating device, where the file generating device includes: a processor, a memory, and a communication bus;
the communication bus is used for realizing communication connection between the processor and the memory;
the processor is configured to execute the program in the memory to implement any of the file generation methods described above.
Correspondingly, the present application further provides a computer-readable storage medium, where one or more programs are stored, and the one or more programs are executable by one or more processors to implement the steps of any of the above-described file generation methods.
The embodiment of the application discloses a file generation method, a file generation device, equipment and a storage medium, and firstly, a code to be run is obtained; responding to a received running instruction for indicating running of the code to be run, and determining a field to be read required by running the code to be run based on the code to be run; secondly, determining annotation information matched with the field to be read from an annotation library; generating a target file representing the corresponding relation between the field to be read and the description information based on the annotation information; therefore, the target file representing the corresponding relation between the field to be acquired and the description information can be directly generated based on the annotation information matched with the field to be acquired, the dependence of generation of the related description file on developers can be reduced, and meanwhile, the generation efficiency of the related description file can be improved.
Drawings
Fig. 1 is a schematic flowchart of a file generation method according to an embodiment of the present application;
fig. 2 is a schematic flowchart of another file generation method according to an embodiment of the present application;
fig. 3 is a schematic flowchart of another file generation method according to an embodiment of the present application;
fig. 4 is a flowchart of generating a target file applied in JAVA according to an embodiment of the present application;
fig. 5 is a schematic diagram of a target file stored in an Excel format according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a file generation apparatus according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a file generation device according to an embodiment of the present application.
Detailed Description
So that the manner in which the above recited features and advantages of the present embodiments can be understood in detail, a more particular description of the embodiments of the invention, briefly summarized above, may be had by reference to the appended drawings, which are included to provide a more thorough understanding of the embodiments of the invention.
It should be appreciated that reference throughout this specification to "an embodiment of the present application" or "an embodiment described previously" means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Thus, the appearances of the phrases "in the embodiments of the present application" or "in the embodiments" in various places throughout this specification are not necessarily all referring to the same embodiments. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the embodiments of the present application, the sequence numbers of the above-mentioned processes do not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application. The above-mentioned serial numbers of the embodiments of the present application are merely for description and do not represent the merits of the embodiments.
An embodiment of the present application provides a file generation method, which is applied to a file generation device, and as shown in fig. 1, the method includes the following steps:
step 101, obtaining a code to be run.
In the embodiment of the present application, the file generation device may be any electronic device having a data processing capability.
It should be noted that the source file written by the code in the language supported by the developer using the development tool may be a set of definite rule system in which the information is represented in a discrete form by characters, symbols or signal code elements; in the embodiment of the present application, a specific presentation form and specific content of the code to be executed are not limited at all.
In the embodiment of the application, the to-be-run in the to-be-run code refers to that the code needs to be tested or run at a specified time or based on a specified instruction.
Correspondingly, the code to be run can be obtained by analyzing the relevant information by the file generation equipment; the code to be executed may also be written into the file generation device in response to a write instruction, and the present application does not limit the specific source for obtaining the code to be executed.
It should be noted that the code to be executed in the embodiment of the present application may be written based on any one of object-oriented programming languages such as C + +, C, JAVA, and Python, that is, the specific writing language for writing the code to be executed is not limited in the present application.
In the following embodiments of the present application, codes to be executed refer to codes in a JAVA execution environment.
Step 102, in response to a received operation instruction indicating to operate a code to be operated, determining a field to be read required for operating the code to be operated based on the code to be operated.
In the embodiment of the application, the file generation device responds to a received operation instruction which indicates that a code to be operated is operated, so as to determine a field to be read, which is required by the code to be operated in the operation process, based on the operation instruction and the code to be operated.
It should be noted that the field to be read may be a feature of a certain thing, or an attribute of the thing; in other embodiments below in the present application, the fields to be read all refer to field attributes in one entity class, where the entity class is an entity object.
In one possible implementation, the fields may be the height, weight, gender, etc. of the person.
In another possible implementation, the field may be a start time, an end time, etc. of the task.
The field to be read can have corresponding information such as a field name, a field type, field description and the like; accordingly, the field name, the field type, and the specific presentation manner corresponding to the field description are not limited in any way in this application.
In the embodiment of the present application, the number of the fields to be read is not limited in any way in the present application, in other words, the number of the fields to be read required for running the code to be run may be one, two or more.
And 103, determining annotation information matched with the field to be read from the annotation library.
In the embodiment of the application, the file generation device determines annotation information matched with the field to be read from the annotation library.
Wherein, the annotation library can be a code library generated by a JAVA-based annotation mechanism; correspondingly, the annotation library at least comprises annotation information matched with the field to be read; in other words, the annotation library at least includes annotation information corresponding to the entity class to which the field to be read belongs.
It should be noted that, the annotation mechanism of JAVA is used to describe the code, and can annotate the packet, class, interface, field, method parameter, local variable, and the like; among them, the annotation mechanism mainly functions as follows: 1. generating a document, and generating a javadoc document through metadata identified in the code; 2. compiling check, which enables a compiler to check and verify during compiling through metadata identified in the code; 3. dynamic processing during compiling, wherein the dynamic processing is carried out through metadata identified in the code during compiling, for example, the code is dynamically generated; 4. run-time dynamic processing, which is dynamically processed by metadata identified in the code at run-time, for example using reflection injection instances.
General annotations can be divided into three categories: 1. is a standard annotation carried by JAVA itself, comprising: @ Override, @ deleted and @ suppressWarnngs, respectively, for indicating that a method is overwritten, that a class or method is outdated, and that an alarm is to be ignored, with these annotations indicating that the compiler will check; 2. meta-annotation, which is an annotation used to define an annotation, including @ Retention, @ Target, @ Inherited, and @ Documented; the system comprises a reader, a client, an annotation server, a client and a client, wherein @ Retention is used for marking the stage of reserving the annotation, @ Target is used for marking the range of the annotation, @ Inhereted is used for marking the inheritance of the annotation, and @ Docummented is used for marking whether to generate a javadoc document; 3. the self-defined annotation can be defined according to the requirement of the user, and can be annotated by the meta-annotation; in the embodiment of the present application, the annotation information may be a custom annotation, that is, a developer or a user may customize the description information and the like corresponding to the required field to be read to form corresponding annotation information.
In the embodiment of the present application, the annotation information matched with the field to be read may include, but is not limited to, a field name, a field type, a field description, and an additional custom comment of the field to be read, which is not limited in this application.
And 104, generating a target file representing the corresponding relation between the field to be read and the description information based on the annotation information.
In the embodiment of the application, the file generation device can directly generate a target file representing the corresponding relation between the field to be read and the description information based on the annotation information; in other words, the annotation information matched with the field to be read includes the field to be read and the description information corresponding to the field to be read by default.
It should be noted that the fields to be read in the target file are stored in one-to-one correspondence with the corresponding description information; the description information may be comment information customized by the developer for the field to be read.
In a feasible implementation manner, in the process of running the code to be run, the file generation device calls annotation information in an annotation library where a field to be read, which is needed by the code to be run, is located, obtains description information corresponding to the field to be read from the annotation information on the basis of a JAVA reflection mechanism, and then forms a target file on the basis of the field to be read and the description information.
Wherein, the JAVA reflection mechanism is in a running state, and all attributes and methods of any class can be known; any method of any object can be called; the function of this dynamically acquired and dynamically invoked method of objects is called the reflection mechanism of the JAVA language; the JAVA reflection mechanism mainly provides the following functions: determining a class to which any one of the objects belongs at runtime; constructing an object of any one class at runtime; determining the member variable and method of any class at runtime; calling a method of any one object at runtime; a dynamic proxy is generated.
In the embodiment of the present application, the description information corresponds to the fields to be read one by one, and each field to be read may have one description information or two or more description information.
The target file may be presented in any form such as a table, a document, a graph, and the like, which is not limited in this application.
In the embodiment of the application, the corresponding relation between the field to be read and the description information means that the field to be read and the description information are represented to have a correlation relation; when the field to be read is at least two fields to be read, each field to be read has its corresponding description information, and the number and content of the corresponding description information are not limited in this application.
It should be noted that, in the embodiment of the present application, on the premise that the annotation information matched with the field to be read and the code to be run where the annotation information is located run, the target file having the corresponding relationship between the field to be read and the description information thereof can be directly obtained, so that, for example, in the related art, it is avoided that research and development personnel need to sequentially input the field to be read and the description information corresponding thereto into a constructed form one by one, and thus, the generation efficiency of the target file can be improved, and a phenomenon that the research and development personnel may make a filling error in manual input is effectively avoided.
The file generation method provided by the embodiment of the application comprises the steps of firstly, acquiring a code to be operated; responding to a received running instruction for indicating running of the code to be run, and determining a field to be read required by running the code to be run based on the code to be run; secondly, determining annotation information matched with the field to be read from an annotation library; generating a target file representing the corresponding relation between the field to be read and the description information based on the annotation information; therefore, the target file representing the corresponding relation between the field to be acquired and the description information can be directly generated based on the annotation information matched with the field to be acquired, the dependence of generation of the related description file on developers can be reduced, and meanwhile, the generation efficiency of the related description file can be improved.
Based on the foregoing embodiments, the embodiments of the present application further provide a file generating method, which is applied to a file generating device, and the following description is made with reference to the steps shown in fig. 1 and fig. 2:
step 201, determining an entity class to which a field to be read belongs.
In the embodiment of the application, the file generation device determines the entity class to which the field to be read belongs.
It should be noted that the entity class may be an entity object.
In a feasible implementation manner, when the entity class is the user, the fields to be read are the age, height, name, gender, and the like of the user.
In another possible implementation manner, when the field to be acquired can execute the task, the field to be read is the start time and the end time of the executable task, and the like.
In the embodiment of the application, the number of the corresponding fields to be read in one entity class is not limited at all; when there are two or more fields to be read in one entity class, there is a mapping relationship between the two or more fields to be read, and the specific definition of the mapping relationship is not limited in this application.
Step 202, determine the annotation information corresponding to the entity class from the annotation library.
In the embodiment of the application, the file generation device directly determines annotation information corresponding to the entity class from an annotation library.
Note that, in JAVA, the annotation information generated based on the annotation mechanism is generally formed in units of entity classes, where each entity class may include multiple fields; correspondingly, the annotation information corresponding to each entity class may further include, on the basis of the description information of the field to be read, the description information of the field related to the field to be read, and the like.
It should be noted that, the entity class to which the field to be read belongs is further determined, and the annotation information corresponding to the entity class is determined, so that the accuracy of determining the matched annotation information can be improved.
Accordingly, before the file generation device performs step 202, that is, before the file generation device determines the annotation information corresponding to the entity class from the annotation library, the following steps a1 and a2 may also be performed:
and A1, acquiring the description information of the entity class.
In the embodiment of the application, the file generation equipment acquires the description information of the entity class; the description information may be comment information for each field to be read in the entity class, that is, custom comment information for the field to be read by a developer.
In one possible implementation, the description information of the entity class may be: the field name is name, and the corresponding annotation information is name; the field name is age, and the corresponding comment information is age; the field name is height, and the corresponding annotation information is height.
The description information of the entity class, that is, the description information of each field to be read in the entity class, may be in any form of text, code, and the like, and this application does not limit this.
Accordingly, the description information may be presented in the form of tables, documents, figures, and the like, which is not limited in any way in this application.
Step a2, in response to the received write command indicating to write the description information, generating annotation information matching the entity class in the annotation library based on the description information and the initial annotation information corresponding to the entity class.
In the embodiment of the application, the file generation device responds to a received write instruction which indicates that the description information is written, and generates annotation information matched with the class in the annotation library based on the description information and initial annotation information corresponding to the entity class.
The writing instruction may be manually input by a developer, or may be a writing instruction or the like sent by an electronic device capable of performing information interaction with the electronic device, which is acquired by a file generation device, and the application is not limited in any way.
It should be noted that the initial annotation information corresponding to the entity class may include only the field name and the field type information of each field of the entity class; accordingly, annotation information that matches a class may be obtained by correspondingly populating description information based on the initial annotation information corresponding to the entity class.
It should be noted that, a developer may directly write description information, i.e., custom annotation information, corresponding to a field required in a code into annotation information during a code compiling process, and directly obtain a description file representing a corresponding relationship between the field to be read and the description information at a later stage based on the code running and the annotation information, so that description information corresponding to the field is given during an earlier code compiling process, and a phenomenon that errors may occur in the description information of the field edited at the later stage can be effectively avoided.
Accordingly, in step 104, that is, the file generating device generates the target file representing the corresponding relationship between the field to be read and the description information based on the annotation information, the file generating device may further perform steps 203 and 204:
step 203, determining the description information corresponding to the field to be read based on the annotation information.
In the embodiment of the application, the file generation device may determine the description information corresponding to the field to be read based on the generated annotation information.
In a feasible implementation manner, in the process of running a code to be run, a file generation device calls annotation information which is matched with a field to be read and is required in the file generation device in an annotation library, and determines description information corresponding to the field to be read based on the annotation information; when the number of the fields to be read is two or more, the description information corresponding to each field to be read can be acquired in sequence.
And step 204, packaging the field to be read and the description information to generate a target file.
In the embodiment of the application, the file generation device correspondingly packages and exports the required target file one by one based on the field to be read and the acquired corresponding description information.
In the embodiment of the application, the field to be read and the description information are encapsulated, that is, the field to be read and the description information are paired one by one according to the corresponding relationship between the field to be read and the description information and are stored to generate the target file.
It should be noted that, in the embodiment of the present application, the file generation device encapsulates the field to be read and the description information to obtain the target file, so that the field to be read and the description information in the target file can be presented to the user in a one-to-one correspondence manner, so that the code user can intuitively and efficiently know the description information of the relevant field, and further, the later code user can understand, use and iterate the class in the code.
The file generation method provided by the embodiment of the application can directly generate the target file representing the corresponding relation between the field to be acquired and the description information based on the operation of the annotation information and the code to be operated, which correspond to the entity class to which the field to be acquired belongs, so that the dependence of the generation of the related description file on developers can be reduced, and meanwhile, the generation efficiency of the related description file can be improved.
Based on the foregoing embodiments, the embodiments of the present application further provide a file generating method, which is applied to a file generating device, and the following description is made with reference to the steps shown in fig. 1 to fig. 3:
when the field to be read is at least two fields to be acquired, the file generation device determines the annotation information matched with the field to be read from the annotation library when executing step 103, that is, the file generation device correspondingly executes the following step 301:
step 301, determining annotation information matched with each field to be acquired from an annotation library.
In the embodiment of the application, the file generation device determines the annotation information matched with each field to be acquired from the annotation library.
In a feasible implementation manner, the file generation device needs to acquire the entity class to which the field to be acquired belongs first, and determines the annotation information matched with the field to be acquired based on the annotation information corresponding to the entity class in the annotation library,
in another possible implementation manner, the file generation device may directly acquire the annotation information matching the field to be acquired based on a pre-stored mapping table having a corresponding relationship between the field to be acquired and the annotation information.
It should be noted that the entity classes to which the at least two fields to be acquired belong may be the same entity class or different entity classes, which is not limited in this application.
Correspondingly, when the file generation device generates the target file representing the corresponding relationship between the field to be read and the description information based on the annotation information, the file generation device can be implemented by the following two ways, namely step 302 and step 303:
step 302, under the condition that the entity classes to which the at least two fields to be acquired belong are the same entity class, generating a target file based on the annotation information matched with the at least two fields to be acquired.
In the embodiment of the application, the file generation device generates a target file based on annotation information matched with at least two fields to be acquired under the condition that the entity classes to which the at least two fields to be acquired belong are the same entity class; namely, the file generation device generates the target file based on the annotation information matched with any field to be acquired.
In a feasible implementation manner, when the entity class to which the at least two fields to be acquired belong is the same entity class, the at least two fields to be acquired may correspond to a user name, a user height, a user age, and the like when the entity class is a user.
It should be noted that the number of the target file may be the same as or different from the number of the entity classes, and in other embodiments below in the present application, the number of the target file is the same as the number of the entity classes, that is, the target file is generated in units of entity classes, where a field to be acquired in the target file may appear in a byte stream or in a byte symbol, which is not limited in this application.
In the target file with the entity class as a unit, each field to be acquired and the description information corresponding to the field to be acquired may be stored in sequence or may be stored according to a preset rule, which is not limited in this application.
Step 303, under the condition that the entity classes to which the at least two fields to be acquired belong are different, generating target files with the same number of files as the number of the entity classes based on the annotation information matched between each entity class and the fields to be acquired belonging to the entity classes.
In the embodiment of the application, the file generation device generates target files with the same number of files as the number of the entity classes based on annotation information matched with each entity class and the fields to be acquired belonging to the entity classes under the condition that the entity classes to which at least two fields to be acquired belong are different entity classes; wherein, each entity class is the entity class to which at least two fields to be acquired belong.
In a feasible implementation manner, when the entity classes to which the at least two fields to be acquired belong are different, the file generation device may first determine a first entity class to which the fields to be acquired belong belonging to the same entity class, and then determine the relevant target file based on the annotation information corresponding to the first entity class and the second entity class; and the field to be acquired of the second entity class only has one field in the at least two fields to be acquired correspondingly.
In a feasible implementation manner, when the entity classes to which the at least two fields to be acquired belong are different entity classes, and the entity classes can be users and tasks, the at least two fields to be acquired correspond to user names, user heights, user ages, task starting times, task duration and the like.
It should be noted that the number of the target file may be the same as the number of the entity classes, and the field to be acquired in the target file may appear in a byte stream or in a byte character, which is not limited in this application.
In each target file using the entity class as a unit, each field to be acquired and the description information corresponding to the field to be acquired may be stored in sequence or may be stored according to a preset rule, which is not limited in this application.
In the embodiment of the application, when a plurality of fields to be acquired are acquired, the entity class to which the fields to be acquired belong needs to be determined specifically, so that the process of acquiring annotation information of each field to be acquired from an annotation library for multiple times is saved, and the efficiency of generating a target file can be improved; meanwhile, the number of the corresponding target files is determined based on the number of the entity classes, so that the problem of confusion when a plurality of target files are generated can be effectively avoided.
Accordingly, after performing step 303, the file generation apparatus may further perform the following steps 304 and 305:
and 304, determining a storage interval corresponding to each entity class in a preset file area to be written.
In the embodiment of the application, the file generation device is preset with a preset file area to be written, and a storage interval corresponding to each entity class is determined in the preset file area to be written.
In a feasible implementation manner, the file generation device may determine, based on attribute information of the entity class, such as a name, a storage interval corresponding to each entity class in a preset to-be-written file area.
In another possible implementation manner, the file generation device may determine, based on the export time of the entity classes, a storage interval corresponding to each entity class in a preset to-be-written file area.
Based on the above, in the embodiment of the present application, the file generation device determines, according to what information is in the preset to-be-written file area, that the storage interval corresponding to each entity class is not limited at all.
In a feasible implementation manner, the entity classes are User, BaseDto and DoctorDto, and the file generation device sequentially divides the corresponding sections in the preset file area to be written based on the User, the BaseDto and the DoctorDto.
Step 305, storing the target file corresponding to each entity class in the storage interval corresponding to each entity class.
In the embodiment of the application, the file generation device stores the target file corresponding to each entity class in the storage interval corresponding to each entity class.
It should be noted that, in the embodiment of the present application, when the file generation device generates based on multiple target files, a storage interval corresponding to each target file may be set in advance, so that a phenomenon of management confusion when multiple target files are exported or generated may be effectively avoided.
Based on this, the file generation device may further perform the following steps B1 and B2 when the fields to be read are at least two fields to be acquired:
and step B1, generating a preset table matched with the at least two fields to be acquired.
In the embodiment of the application, the file generation device may directly generate a preset table matched with at least two fields to be acquired first based on the fields to be acquired; the specific form of the table is not limited in this application.
The number of rows or columns in the preset table may be matched with the number of at least two fields to be acquired one by one.
And step B2, sequentially storing the fields to be acquired of each entity class and the corresponding description information in a preset table to obtain the target file corresponding to each entity class.
In the embodiment of the application, the file generation device stores the fields to be acquired and the corresponding description information one by one in a preset table on the basis of the derived fields to be acquired and the corresponding description information of each entity class, so as to obtain the target file corresponding to each entity class.
It should be noted that, this can effectively avoid the phenomenon of information management confusion in deriving and storing the fields to be acquired and the corresponding description information of each entity class.
According to the file generation method provided by the embodiment of the application, the target file representing the corresponding relation between the field to be acquired and the description information can be directly generated based on the operation of the annotation information and the code to be operated, which correspond to the entity class to which the field to be acquired belongs, so that the dependence of the generation of the related description file on developers can be reduced, and meanwhile, the generation efficiency of the related description file can be improved; meanwhile, based on the predetermined storage interval and the preset table, the generated target file and the phenomenon of disordered information management in the target file can be effectively avoided.
Based on the file generation method provided in the above embodiment, before the file generation device executes step 101, that is, before the file generation device acquires the code to be executed, the following steps C1 to C3 may also be executed:
and step C1, acquiring a preset entity class set comprising a plurality of entity classes.
In the embodiment of the application, the file generation device may directly obtain a preset entity class set including a plurality of entity classes; the plurality of entity classes corresponding to the preset entity class set may or may not be associated with the code to be run, and this application does not limit this.
In a feasible implementation manner, the file generation device obtains all entity class information in the main program code corresponding to the code to be run, and takes the entity class as a preset entity class set.
The preset entity class set may be presented in any form of document, table, graph, code, and the like, which is not limited in this application.
And step C2, determining the initial annotation information of each preset entity class.
In the embodiment of the application, the file generation equipment determines the initial annotation information of each preset entity class; the initial annotation information may be framework information with an entity class as main information; the initial code formed based on the name information of the annotation mechanism and the entity class may be used, and the specific reference of the initial annotation information is not limited in any way in the present application.
In a possible implementation manner, the file generation device may determine the initial annotation information of each preset entity class based on the attribute information of each preset entity class in the preset entity class set.
In another possible implementation manner, the file generation device may determine the initial annotation information of each preset entity class based on the name, the generation time, and the like of each preset entity class in the preset entity class set.
And step C3, editing the initial annotation information according to an annotation mechanism mode for each preset entity class to form the annotation information of each preset entity class so as to establish an annotation library.
In the embodiment of the application, for each preset entity class, the file generation device may edit or compile the initial annotation information corresponding to the preset entity class in an annotation mechanism manner to form annotation information of each preset entity class; and establishing an annotation library based on the annotation information of each preset entity class.
Accordingly, in the embodiment of the present application, the annotation library has annotation information corresponding to each preset entity class, and each preset entity class includes at least one field and description information corresponding to the field.
It should be noted that, in the embodiment of the present application, the file generation device may customize description information, i.e., annotation information, of a relevant field in the code in advance based on an annotation mechanism in a code compiling process, then directly derive the relevant field and description information corresponding to the relevant field by using a running process and the annotation information of the code, i.e., using a JAVA reflection mechanism, and further convert the derived information into a target file, which can avoid that, as in the related art, a developer needs to re-establish a relevant form after the code is compiled, search each field and description information corresponding to the field in the compiled code, and then sequentially fill the relevant field and description information corresponding to the field in the form, so that dependence of generation of the relevant description file on the developer can be reduced, and meanwhile, generation efficiency of the relevant description file can be improved.
Based on this, as shown in fig. 4, a flowchart of generating a target file applied in JAVA is provided in the embodiment of the present application; the method includes that 401 is to obtain an entity class to be read or a field of the entity class, that is, a field to be read, which is required for running a code to be run, is determined based on the code to be run, corresponding to a running instruction for running the code to be run in response to a received instruction in the embodiment of the present application; secondly, acquiring annotation information (402) of the entity class based on a reflection mechanism in the JAVA running code, and acquiring the annotation information of the entity class by the reflection mechanism; then, judging whether the entity class corresponding to the annotation information has custom description information based on 403, if so, generating a target file, namely exporting Excel, based on the description information and the entity class directly, and corresponding 405; or under the condition that the entity class does not have the custom description information, further executing 404 judgment, namely judging whether the field of the entity class has the custom description information, and under the condition that the field of the entity class has the custom description information, generating a target file, namely exporting Excel, according to 405, directly based on the description information and the field of the entity class; in addition, when the annotation information does not have any description information, that is, when no custom description information can be derived, the entity class or field to be read can be obtained again.
It should be noted that the description information related in fig. 4 is the customized comment information for the field of the entity class; the derived Excel can be derived through two paths: firstly, a server exports, determines an entity class needing to be exported and a corresponding field, determines a storage path of an exported file, and invokes an export function method to automatically generate an Excel file corresponding to the class; and secondly, exporting by the browser, and generating the file only by determining an entity type path needing to be exported.
Meanwhile, as shown in fig. 5, a schematic diagram of a target file stored in an Excel form is provided in the embodiment of the present application; wherein 501 is a field name column, a field type column, a field description column, a transmission necessity column and a remark column corresponding to each field in the User; the field description column, whether the column is necessary to be transmitted or not and the information corresponding to the remark column are the description information corresponding to the field related in the embodiment of the application; 502 are three entity classes, namely User, BaseDto, and DoctorDto.
It should be noted that fig. 5 shows an Excel file obtained by using a JAVA-based annotation mechanism and a reflection mechanism, where if a developer has a custom description for a field in an entity class Users as a name, a field description column corresponding to the name in a generated Excel table has corresponding custom information, and if the field description column information in the Excel is not null; the self-defined information, namely the description information, can be set according to requirements, and only the corresponding attribute information needs to be analyzed when the annotation information is acquired; meanwhile, based on the annotation information generated by the annotation mechanism, the corresponding custom information is only required to be added to the field for exporting the additional custom information when in use; the field without deriving extra information can be without adding the self-defining information, namely the description information; and the export tool defaults to the basic information needed to export the fields, i.e., the field names and the field types.
Meanwhile, when target files corresponding to a plurality of entity classes are exported, in order to prevent repeated analysis and export work, a set corresponding to the entity classes to be generated can be created in advance; meanwhile, in the process of generating a target file, namely Excel, namely in the process of iterating object field information, whether the description information of the field and the attribute information corresponding to the description information need to be exported or not can be verified through annotation; if the current field is not customized, only basic information of the field itself, such as field name and field type, needs to be derived.
It should be noted that, if the current field is the self-defined description information and the special field in the annotation is true, it represents that the type of the field is the field type of the self-defined description information, and the entity type information corresponding to the type needs to be derived; the next operation can be carried out in a recursive manner; the field types of the cyclic references, and when using custom annotations, can also be defaulted in special fields to avoid recursive endless exportation.
In addition, the file generation device can generate a required Excel file in a byte stream or character stream mode; analyzing all field information needing to be exported in an entity class and a subclass in the entity class in a recursive mode in the process of generating the Excel file; wherein the child class contains its parent class attribute information.
Therefore, the file generation device freely sets some description information which can be acquired in the field in a comment mode, further can acquire the description information in the freely set field in a reflection mode, and can export and generate the Excel file in a byte stream or character stream mode, so that a later code user can understand, use and iterate classes in the code.
Based on the foregoing embodiments, an embodiment of the present application further provides a file generating apparatus 6, where the file generating apparatus 6 may be applied to a file generating method provided in the embodiments corresponding to fig. 1 to 3, and as shown in fig. 6, the file generating apparatus 6 may include: an obtaining module 61, a determining module 62 and a generating module 63, wherein:
an obtaining module 61, configured to obtain a code to be run;
the determining module 62 is configured to determine, in response to a received operation instruction indicating that a code to be executed is to be executed, a field to be read, which is required for executing the code to be executed, based on the code to be executed;
the determining module 62 is further configured to determine annotation information matched with the field to be read from the annotation library;
and the generating module 63 is configured to generate a target file representing a corresponding relationship between the field to be read and the description information based on the annotation information.
In other embodiments of the present application, the determining module 62 is further configured to determine an entity class to which a field to be read belongs; from the annotation repository, annotation information corresponding to the entity class is determined.
In other embodiments of the present application, the obtaining module 61 is further configured to obtain description information of the entity class; correspondingly, the generating module 63 is further configured to generate annotation information matching the entity class in the annotation library based on the description information and the initial annotation information corresponding to the entity class in response to the received write instruction indicating to write the description information.
In other embodiments of the present application, the obtaining module 61 is further configured to obtain a preset entity class set including a plurality of entity classes; correspondingly, the determining module 62 is further configured to determine initial annotation information of each preset entity class; the file generating apparatus 6 further includes an establishing module 64, configured to edit the initial annotation information according to an annotation mechanism for each preset entity class, so as to form annotation information of each preset entity class, so as to establish an annotation library.
In other embodiments of the present application, the determining module 62 is further configured to determine, based on the annotation information, description information corresponding to a field to be read; correspondingly, the generating module 63 is further configured to encapsulate the field to be read and the description information, and generate the target file.
In other embodiments of the present application, the fields to be read are at least two fields to be acquired, and the determining module 62 is further configured to determine, from the annotation library, annotation information matched with each field to be acquired; correspondingly, the generating module 63 is further configured to generate the target file based on the annotation information matched with the at least two fields to be acquired when the entity classes to which the at least two fields to be acquired belong are the same entity class; and under the condition that the entity classes to which the at least two fields to be acquired belong are different, generating target files with the same number of files as the entity classes based on the annotation information matched with each entity class and the fields to be acquired belonging to the entity classes.
In other embodiments of the present application, the determining module 62 is further configured to determine, in a preset to-be-written file area, a storage interval corresponding to each entity class; correspondingly, the file generating apparatus 6 further includes a storage module 65, configured to store the target file corresponding to each entity class in the storage interval corresponding to each entity class.
In other embodiments of the present application, the generating module 63 is further configured to generate a preset table matched with at least two fields to be acquired; and sequentially storing the fields to be acquired of each entity class and the corresponding description information in a preset table to obtain a target file corresponding to each entity class.
It should be noted that, in this embodiment, specific implementation processes of steps executed by each module may refer to implementation processes in the file generation method provided in embodiments corresponding to fig. 1 to 3, and are not described herein again.
The file generation device provided by the embodiment of the application can directly generate the target file representing the corresponding relation between the field to be acquired and the description information based on the operation of the annotation information and the code to be operated, which correspond to the entity class to which the field to be acquired belongs, so that the dependence of the generation of the related description file on developers can be reduced, and meanwhile, the generation efficiency of the related description file can be improved; meanwhile, based on the predetermined storage interval and the preset table, the generated target file and the phenomenon of disordered information management in the target file can be effectively avoided.
Based on the foregoing embodiment, an embodiment of the present application further provides a file generating device 7, where the file generating device 7 may be applied to a file generating method provided in the embodiments corresponding to fig. 1 to 3, and as shown in fig. 7, the file generating device 7 may include: a processor 71, a memory 72, and a communication bus 73, wherein:
the communication bus 73 is used to realize a communication connection between the processor 71 and the memory 72.
The processor 71 is configured to execute a program of the file generation method stored in the memory 72 to implement the file generation method provided with reference to the corresponding embodiments of fig. 1 to 3.
The file generation device provided by the embodiment of the application can directly generate the target file representing the corresponding relation between the field to be acquired and the description information based on the operation of the annotation information and the code to be operated, which correspond to the entity class to which the field to be acquired belongs, so that the dependence of the generation of the related description file on developers can be reduced, and meanwhile, the generation efficiency of the related description file can be improved; meanwhile, based on the predetermined storage interval and the preset table, the generated target file and the phenomenon of disordered information management in the target file can be effectively avoided.
Based on the foregoing embodiments, embodiments of the present application provide a computer-readable storage medium storing one or more programs, which are executable by one or more processors to implement the steps of the file generation method provided by the embodiments corresponding to fig. 1 to 3.
The computer-readable storage medium may be a Read Only Memory (ROM), a Programmable Read Only Memory (PROM), an Erasable Programmable Read Only Memory (EPROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a magnetic Random Access Memory (FRAM), a Flash Memory (Flash Memory), a magnetic surface Memory, an optical Disc, or a Compact Disc Read-Only Memory (CD-ROM); and may be various electronic devices such as mobile phones, computers, tablet devices, personal digital assistants, etc., including one or any combination of the above-mentioned memories.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above-mentioned serial numbers of the embodiments of the present application are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method described in the embodiments of the present application.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above description is only a preferred embodiment of the present application, and not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings of the present application, or which are directly or indirectly applied to other related technical fields, are included in the scope of the present application.

Claims (11)

1. A method of file generation, the method comprising:
acquiring a code to be operated;
responding to a received running instruction for indicating to run the code to be run, and determining a field to be read required by running the code to be run based on the code to be run;
determining annotation information matched with the field to be read from an annotation library;
and generating a target file representing the corresponding relation between the field to be read and the description information based on the annotation information.
2. The method according to claim 1, wherein the determining annotation information matching the field to be read from an annotation library comprises:
determining an entity class to which the field to be read belongs;
determining the annotation information corresponding to the entity class from the annotation repository.
3. The method of claim 2, wherein prior to determining the annotation information corresponding to the entity class from the annotation repository, the method further comprises:
acquiring the description information of the entity class;
in response to a received write instruction indicating to write the description information, generating, in the annotation library, the annotation information matching the entity class based on the description information and initial annotation information corresponding to the entity class.
4. The method of claim 3, wherein prior to obtaining the code to be run, the method further comprises:
acquiring a preset entity class set comprising a plurality of entity classes;
determining initial annotation information of each preset entity class;
and editing the initial annotation information according to an annotation mechanism mode for each preset entity class to form the annotation information of each preset entity class so as to establish the annotation library.
5. The method according to claim 1, wherein the generating a target file characterizing correspondence between the field to be read and the description information based on the annotation information comprises:
determining description information corresponding to the field to be read based on the annotation information;
and packaging the field to be read and the description information to generate the target file.
6. The method according to claim 1, wherein the fields to be read are at least two fields to be acquired, and the determining, from the annotation library, annotation information that matches the fields to be read includes:
determining annotation information matched with each field to be acquired from the annotation library;
correspondingly, the generating a target file representing the corresponding relationship between the field to be read and the description information based on the annotation information includes:
under the condition that the entity classes to which the at least two fields to be acquired belong are the same entity class, generating the target file based on the annotation information matched with the at least two fields to be acquired;
and under the condition that the entity classes to which the at least two fields to be acquired belong are different, generating target files with the same number of files as the entity classes based on the annotation information matched with each entity class and the fields to be acquired belonging to the entity classes.
7. The method according to claim 6, wherein after generating the target files with the same number of files as the entity classes based on the annotation information matched between each entity class and the fields to be acquired belonging to the entity classes when the entity classes to which the at least two fields to be acquired belong are different entity classes, the method further comprises:
determining a storage interval corresponding to each entity class in a preset file area to be written;
and storing the target file corresponding to each entity class in the storage interval corresponding to each entity class.
8. The method according to any one of claims 6 and 7, further comprising:
generating a preset table matched with the at least two fields to be acquired;
and sequentially storing the fields to be acquired of each entity class and the corresponding description information in the preset table to obtain a target file corresponding to each entity class.
9. A file generation apparatus, characterized by comprising: the device comprises an acquisition module, a determination module and a generation module, wherein:
the acquisition module is used for acquiring a code to be operated;
the determining module is used for responding to a received running instruction for indicating to run the code to be run, and determining a field to be read required by running the code to be run based on the code to be run;
the determining module is further used for determining annotation information matched with the field to be read from an annotation library;
and the generating module is used for generating a target file representing the corresponding relation between the field to be read and the description information based on the annotation information.
10. A file generation device characterized by comprising: a processor, a memory, and a communication bus;
the communication bus is used for realizing communication connection between the processor and the memory;
the processor is configured to execute the program in the memory to implement the file generation method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that the computer-readable storage medium stores one or more programs which are executable by one or more processors to implement the steps of the file generation method according to any one of claims 1 to 8.
CN202110335326.XA 2021-03-29 2021-03-29 File generation method, device, equipment and storage medium Pending CN113760360A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110335326.XA CN113760360A (en) 2021-03-29 2021-03-29 File generation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110335326.XA CN113760360A (en) 2021-03-29 2021-03-29 File generation method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113760360A true CN113760360A (en) 2021-12-07

Family

ID=78786808

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110335326.XA Pending CN113760360A (en) 2021-03-29 2021-03-29 File generation method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113760360A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116822451A (en) * 2023-06-29 2023-09-29 成都融见软件科技有限公司 Method, equipment and medium for reusing and displaying annotation area of variable chip design code

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116822451A (en) * 2023-06-29 2023-09-29 成都融见软件科技有限公司 Method, equipment and medium for reusing and displaying annotation area of variable chip design code
CN116822451B (en) * 2023-06-29 2024-03-08 成都融见软件科技有限公司 Method, equipment and medium for reusing and displaying annotation area of variable chip design code

Similar Documents

Publication Publication Date Title
CN111708539B (en) Application program code conversion method and device, electronic equipment and storage medium
CN108920133B (en) Cross-language programming method and device, electronic equipment and storage medium
CN105718289B (en) Component relation establishing method and equipment
CN110704063B (en) Method and device for compiling and executing intelligent contract
CN110704064B (en) Method and device for compiling and executing intelligent contract
CN113590104B (en) Platform and method for realizing graphical code-free software development
CN111399840A (en) Module development method and device
JP2022545489A (en) Smart contract client program generation method, system, device, and medium
CN111694613A (en) Decoupling method between application program modules, electronic device and storage medium
CN112052006A (en) Software code compiling method and system
CN112000320A (en) Automatic code generation method, device, equipment and storage medium
CN114153459A (en) Interface document generation method and device
CN114138748A (en) Database mapping file generation method, device, equipment and storage medium
EP1452962B1 (en) System and method for defining and using subclasses declaratively within markup
CN113760360A (en) File generation method, device, equipment and storage medium
CN113867704A (en) Code test processing method and device, electronic equipment and storage medium
CN111930419B (en) Code packet generation method and system based on deep learning model
CN113703779A (en) Cross-platform multi-language compiling method and ultra-light Internet of things virtual machine
CN111309332A (en) File content on-demand loading method and device, electronic equipment and storage medium
CN111488144A (en) Data processing method and equipment
CN111352631A (en) Interface compatibility detection method and device
CN110110299B (en) Text conversion method, device and server
CN112748946B (en) Application program installation file generation method and device, computing equipment and storage medium
CN114816364A (en) Method, device and application for dynamically generating template file based on Swagger
CN108549585B (en) Method for modifying application data, application testing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination