A method and system for generating java-based data transfer objects
By parsing Word documents to generate result sets and using the DtoGenerator tool to automatically generate DTOs, the problem of low efficiency in manually generating DTOs is solved, and efficient and standardized DTO generation is achieved.
Patent Information
- Application Number
- CN202310095160.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-10
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2043-02-10
AI Technical Summary
In existing technologies, manually generating Data Transfer Objects (DTOs) is labor-intensive and error-prone, resulting in low generation efficiency and non-compliance with Java specifications.
By setting the AbstractDocParse class to parse the interface data in the Word document, generating a result set, and using the DtoGenerator tool to automatically generate DTOs, human intervention is reduced and the generated DTOs are ensured to conform to Java specifications.
It reduces the workload of developers, lowers the error rate, improves the efficiency of DTO generation, and ensures that the generated DTOs fully comply with Java specifications.
Smart Images

Figure CN116126558B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a method and system for generating data transfer objects based on Java. Background Technology
[0002] Data Transfer Objects (DTOs) are frequently used in Java web applications to interface with third-party web APIs. The common practice is to define a corresponding DTO based on the data types required by the third-party web API. When sending an HTTP request to the third party, the request DTO is serialized into a JSON message and sent. The third party, after processing the request, also returns a JSON message as the result. The requesting party, upon receiving the JSON result, needs to deserialize it back into the result DTO, such as... Figure 1 The process shown is to send user information to a third party.
[0003] Third-party providers of API services typically provide API documentation (if it's a PDF document, you can convert it to Word first using a PDF to Word converter). This documentation will specify the data format for each web API, such as... Figure 2 As shown, developers need to create corresponding DTOs based on the documentation. Developers need to create corresponding DTOs based on the data format of each web interface in the documentation and interface files. The existing method of generating DTOs from Word documents involves manual writing of the code. Figure 2 For example, the parameter format for sequence number 1 will be written in the DTO as follows: Figure 3 As shown. Because manual coding is extremely labor-intensive and prone to errors, it often fails to conform to Java standards. For example, it may lack comments like "Transaction serial number -- Y, length: 50." or have insufficiently detailed comments, or directly copy field names from Word documents like "TxnSrlNo," which does not conform to Java's field naming convention of starting with a lowercase letter—"txnSrlNo," etc., resulting in low generation efficiency. Summary of the Invention
[0004] In order to overcome the shortcomings of the existing technology, one object of the present invention is to provide a method for generating data transfer objects based on Java, so as to solve the above-mentioned problems.
[0005] In order to overcome the shortcomings of the existing technology, another objective of the present invention is to provide a Java-based data transfer object generation system to solve the above-mentioned problems.
[0006] The technical scheme adopted by the present application to solve its technical problems is: a generation method of a data transmission object based on java, comprising:
[0007] A result set analysis step: setting an AbstractDocParse class, extracting interface data descriptions in a word document according to interfaces by using the AbstractDocParse class, and parsing the interface data descriptions into a result set;
[0008] A DTO generation step: inputting a request message corresponding to an interface extracted from the result set into a DtoGenerator tool to generate a DTO.
[0009] It is worth noting that in the result set analysis step, a parse(String docPath, String textPath) method is called to traverse all IBodyElement objects and obtain object types of the corresponding IBodyElement objects;
[0010] When the object type of the IBodyElement object is an XWPFParagraph type, each line of text in the IBodyElement object is read; when an isReqFormatStart(String line) abstract method or an isReqFormatStart(String line) abstract method returns "yes" for the text, the text is extracted and a preset string is added in front of the text, and then the text is stored in the result set; when an isApiStartLine(String line) abstract method returns "yes" for the text, the text is extracted and a preset string is added behind the text, and then the text is stored in the result set; when an isEnd(String line) abstract method returns "yes" for the text, the result set is returned and the process is ended;
[0011] When the object type of the IBodyElement object is an XWPFTableRow type, each line of data in the table is read, and each cell in each line of data is separated by "##", and then the data is stored in the result set.
[0012] Optionally, in the DTO generation step, a package name setPackageValue(String packageName) of the DTO, a root directory setSrcPath(String srcPath) of a project where the DTO is generated, and a processor processing field information of each field are set in the DtoGenerator tool in advance, wherein the field information includes a field name, a field type, a maximum length, whether the field can be empty, an explanation, and a note.
[0013] After the request message of the corresponding interface is extracted from the result set and input to the DtoGenerator tool, the build(String text, String dtoName) method of the DtoGenerator tool is called to generate the DTO under the root directory setSrcPath(String srcPath) and the package name setPackageValue(String packageName) of the corresponding project.
[0014] Specifically, the build(String text, String dtoName) method in the DTO generation step is: each field of each row of the result set is parsed into the corresponding field information of the DTO to form a field information list fieldDefinitionList, and the obtained field information list fieldDefinitionList is used to generate the DTO, wherein the field information of each field includes the field name, the field type, the maximum length, whether it can be empty, the description and the note.
[0015] Preferably, the DTO generation step specifically includes:
[0016] Splitting each row of data in the result set and traversing each row of data;
[0017] Creating a DtoFieldDefinition object;
[0018] Splitting each row of data after the splitting into multiple fields with "##", processing each field through a preset processor, and loading the field information of the processed field into the DtoFieldDefinition object;
[0019] Adding the DtoFieldDefinition object to the field information list fieldDefinitionList;
[0020] Returning the parsed field information list fieldDefinitionList;
[0021] Writing the package name to the result set;
[0022] Writing the class name to be imported to the result set, and then adding the Jackson tool and the Serializable interface: import com.fasterxml.jackson.annotation.JsonProperty and import java.io.Serializable;
[0023] Writing the class start part of the Dto to the result set;
[0024] Writing the field part of the DTO to the result set: first write the Serializable interface requirement private static final long serialVersionUID = 1L, and then translate each piece of information in the field information list fieldDefinitionList into a field in the DTO;
[0025] Writing the set and get of the DTO to the result set;
[0026] Writing the class end part of the DTO to the result set "{}", and outputting the result set with the root directory and package name as the directory and the class name as the file name.
[0027] A java-based data transmission object generation system, comprising a result set parsing module and a DTO generation module;
[0028] The result set parsing module is used to set the AbstractDocParse class, extract the interface data description in the word document according to the interface by using the AbstractDocParse class, and parse it into a result set;
[0029] The DTO generation module is used to input the request message corresponding to the interface extracted from the result set into the DtoGenerator tool to generate a DTO.
[0030] Preferably, the result set parsing module is used to call the parse(String docPath, String textPath) method to traverse all IBodyElement objects and obtain the object type of the corresponding IBodyElement object;
[0031] When the object type of the IBodyElement object is the XWPFParagraph type, read each line of text in the IBodyElement object; when the isReqFormatStart(String line) abstract method or the isReqFormatStart(String line) abstract method returns "yes" for the text, extract the text and add a preset string in front of the text, and then store it in the result set; when the isApiStartLine(String line) abstract method returns "yes" for the text, extract the text and add a preset string behind the text, and then store it in the result set; when the isEnd(String line) abstract method returns "yes" for the text, return the result set and end;
[0032] For when the object type of the IBodyElement object is the XWPFTableRow type, read the data of each row in the table, and make each cell in each row of data separated by "##", and then store in the result set.
[0033] Specifically, the DTO generation module is used for setting the package name setPackageValue(String packageName) of the DTO, the root directory setSrcPath(String srcPath) of the project after the generation of the DTO, and the processor for processing the field information of each field, wherein the field information includes the field name, the field type, the maximum length, whether it can be null, the description, and the remark; for extracting the request message of the corresponding interface from the result set and inputting to the DtoGenerator tool, calling the build(String text, String dtoName) method of the DtoGenerator tool, and generating the DTO under the root directory setSrcPath(String srcPath) and the package name setPackageValue(String packageName) of the corresponding project.
[0034] It is worth noting that the DTO generation module is used for parsing each field of each row of the result set into the corresponding field information of the DTO by the build(String text, String dtoName) method, forming a field information list fieldDefinitionList, and generating the DTO by the obtained field information list fieldDefinitionList, wherein the field information of each field includes the field name, the field type, the maximum length, whether it can be null, the description, and the remark.
[0035] Optionally, the DTO generation module is used for splitting each row of data in the result set and traversing each row of data; for newly creating a DtoFieldDefinition object; for splitting each row of data after the splitting into multiple fields by "##", processing each field by a preset processor, and loading the field information of the processed field into the DtoFieldDefinition object; for adding the DtoFieldDefinition object to the field information list fieldDefinitionList; and for returning the parsed field information list fieldDefinitionList.
[0036] For writing package name to result set; for writing class name to be imported to result set, then add Jackson tool and Serializable interface: import com.fasterxml.jackson.annotation.JsonProperty and import java.io.Serializable; for writing class start part of Dto to result set; for writing field part of Dto to result set: first write private static final longserialVersionUID = 1L required by Serializable interface, then translate each information in field information list into a field in DTO; for writing set and get of DTO to result set; for writing class end part of DTO to result set, and output result set with root directory and package name as directory and class name as file name.
[0037] The java-based data transmission object generation method has the advantages that: in the java-based data transmission object generation method, the information in the word document is parsed into a result set first, and then the corresponding DTO is generated through the result set, human intervention is reduced, thereby reducing the workload of the developer for converting the word document into the DTO, compared with manual conversion, the error rate of the java-based data transmission object generation method is lower when the method is executed step by step, and the generated DTO can completely meet the java specification, thereby improving the DTO generation efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0038] Figure 1 A schematic diagram of sending user information to a third-party service in the prior art;
[0039] Figure 2 A schematic diagram of data in a word document to be processed by a developer;
[0040] Figure 3 A schematic diagram of a DTO after processing;
[0041] Figure 4 A schematic diagram of a processing flow of the java-based data transmission object generation method of the application;
[0042] Figure 5 A flowchart of the java-based data transmission object generation method of the application;
[0043] Figure 6 A schematic diagram of an abstract method judgment flow of the application;
[0044] Figure 7 A schematic diagram of a result set formed in an embodiment of the application;
[0045] Figure 8 for Figure 7 A schematic diagram of a segment of data in the result set;
[0046] Figure 9 To process Figure 8 A diagram illustrating how the data forms a result set;
[0047] Figure 10 To Figure 9 A diagram illustrating the process of writing the result set into the DTO field section;
[0048] Figure 11 To Figure 9 A diagram illustrating the process of writing the result set into a DTO using set and get methods;
[0049] Figure 12 This is an example diagram illustrating the use of the DtoGenerator tool in one embodiment of the present invention;
[0050] Figure 13 This is a flowchart of the parse method in one embodiment of the present invention;
[0051] Figure 14 This is a system block diagram of a Java-based data transfer object generation system according to one embodiment of the present invention. Detailed Implementation
[0052] The specific embodiments of the present invention will be further described below with reference to the accompanying drawings. It should be noted that these descriptions are for the purpose of aiding understanding the present invention, but do not constitute a limitation thereof. Furthermore, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0053] like Figures 4-14 As shown, a method for generating a data transfer object based on Java includes:
[0054] Result set parsing steps: Set up the AbstractDocParse class, and use the AbstractDocParse class to extract the interface data descriptions from the Word document by interface and parse them into a result set; each interface data description in each line is separated by "##" to form the corresponding request message; if it is a PDF document, you can first use a PDF to Word tool to convert the document into a Word document; in this embodiment, the result set is the collection of all DTO information;
[0055] DTO generation steps: Extract the request message of the corresponding interface from the result set and input it into the DtoGenerator tool to generate the DTO.
[0056] As Figure 4 And Figure 5 As shown in the generation method of the java-based data transmission object, the information in the word document is parsed into a result set first, and then the corresponding DTO is generated through the result set. Since human intervention is reduced, the workload of the developer in converting the word document into DTO is reduced. Compared with manual conversion, the generation method of the java-based data transmission object has a lower error rate when executed step by step, and the generated DTO can fully comply with the java specification, thereby improving the generation efficiency of the DTO.
[0057] It is worth noting that, as Figure 13 shown in the result set parsing step, the parse(String docPath, String textPath) method is called to traverse all IBodyElement objects and obtain the object type of the corresponding IBodyElement object; wherein docPath is the path of the word document, and textPath is the path of the text file;
[0058] When the object type of the IBodyElement object is of the XWPFParagraph type, read each line of text in the IBodyElement object; when the isReqFormatStart(String line) abstract method or the isReqFormatStart(String line) abstract method returns "yes" to the text, extract the text and add a predetermined string in front of the text, and then store it in the result set; in this embodiment, the predetermined string is "……"; when the isApiStartLine(String line) abstract method returns "yes" to the text, extract the text and add a predetermined string behind the text, and then store it in the result set; when the isEnd(String line) abstract method returns "yes" to the text, return the result set and end;
[0059] When the object type of the IBodyElement object is of the XWPFTableRow type, read each line of data in the table, and separate each cell in each line of data with "##", and then store it in the result set.
[0060] The isApiStartLine(String line) abstract method is to judge the start of the interface, the isReqFormatStart(String line) abstract method is to judge the start of the request format description of the interface, the isReqFormatStart(String line) abstract method is to judge the start of the return format description of the interface, and the isEnd(String line) abstract method is to judge the end of the parsing, as shown in Figure 6 In the embodiment, the open source tool poi needs to be used, and IBodyElement, XWPFParagraph and XWPFTableRow are poi objects. The parse(String docPath, String textPath) method in AbstractDocParse is called to parse the word document into a text file as shown in Figure 7 XWPFParagraph is a world text object, and XWPFTableRow is a world table object. It is assumed that the inheritance class of the AbstractDocParse class is DocParse, and thus used as: newDocParse().parse(world path, result set text path) to generate a result set file.
[0061] Optionally, in the DTO generating step, the package name setPackageValue(String packageName) of the DTO, the root directory setSrcPath(String srcPath) of the project after the DTO is generated, and the processor of the field information of each field, wherein the field information includes the field name, the field type, the maximum length, whether it is null, the description and the remark, are set in the DtoGenerator tool in advance; in this embodiment, the DtoGenerator tool provides six processors, which are respectively the DescribeProcess field description processor, the FieldNameProcess field name processor, the IsNotNullProcess whether it is null processor, the LengthProcess maximum length processor, the RemarkProcess remark processor and the TypeProces field type processor, the user can customize the processor by implementing the DtoFieldAttributeProcess interface, and the processor is specified by using the addAttributeLocate(int index, DtoFieldAttributeProcess process) method, wherein the int index is the position of the specified field, and the DtoFieldAttributeProcess process is the processor for processing the field;
[0062] After the request message of the corresponding interface is extracted from the result set and input into the DtoGenerator tool, for example, the request message of the AFCOpenAcct interface in Figure 7 is as follows Figure 8 , and then the Dto is generated by putting it into the tool DtoGenerator, the build(String text, String dtoName) method of the DtoGenerator tool is called, and the DTO is generated under the root directory setSrcPath(String srcPath) and the package name setPackageValue(String packageName) of the corresponding project. In the build(String text, String dtoName) method, the String text is the specified result set which needs to be converted, and the String dtoName is the class name of the DTO to be generated.
[0063] Preferably, the build(String text, String dtoName) method in the DTO generating step is: parsing each field of each row of the result set into corresponding field information of the DTO to form a field information list fieldDefinitionList, and generating the DTO from the obtained field information list fieldDefinitionList, wherein the field information of each field includes field name, field type, maximum length, whether null, description and remarks.
[0064] Specifically, the DTO generating step is specifically:
[0065] Splitting each row of data in the result set and traversing each row of data;
[0066] Creating a DtoFieldDefinition object; the DtoFieldDefinition object is used to load field information of the field;
[0067] Splitting each row of data after the separation into multiple fields by “##”, processing each field by a preset processor, and loading the field information of the processed field into the DtoFieldDefinition object; the processor method is process(DtoFieldDefinition dotDefinition, String world), and the process inside fills the information processed from world into the DtoFieldDefinition object. After each field is processed, the field information of the row is filled into the DtoFieldDefinition object, and the process is as shown in Figure 8 The second line of the example is as shown in Figure 9 ;
[0068] Adding the DtoFieldDefinition object to the field information list fieldDefinitionList;
[0069] Returning the parsed field information list fieldDefinitionList;
[0070] Writing the package name to the result set; assuming that the package name is xx.yy, the package name written to the result set is package xx.yy;
[0071] Writing the class name to be imported to the result set, and then adding the Jackson tool and the Serializable interface: import com.fasterxml.jackson.annotation.JsonProperty and import java.io.Serializable;
[0072] As Figure 10 shown, @JsonProperty is Jackson's label.
[0073] The role of @JsonProperty is to replace the field with the value in @JsonProperty during serialization.
[0074] For example, helloWorld = "Hello", without @JsonPropert, the serialized result is {"helloWorld":"Hello"};
[0075] But with the label:
[0076] @JsonProperty("hello_world")
[0077] private String helloWorld
[0078] The serialized result is {"hello_world":"Hello"};
[0079] The beginning of the class that writes the Dto to the result set; assuming the class name is Hello, the beginning of the class that writes the Dto to the result set is public class Hello implements Serializable{;
[0080] The field part of the class that writes the DTO to the result set: as Figure 10 shown, first write private static final long serialVersionUID = 1L, which is required by the Serializable interface, and then translate each piece of information in the fieldDefinitionList into a field in the DTO; among them, the processing of the field name is to make the field name hump, such as: hello_world->helloWorld, where hello_world is not hump; helloWorld is hump, see if the field changes before and after processing, if it changes, use the hump processed name of the field name and add the @JsonProperty label, the label value uses the field name before processing, so that the field name can be kept in the java specification;
[0081] The set and get of the DTO are written into the result set, and each information (DtoFieldDefinition) in the field information list is translated into a pair of set and get methods in the DTO, such as Figure 11 , wherein the method name is camelized, for example: hello_world->setHelloWorld / getHelloWorld; in this embodiment, the set and get are the specifications of the javabean;
[0082] The class end part "} " of the DTO written into the result set is written, and the result set is output with the root directory and the package name as the directory and the class name as the file name. For example, if the root directory is: D:\mainbranch\zhb\xft_zbank\src\main\java, the package name is: Hello, and the package name is: xx.yy, then the final output is in the D:\mainbranch\zhb\xft_zbank\src\main\java\xx\yy\Hello.java file. The use example of the DtoGenerator tool is as follows Figure 12 , in the example, not all processors of the tool are used, and the field type and length are defined by the processor.
[0083] As shown in Figure 14 , preferably, a java-based data transmission object generation system includes a result set analysis module and a DTO generation module;
[0084] The result set analysis module is used to set the AbstractDocParse class, and the interface data description in the word document is extracted according to the interface by using the AbstractDocParse class, and is parsed into a result set;
[0085] The DTO generation module is used to input the request message corresponding to the interface in the result set into the DtoGenerator tool to generate a DTO.
[0086] It is worth noting that the result set analysis module is used to call the parse (String docPath, StringtextPath) method to traverse all IBodyElement objects and obtain the object type of the corresponding IBodyElement object;
[0087] for reading each line of text within the IBodyElement object when the object type of the IBodyElement object is XWPFParagraph type; for extracting the text and adding a preset string in front of the text when the isReqFormatStart(String line) abstract method or the isReqFormatStart(String line) abstract method returns "yes" for the text, and then storing in the result set; for extracting the text and adding a preset string behind the text when the isApiStartLine(String line) abstract method returns "yes" for the text, and then storing in the result set; for returning the result set and ending when the isEnd(String line) abstract method returns "yes" for the text.
[0088] for reading each line of data in the table when the object type of the IBodyElement object is XWPFTableRow type, and separating each cell in each line of data by "##", and then storing in the result set.
[0089] Specifically, the DTO generation module is configured to set a package name setPackageValue(String packageName) of the DTO, a root directory setSrcPath(String srcPath) of a project where the DTO is generated, and a processor for processing field information of each field, wherein the field information includes a field name, a field type, a maximum length, whether the field is null, an explanation, and a note; and the DTO generation module is configured to call a build(String text, String dtoName) method of the DtoGenerator tool after extracting a request message of a corresponding interface in the result set and inputting the request message into the DtoGenerator tool, and generating the DTO under the root directory setSrcPath(String srcPath) and the package name setPackageValue(String packageName) of the corresponding project.
[0090] Optionally, the DTO generation module is configured to parse each field of each row in the result set into corresponding field information of the DTO by the build(String text, String dtoName) method, form a field information list fieldDefinitionList, and generate the DTO by using the obtained field information list fieldDefinitionList, wherein the field information of each field includes a field name, a field type, a maximum length, whether the field is null, an explanation, and a note.
[0091] Preferably, the DTO generation module is configured to split each row of data in the result set and traverse each row of data; create a DtoFieldDefinition object; split each row of data separated by "##" into multiple fields, process each field by a preset processor, load the field information of the processed field into the DtoFieldDefinition object; add the DtoFieldDefinition object to the field information list fieldDefinitionList; and return the parsed field information list fieldDefinitionList.
[0092] write the package name to the result set; write the class name to be imported to the result set, and then add the Jackson tool and the Serializable interface: import com.fasterxml.jackson.annotation.JsonProperty and import java.io.Serializable; write the class start part of the Dto to the result set; write the field part of the Dto to the result set: first write the Serializable interface requirement private static final longserialVersionUID=1L, and then translate each piece of information in the field information list into a field in the DTO; write the set and get of the DTO to the result set; write the class end part "}" of the DTO to the result set, and output the result set with the root directory and the package name as the directory and the class name as the file name.
[0093] The embodiments of the present application are described in detail above with reference to the drawings, but the present application is not limited to the described embodiments. For those skilled in the art, various changes, modifications, replacements and variations can be made to the embodiments without departing from the principles and spirits of the present application, and still fall within the protection scope of the present application.
Claims
1. A method for generating data transfer objects based on Java, characterized in that, include: Result set parsing steps: Set up the AbstractDocParse class, and use the AbstractDocParse class to extract the interface data descriptions in the Word document according to the interface, and parse them into a result set; DTO generation steps: Extract the request message of the corresponding interface from the result set and input it into the DtoGenerator tool to generate the DTO; The DTO generation steps are as follows: Split the result set into each row and iterate through each row; Create a new DtoFieldDefinition object; Each row of data after splitting is divided into multiple fields using "##", each field is processed by a preset processor, and the field information of the processed fields is loaded into a DtoFieldDefinition object; Add the DtoFieldDefinition object to the field information list fieldDefinitionList; Returns a list of parsed field information, fieldDefinitionList; Write the package name to the result set; Write the class names to be imported into the result set, followed by the Jackson utility and the Serializable interface: `import com.fasterxml.jackson.annotation.JsonProperty` and `import java.io.Serializable`; Write the class beginning of the DTO to the result set; The field part of writing to the result set in the DTO is as follows: First, write the Serializable interface requirement private static final long serialVersionUID=1L. Then, translate each piece of information in the field information list fieldDefinitionList into a field in the DTO. The field name is processed by camelCase. It is then checked whether the field name has changed before and after the processing. If it has changed, the field name is changed to the camelCase name and the @JsonProperty tag is added. The tag value is the field name before processing. Write the set and get operations to the DTO in the result set; Write the class closing part "}" to the result set, and output the result set with the root directory and package name as the directory and the class name as the file name.
2. The method for generating a Java-based data transfer object according to claim 1, characterized in that: In the result set parsing step, the parse(String docPath, String textPath) method is called to traverse all IBodyElement objects and obtain the object type of the corresponding IBodyElement object; When the IBodyElement object is of type XWPFParagraph, read each line of text within the IBodyElement object; When the abstract methods isReqFormatStart(String line) or isReqFormatStart(String line) return "yes" to the text, extract the text, prepend the predefined string to the text, and then store it in the result set; when the abstract method isApiStartLine(String line) returns "yes" to the text, extract the text, prepend the predefined string to the text, and then store it in the result set; when the abstract method isEnd(String line) returns "yes" to the text, return the result set and end the process. When the IBoodyElement object is of type XWPFTableRow, it reads each row of data in the table, separates each cell in each row with "##", and then stores it in the result set.
3. The method for generating a Java-based data transfer object according to claim 2, characterized in that: In the DTO generation step, the package name of the DTO is set in advance in the DtoGenerator tool as setPackageValue(String packageName), the root directory of the project where the DTO will be generated as setSrcPath(String srcPath), and a processor for processing the field information of each field. The field information includes field name, field type, maximum length, whether it can be nullable, description and remarks. After extracting the request message of the corresponding interface from the result set and inputting it into the DtoGenerator tool, the build(String text, String dtoName) method of the DtoGenerator tool is called to generate DTOs in the root directory setSrcPath(String srcPath) and package name setPackageValue(String packageName) of the corresponding project.
4. The method for generating a Java-based data transfer object according to claim 3, characterized in that, The build(String text, String dtoName) method in the DTO generation step is as follows: each field in each row of the result set is parsed into the corresponding field information of the DTO, forming a field information list fieldDefinitionList. The obtained field information list fieldDefinitionList is used to generate the DTO, wherein the field information of each field includes field name, field type, maximum length, whether it can be null, description and remarks.
5. A Java-based data transfer object generation system, characterized in that: Includes a result set parsing module and a DTO generation module; The result set parsing module is used to set up the AbstractDocParse class, and use the AbstractDocParse class to extract the interface data descriptions in the Word document according to the interface and parse them into a result set. The DTO generation module is used to extract the request message of the corresponding interface from the result set and input it into the DtoGenerator tool to generate a DTO. The DTO generation module is used to split each row of data in the result set and iterate through each row; to create a new DtoFieldDefinition object; to split each row of data into multiple fields using "##", to process each field through a preset processor, and to load the field information of the processed fields into the DtoFieldDefinition object; to add the DtoFieldDefinition object to the field information list fieldDefinitionList; and to return the parsed field information list fieldDefinitionList. Used to write package names to the result set; used to write class names to be imported to the result set, followed by the Jackson utility and Serializable interface: `import com.fasterxml.jackson.annotation.JsonProperty` and `import java.io.Serializable`; used to write the beginning part of the class in the DTO to the result set; used to write the field part of the DTO to the result set: first write the Serializable interface requirement `private static final long serialVersionUID=1L`, then translate each piece of information in the field information list into a field in the DTO; the field name processing involves camelCase processing of the field name, checking if the field name has changed before and after processing, if it has changed, changing the field name to the camelCase name and adding the `@JsonProperty` tag, with the tag value being the original field name; used to write the set and get methods of the DTO to the result set; used to write the end part of the class in the DTO to the result set, and output the result set with the root directory and package name as the directory and the class name as the file name.
6. The Java-based data transfer object generation system according to claim 5, characterized in that: The result set parsing module is used to call the parse(String docPath, String textPath) method to traverse all IBodyElement objects and obtain the object type of the corresponding IBodyElement object; Used to read each line of text within an IBodyElement object when the object type of the IBodyElement object is XWPFParagraph; Used to extract the text when the abstract method isReqFormatStart(String line) or isReqFormatStart(String line) returns "yes" to the text, prepend a predefined string to the text, and then store it in the result set; Used to extract the text when the abstract method isApiStartLine(String line) returns "yes" to the text, append a predefined string to the text, and then store it in the result set; This is used to return the result set and end the process when the abstract method isEnd(String line) returns "Yes" to the text. Used when the IBoodyElement object is of type XWPFTableRow, to read each row of data in the table, separate each cell in each row with "##", and then store it in the result set.
7. The Java-based data transfer object generation system according to claim 6, characterized in that: The DTO generation module is used to pre-set the package name (setPackageValue(String packageName)), the root directory (setSrcPath(String srcPath)) of the project where the generated DTO will be located, and a processor to handle the field information of each field in the DtoGenerator tool. The field information includes the field name, field type, maximum length, whether it can be nullable, description, and remarks. After extracting the request message of the corresponding interface from the result set and inputting it into the DtoGenerator tool, it calls the build(String text, String dtoName) method of the DtoGenerator tool to generate the DTO under the root directory (setSrcPath(String srcPath)) and package name (setPackageValue(String packageName)) of the corresponding project.
8. The Java-based data transfer object generation system according to claim 7, characterized in that: The DTO generation module is used to parse each field of each row of the result set into the corresponding field information of the DTO through the build(String text, String dtoName) method, forming a field information list fieldDefinitionList, and generating a DTO from the obtained field information list fieldDefinitionList. The field information of each field includes field name, field type, maximum length, whether it can be null, description and remarks.
Citation Information
Patent Citations
Data conversion method, electronic device and computer readable storage medium
CN110532526A