Code file conversion method and device, equipment and medium
By identifying and refactoring code tags in Freemarker template files to generate target HTML files, the problem of high manpower consumption in front-end and back-end system conversion is solved, and refactoring efficiency is improved.
Patent Information
- Application Number
- CN202411056825.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-11-12
AI Technical Summary
Upgrading a front-end and back-end integrated system to a front-end and back-end separated system in the current technology requires a lot of human resources and time, and the reconstruction efficiency is low.
By obtaining the Freemarker template file, identifying and extracting the tag types of code tags, extracting code snippets from the template file based on the tag types, refactoring them, and generating the target HTML file to achieve system conversion.
It reduces the amount of code and time spent by technical personnel, and improves the efficiency of code file conversion and the refactoring efficiency of front-end and back-end separation systems.
Smart Images

Figure CN118939272A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of code conversion technology, and in particular to a code file conversion method, device, equipment and medium. Background Art
[0002] With the continuous advancement of science and information technology and the rapid development of Internet technology, the separation of front-end and back-end has become the industry standard for Internet project development.
[0003] Currently, more and more websites are developed with front-end and back-end separation. If you want to upgrade the original front-end and back-end integrated system to a front-end and back-end separation system, you generally need to reconstruct the entire system, which requires manual operation by relevant technical personnel, including writing new code in a new technical language, sorting out old business logic, and redesigning the interaction method.
[0004] However, system reconstruction based on the above manual operation method consumes a lot of human resources and time, and the reconstruction efficiency is low. Summary of the invention
[0005] The present invention provides a code file conversion method, device, equipment and medium, which are used to solve the defects in the related art that system reconstruction based on manual operation consumes a lot of human resources and time and has low reconstruction efficiency, and improve the reconstruction efficiency.
[0006] In a first aspect, the present invention provides a code file conversion method, comprising: Get the Freemarker template file corresponding to the code file to be converted in the front-end and back-end integrated system; Identify that the file type of the Freemarker template file is a preset type, and then search for multiple code tags in the Freemarker template file; For any of the code tags, determine a tag type corresponding to the code tag, extract a code snippet corresponding to the code tag in the Freemarker template file according to the tag type, and reconstruct the code snippet according to the code tag and the tag type to obtain a corresponding reconstructed code; The reconstructed code corresponding to any of the code tags is written into a preset HTML file to obtain a target HTML file; wherein the target HTML file is used to generate the front end and / or back end in a front-end and back-end separation system, and the front-end and back-end separation system corresponds to the front-end and back-end integration system.
[0007] Optionally, the tag type is a tree structure tag or a standard tag; wherein: The standard tags include an external resource link element link tag, a script element script tag, a style information element style tag and / or a document body element body tag.
[0008] Optionally, extracting a code snippet corresponding to the code tag in the Freemarker template file according to the tag type includes: When the tag type is a tree structure tag, searching the Freemarker template file for a root node tag and at least one child node tag corresponding to the tree structure tag, and extracting code snippets corresponding to the root node tag and each child node tag respectively; When the tag type is the link tag, the script tag, the style tag or the body tag, the code snippet corresponding to the code tag is directly extracted from the Freemarker template file.
[0009] Optionally, reconstructing the code snippet according to the code tag and the tag type to obtain corresponding reconstructed code includes: Determining a corresponding reconstruction tag according to the code tag, and determining a corresponding code conversion method according to the tag type; Convert the code snippet based on the code conversion method to obtain a corresponding hypertext markup language HTML web page text; The HTML webpage text and the reconstruction tag are concatenated to obtain corresponding reconstruction code.
[0010] Optionally, determining a corresponding refactoring tag according to the code tag includes: Finding multiple corresponding candidate refactoring tags in the tag correspondence according to the code tag, and displaying the multiple candidate refactoring tags to prompt the user to select from the multiple candidate refactoring tags; In response to the label selection instruction input by the user, a corresponding candidate refactoring label is selected from the plurality of candidate refactoring labels and used as the refactoring label corresponding to the code label.
[0011] Optionally, determining a corresponding code conversion method according to the tag type includes: When the tag type is a tree structure tag, determining a corresponding first code conversion mode according to the tree structure tag; When the tag type is a link tag, a script tag, a style tag or a body tag, a corresponding second code conversion mode is determined according to the standard tag; wherein the second code conversion mode is different from the first code conversion mode.
[0012] Optionally, the Freemarker template file includes multiple lines of code; searching for multiple code tags in the Freemarker template file includes: Using a preset regular expression and / or lexical analyzer, traversal matching is performed in the multiple lines of code in the Freemarker template file to find the multiple code tags from the multiple lines of code.
[0013] In a second aspect, the present invention provides a code file conversion device, comprising: An acquisition unit is used to acquire a Freemarker template file corresponding to a code file to be converted in the front-end and back-end integrated system; A searching unit, configured to identify that the file type of the Freemarker template file is a preset type, and then search for a plurality of code tags in the Freemarker template file; A first determining unit, configured to determine, for any of the code tags, a tag type corresponding to the code tag; An extraction unit, configured to extract a code snippet corresponding to the code tag in the Freemarker template file according to the tag type; A refactoring unit, configured to refactor the code snippet according to the code tag and the tag type to obtain a corresponding refactored code; A writing unit is used to write the reconstructed code corresponding to any of the code tags into a preset HTML file to obtain a target HTML file; wherein the target HTML file is used to generate the front end and / or back end in a front-end and back-end separation system, and the front-end and back-end separation system corresponds to the front-end and back-end integrated system.
[0014] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor are communicatively connected to each other, computer instructions are stored in the memory, and the processor executes the code file conversion method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0015] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the code file conversion method of the first aspect or any corresponding embodiment thereof.
[0016] The code file conversion method, device, equipment and medium provided by the present invention can obtain a Freemarker template file corresponding to a code file to be converted in a front-end and back-end integrated system; identify that the file type of the Freemarker template file is a preset type, and then search for multiple code tags in the Freemarker template file; for any code tag, determine the tag type corresponding to the code tag, extract the code fragment corresponding to the code tag in the Freemarker template file according to the tag type, and reconstruct the code fragment according to the code tag and the tag type to obtain the corresponding reconstructed code; write the reconstructed code corresponding to any code tag into a preset HTML file to obtain a target HTML file; wherein the target HTML file is used to generate the front end and / or the back end in the front-end and back-end separation system, and the front-end and back-end separation system corresponds to the front-end and back-end integrated system. The present invention can obtain a Freemarker template file generated by a technician who only needs to perform a small amount of code writing work according to the code file to be converted, and then reconstruct the code in the Freemarker template file to obtain the reconstructed code and write it into the HTML file, that is, the front end and / or back end for generating the front end and back end separation system can be obtained, thereby realizing intelligent conversion of code files, improving the efficiency of code reconstruction, and effectively reducing the amount of code and time required to be written by relevant technicians in the relevant technology to upgrade the front end and back end integrated system to the front end and back end separation system, thereby improving the code file conversion efficiency and improving the reconstruction efficiency of the front end and back end separation system. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 A flowchart of a code file conversion method provided by an embodiment of the present invention; Figure 2 A flowchart of another code file conversion method provided by an embodiment of the present invention; Figure 3 A flowchart of another code file conversion method provided by an embodiment of the present invention; Figure 4 A flowchart of another code file conversion method provided by an embodiment of the present invention; Figure 5 A schematic diagram of the structure of a code file conversion device provided by an embodiment of the present invention; Figure 6A schematic diagram of the structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0019] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0020] Combine the following Figure 1-Figure 4 The code file conversion method of the present invention is described.
[0021] like Figure 1 As shown, this embodiment proposes a first code file conversion method, which may include the following steps: S101, obtaining a Freemarker template file corresponding to a code file to be converted in a front-end and back-end integrated system.
[0022] It should be noted that most software in Internet companies is developed based on Java language, using the hierarchical development of mode, view and controller (Model View Controller, MVC). Freemarker is a template engine, specifically a general tool for generating text output based on templates. It can be written in pure Java and can be designed to generate Hypertext Markup Language (HTML) web pages, especially applications based on the MVC mode, which extract the view from the business logic. The business no longer includes the display of the view, but the view is handed over to FreeMarker for output. Although FreeMarker has some programming capabilities, the data to be displayed is usually prepared by the Java program, and the page is generated by FreeMarker, and the prepared data is displayed through the template.
[0023] Optionally, a FreeMarker template file can be a markup text content composed of a tree structure, mainly including elements, attributes and text.
[0024] Specifically, the content in the Freemarker template file can be filled in by the technician according to the code file to be converted. It should be noted that the Freemarker template file can be used as a code file conversion tool. The technician only needs to fill in a small amount of code in the Freemarker template file according to the code file to be converted, and the machine can then perform intelligent conversion on the code file.
[0025] S102: If the file type of the Freemarker template file is identified as a preset type, multiple code tags are searched in the Freemarker template file.
[0026] The preset type may be a file type pre-specified by a technician.
[0027] Specifically, this embodiment can first obtain a Freemarker template file, and then identify the file type of the Freemarker template file. If the file type of the Freemarker template file is a preset type, then search for code tags in the Freemarker template file. If the Freemarker template file is not a preset type, then stop executing subsequent steps without searching for code tags in the Freemarker template file.
[0028] Optionally, the Freemarker template file includes multiple lines of code. The above method of searching for multiple code tags in the Freemarker template file may include: Use the preset regular expression and / or lexical analyzer to traverse and match multiple lines of code in the Freemarker template file to find multiple code tags from multiple lines of code.
[0029] S103: For any code tag, determine the tag type corresponding to the code tag.
[0030] Specifically, in this embodiment, for any code tag found, the tag type corresponding to the code tag can be determined according to the code tag.
[0031] Optionally, the tag type is a tree structure tag or a standard tag. Standard tags include the link tag for external resource links, the script tag for script elements, the style tag for style information elements, and / or the body tag for document main body elements.
[0032] Specifically, the tree structure tag includes a root node tag and at least one child node tag, and has a tree structure relationship.
[0033] S104. Extracting a code snippet corresponding to the code tag from the Freemarker template file according to the tag type.
[0034] Specifically, in this embodiment, for any code tag, the corresponding tag type can be determined, and then the code snippet corresponding to the code tag can be extracted from the Freemarker template file according to the tag type.
[0035] Optionally, step S104 may include: When the tag type is a tree structure tag, search for a root node tag and at least one child node tag corresponding to the tree structure tag in the Freemarker template file, and extract code snippets corresponding to the root node tag and each child node tag respectively; When the tag type is a link tag, a script tag, a style tag, or a body tag, the code snippet corresponding to the code tag is directly extracted from the Freemarker template file.
[0036] Specifically, when the tag type corresponding to the code tag is a tree structure tag, this embodiment can determine the root node tag and at least one child node tag related to the tree structure tag in the Freemarker template file. It can be understood that the tree structure tag can be the root node tag or a child node tag in the at least one child node tag.
[0037] Specifically, after finding the root node tag and each child node tag, this embodiment can extract the code snippets corresponding to the root node tag and each child node tag. Of course, this embodiment can also extract the code snippet corresponding to the root node tag when finding the root node tag, and extract the code snippet corresponding to a child node tag when finding a child node tag.
[0038] Specifically, in this embodiment, when the tag type corresponding to the code tag is a standard tag, the code snippet corresponding to the code tag can be directly extracted from the Freemarker template file.
[0039] S105: reconstruct the code snippet according to the code tag and tag type to obtain corresponding reconstructed code.
[0040] Specifically, for any code tag, this embodiment can determine the corresponding tag type and find the corresponding code snippet. Afterwards, this embodiment can reconstruct the code snippet according to the code tag and the tag type to obtain the corresponding reconstructed code.
[0041] Optionally, step S105 may include: Determine the corresponding refactoring tag according to the code tag, and determine the corresponding code conversion method according to the tag type; The code fragments are converted based on a code conversion method to obtain corresponding hypertext markup language HTML web page text; Concatenate HTML web page text and refactor tags to get the corresponding refactored code.
[0042] Optionally, the above-mentioned determination of corresponding refactoring tags according to code tags includes: Finding multiple corresponding candidate refactoring labels in the label correspondence according to the code label, and displaying the multiple candidate refactoring labels to prompt the user to select from the multiple candidate refactoring labels; In response to a label selection instruction input by a user, a corresponding candidate refactoring label is selected from a plurality of candidate refactoring labels and used as the refactoring label corresponding to the code label.
[0043] Specifically, in this embodiment, the user can customize and select the reconstruction label corresponding to the code label.
[0044] Specifically, this embodiment can determine the corresponding code conversion method according to the tag type corresponding to the code tag. It should be noted that the code conversion method can convert the code fragment in the Freemarker template file into the corresponding HTML webpage text.
[0045] Optionally, the above-mentioned determining a corresponding code conversion method according to the tag type includes: When the tag type is a tree structure tag, determining a corresponding first code conversion mode according to the tree structure tag; When the tag type is a link tag, a script tag, a style tag or a body tag, a corresponding second code conversion mode is determined according to the standard tag; wherein the second code conversion mode is different from the first code conversion mode.
[0046] The first code conversion method is a code conversion method corresponding to the tree structure tag, which can be used to convert the code fragment corresponding to the tree structure tag into the corresponding HTML webpage text.
[0047] The second code conversion method is a code conversion method different from the first code conversion method. Specifically, the second code conversion method is a code conversion method corresponding to a standard tag, which can be used to convert a code segment corresponding to a standard tag into a corresponding HTML webpage text.
[0048] Specifically, after determining the code conversion method corresponding to the code tag, this embodiment can use the code conversion method to convert the code fragment corresponding to the code tag into the corresponding HTML webpage text.
[0049] Specifically, this embodiment can determine the corresponding reconstruction tag and HTML webpage text according to any code tag found. For any code tag, this embodiment can splice the reconstruction tag corresponding to the code tag and the HTML webpage text, that is, the reconstruction code corresponding to the code tag can be obtained.
[0050] S106. Write the reconstructed code corresponding to any code tag into a preset HTML file to obtain a target HTML file; wherein the target HTML file is used to generate the front end and / or back end in the front end and back end separation system, and the front end and back end separation system corresponds to the front end and back end integration system.
[0051] The preset HTML file may be an empty HTML file.
[0052] Specifically, in this embodiment, the reconstructed code corresponding to each found code tag can be written into an HTML file and saved.
[0053] The target HTML file includes the reconstructed code corresponding to each code tag.
[0054] Specifically, this embodiment can generate the front end and / or back end in the front end and back end separation system based on the target HTML file, thereby reconstructing the front end and back end integrated system into the front end and back end separation system.
[0055] The code file conversion method proposed in this embodiment can obtain a Freemarker template file corresponding to a code file to be converted in a front-end and back-end integrated system; identify that the file type of the Freemarker template file is a preset type, and then search for multiple code tags in the Freemarker template file; for any code tag, determine the tag type corresponding to the code tag, extract the code fragment corresponding to the code tag in the Freemarker template file according to the tag type, and reconstruct the code fragment according to the code tag and the tag type to obtain the corresponding reconstructed code; write the reconstructed code corresponding to any code tag into a preset HTML file to obtain a target HTML file; wherein the target HTML file is used to generate the front end and / or back end in the front-end and back-end separation system, and the front-end and back-end separation system corresponds to the front-end and back-end integrated system. This embodiment can obtain a Freemarker template file generated by a technician who only needs to perform a small amount of code writing work based on the code file to be converted, and then reconstruct the code in the Freemarker template file to obtain the reconstructed code and write it into the HTML file, that is, the front end and / or back end for generating the front end and back end separation system can be obtained, thereby realizing intelligent conversion of code files, improving the efficiency of code reconstruction, and effectively reducing the amount of code and time required to be written by relevant technicians in the relevant technology to upgrade the front end and back end integrated system to the front end and back end separation system, thereby improving the code file conversion efficiency and the reconstruction efficiency of the front end and back end separation system.
[0056] based on Figure 1 This embodiment proposes a second code file conversion method, which may include the following steps: S11. Load the FreeMarker template file and determine to parse the link, script, style, and body code fragments in the FreeMarker template file.
[0057] S12. After determining that the file type of the FreeMarker file is a preset type, the content of the FreeMarker file is matched by a preset regular expression and lexical analyzer, and the child nodes in the FreeMarker file are traversed to obtain the attributes or content of the child nodes.
[0058] S13, Tags and tokens through lexical, grammatical analysis, regular expressions, finite automata, conversion from regular expressions to finite automata, lexical analyzer based on context-free grammar, recursive descent analysis, LR analysis, error handling, automatic generation of type systems by grammatical analyzers, attributes.
[0059] It should be noted that developers can customize the configuration and modify the properties, which enhances the flexibility and maintainability of the code and provides strong support for user data binding. Property change notifications further enhance the responsiveness of the application, allowing developers to create a more flexible, interactive and intuitive conversion and parsing experience.
[0060] S14, through variable address allocation, arithmetic expression translation, Boolean expression translation, array, structure and string translation, control flow translation, function call translation.
[0061] Among them, the default configured parser expressions and parameters provide support for subsequent Freemarker file content through these configured expressions and parameters.
[0062] S15. The final target code is obtained according to the target architecture, tree matching code generation, dynamic programming-based code generation, register allocation, instruction scheduling, control flow analysis, data flow analysis, dead code removal, constants, copy propagation, and static single assignment.
[0063] The code file conversion method proposed in this embodiment can provide software developers with a more efficient and convenient development model, and promote innovation and progress in the field of software development. Simplify and accelerate the application development process, lower the development threshold, and enable developers to quickly build applications. The automatic file conversion method reduces the need for manual coding, so applications can be developed faster. This enables the development team to iterate development faster and respond quickly to user feedback and market demand. Using automation technology and tools to improve the efficiency, quality and reliability of the software development process, the main goal of the automated conversion development model is to reduce manual repetitive work, reduce error rates, speed up product launches, and improve the maintainability and reliability of the software.
[0064] like Figure 2 As shown, this embodiment proposes a third code file conversion method, which may include the following steps: S201, read the FreeMarker template file, and determine to parse the link, script, style and body code fragments in the FreeMarker template file.
[0065] Specifically, this embodiment can load a FreeMarker template file and determine to parse link, script, style, and body code fragments in the FreeMarker template file.
[0066] It should be noted that the code tags in the Freemarker template file can be <#if>, <#list>, <#assign>, and <#switch>, etc.
[0067] S202: After determining that the file type of the Freemarker template file is a preset type, the content of the Freemarker template file is matched by using a preset regular expression and lexical analyzer to determine a candidate character string.
[0068] Specifically, this embodiment may provide a default character string to the user, and the user may fill in the character string by customization.
[0069] S203: taking the character string containing the preset language in the candidate character strings as the target text to be processed.
[0070] S204: Determine a replacement rule corresponding to the file type of the Freemarker template file to be processed.
[0071] S205: Use the determined replacement rule to replace the target text and write it into the prepared HTML file.
[0072] Specifically, this embodiment can perform the replacement process by means of preset variables, arithmetic expressions, Boolean expressions, arrays, structures, strings, functions, etc., to change one language into another language, thus avoiding manual writing line by line.
[0073] The code file conversion method proposed in this embodiment can realize intelligent reconstruction of code snippets corresponding to code tags, intelligently convert code written in one language into code written in another language, and improve code reconstruction efficiency.
[0074] like Figure 3 As shown, this embodiment proposes a fourth code file conversion method, which may include the following steps: S301, reading a FreeMarker template file, and determining to parse a body code fragment in the FreeMarker template file.
[0075] S302: After determining that the file type of the Freemarker template file is a preset type, traverse the child nodes in the Freemarker template file to obtain attributes or contents of the child nodes.
[0076] Specifically, the Freemarker template content may be composed of a tree structure, including a root node tag and a child node tag. It should be noted that a Freemarker template file may include many modules, and a child node tag is one of them.
[0077] S303: Determine the attribute or content of the child node containing the preset language through a preset regular expression.
[0078] S304: taking the determined attribute or content of the sub-node containing the preset language as the target text to be processed.
[0079] S305 : Determine the replacement rule corresponding to the child node in the Freemarker template file to be processed according to the preset correspondence between the child node type and the replacement rule.
[0080] S306: Use the determined replacement rule to replace the target text and write it into the prepared HTML file.
[0081] The code file conversion method proposed in this embodiment can simultaneously convert code snippets corresponding to standard tags and tree structure tags to obtain corresponding reconstructed codes, diversify reconstructing functions, and ensure the reliability of code reconstructing.
[0082] based on Figure 1 This embodiment proposes a fifth code file conversion method, which may include the following steps: S401. Obtain a Freemarker template file to be transcoded.
[0083] S402. The Parser performs syntax analysis on the Freemarker template file.
[0084] S403: Convert into a Document Object Model (DOM) tree structure.
[0085] S404: Parse and create corresponding DOM nodes.
[0086] S405: construct an empty html file, write the converted DOM tree into the empty html file, and obtain a written html file.
[0087] It should be noted that, in this embodiment, a single parser can be used to convert the FreeMarker template file into HTML web page text content.
[0088] Specifically, this embodiment can quickly perform repetitive tasks, reduce manual intervention, and improve work efficiency through intelligent conversion of code files. A large amount of automatic conversion work can be completed in a short time to ensure software quality. At the same time, human errors can be reduced, and code quality and system stability can be improved. Through intelligent conversion of code files, problems can also be discovered and repaired in a timely manner, reducing the probability of problems occurring.
[0089] In practical applications, this embodiment can quickly iterate and optimize products to meet the rapid changes in market demand. Automated conversion usually has good scalability and can be customized and adjusted according to team needs. This enables the team to respond to various project sizes and complexities more flexibly. In the process of implementing automated conversion, the automated process is continuously optimized and improved. By collecting feedback, analyzing data and summarizing experience, the automated system is gradually improved to improve the efficiency and stability of software development.
[0090] The code file conversion method proposed in this embodiment can convert the FreeMarker template file into HTML web page text content through a parser, effectively ensuring the vision of code reconstruction and code file conversion.
[0091] like Figure 5 As shown, this embodiment provides a code file conversion device, which may include: An acquisition unit 101 is used to acquire a Freemarker template file corresponding to a code file to be converted in a front-end and back-end integrated system; A searching unit 102 is used to identify that the file type of the Freemarker template file is a preset type, and then search for multiple code tags in the Freemarker template file; A first determining unit 103 is used to determine, for any code tag, a tag type corresponding to the code tag; An extraction unit 104 is used to extract a code snippet corresponding to a code tag in a Freemarker template file according to a tag type; A refactoring unit 105, configured to refactor the code snippet according to the code tag and tag type to obtain corresponding refactored code; The writing unit 106 is used to write the reconstructed code corresponding to any code tag into a preset HTML file to obtain a target HTML file; wherein the target HTML file is used to generate the front end and / or back end in the front end and back end separation system, and the front end and back end separation system corresponds to the front end and back end integrated system.
[0092] It should be noted that the processing of the acquisition unit 101, the search unit 102, the first determination unit 103, the extraction unit 104, the reconstruction unit 105 and the writing unit 106 and the beneficial effects thereof can be respectively referred to in Figure 1 Steps S101 to S106 in the above are not described in detail.
[0093] Optionally, the tag type is a tree structure tag or a standard tag; Standard tags include the link tag for external resource links, the script tag for script elements, the style tag for style information elements, and / or the body tag for document main body elements.
[0094] Optionally, the extraction unit 104 is further configured to: When the tag type is a tree structure tag, search for a root node tag and at least one child node tag corresponding to the tree structure tag in the Freemarker template file, and extract code snippets corresponding to the root node tag and each child node tag respectively; When the tag type is a link tag, a script tag, a style tag, or a body tag, the code snippet corresponding to the code tag is directly extracted from the Freemarker template file.
[0095] Optionally, the reconstruction unit 105 is further configured to: Determine the corresponding refactoring tag according to the code tag, and determine the corresponding code conversion method according to the tag type; The code fragments are converted based on a code conversion method to obtain corresponding hypertext markup language HTML web page text; Concatenate HTML web page text and refactor tags to get the corresponding refactored code.
[0096] Optionally, the reconstruction unit 105 is further configured to: Finding multiple corresponding candidate refactoring labels in the label correspondence according to the code label, and displaying the multiple candidate refactoring labels to prompt the user to select from the multiple candidate refactoring labels; In response to a label selection instruction input by a user, a corresponding candidate refactoring label is selected from a plurality of candidate refactoring labels and used as the refactoring label corresponding to the code label.
[0097] Optionally, the reconstruction unit 105 is further configured to: When the tag type is a tree structure tag, determining a corresponding first code conversion mode according to the tree structure tag; When the tag type is a link tag, a script tag, a style tag or a body tag, a corresponding second code conversion mode is determined according to the standard tag; wherein the second code conversion mode is different from the first code conversion mode.
[0098] Optionally, the Freemarker template file includes multiple lines of code; The searching unit 102 is further configured to: Use the preset regular expression and / or lexical analyzer to traverse and match multiple lines of code in the Freemarker template file to find multiple code tags from multiple lines of code.
[0099] The code file conversion device proposed in this embodiment can obtain a Freemarker template file corresponding to a code file to be converted in a front-end and back-end integrated system; identify that the file type of the Freemarker template file is a preset type, and then search for multiple code tags in the Freemarker template file; for any code tag, determine the tag type corresponding to the code tag, extract the code fragment corresponding to the code tag in the Freemarker template file according to the tag type, and reconstruct the code fragment according to the code tag and the tag type to obtain the corresponding reconstructed code; write the reconstructed code corresponding to any code tag into a preset HTML file to obtain a target HTML file; wherein the target HTML file is used to generate the front end and / or back end in the front-end and back-end separation system, and the front-end and back-end separation system corresponds to the front-end and back-end integrated system. This embodiment can obtain a Freemarker template file generated by a technician who only needs to perform a small amount of code writing work based on the code file to be converted, and then reconstruct the code in the Freemarker template file to obtain the reconstructed code and write it into the HTML file, that is, the front end and / or back end for generating the front end and back end separation system can be obtained, thereby realizing intelligent conversion of code files, improving the efficiency of code reconstruction, and effectively reducing the amount of code and time required to be written by relevant technicians in the relevant technology to upgrade the front end and back end integrated system to the front end and back end separation system, thereby improving the code file conversion efficiency and the reconstruction efficiency of the front end and back end separation system.
[0100] The code file conversion device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0101] The embodiment of the present invention also provides a computer device having the above Figure 5 The code file conversion device shown.
[0102] See also Figure 6 , a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are connected to each other using different buses for communication, and can be installed on a common motherboard or installed in other ways as needed. The processor can process instructions executed in the computer device, including instructions stored in or on the memory to display graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 6 A processor 10 is taken as an example.
[0103] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0104] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0105] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function. The data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage devices. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0106] The memory 20 may include a volatile memory, such as a random access memory. The memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive. The memory 20 may also include a combination of the above-mentioned types of memory.
[0107] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0108] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0109] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A code file conversion method, characterized in that: include: Get the Freemarker template file corresponding to the code file to be converted in the front-end and back-end integrated system; Identify that the file type of the Freemarker template file is a preset type, and then search for multiple code tags in the Freemarker template file; For any of the code tags, determine a tag type corresponding to the code tag, extract a code snippet corresponding to the code tag in the Freemarker template file according to the tag type, and reconstruct the code snippet according to the code tag and the tag type to obtain a corresponding reconstructed code; The reconstructed code corresponding to any of the code tags is written into a preset HTML file to obtain a target HTML file; wherein the target HTML file is used to generate the front end and / or back end in a front-end and back-end separation system, and the front-end and back-end separation system corresponds to the front-end and back-end integration system.
2. The method according to claim 1, characterized in that The tag type is a tree structure tag or a standard tag; wherein: The standard tags include an external resource link element link tag, a script element script tag, a style information element style tag and / or a document body element body tag.
3. The method according to claim 2, characterized in that Extracting the code snippet corresponding to the code tag in the Freemarker template file according to the tag type includes: When the tag type is a tree structure tag, searching the Freemarker template file for a root node tag and at least one child node tag corresponding to the tree structure tag, and extracting code snippets corresponding to the root node tag and each child node tag respectively; When the tag type is the link tag, the script tag, the style tag or the body tag, the code snippet corresponding to the code tag is directly extracted from the Freemarker template file.
4. The method according to claim 1, characterized in that: The reconstructing the code snippet according to the code tag and the tag type to obtain corresponding reconstructed code includes: Determining a corresponding reconstruction tag according to the code tag, and determining a corresponding code conversion method according to the tag type; Convert the code snippet based on the code conversion method to obtain a corresponding hypertext markup language HTML web page text; The HTML webpage text and the reconstruction tag are concatenated to obtain corresponding reconstruction code.
5. The method according to claim 4, characterized in that The determining a corresponding reconstruction tag according to the code tag includes: Finding a plurality of corresponding candidate refactoring tags in the tag correspondence according to the code tag, and displaying the plurality of candidate refactoring tags to prompt the user to select from the plurality of candidate refactoring tags; In response to the label selection instruction input by the user, a corresponding candidate refactoring label is selected from the plurality of candidate refactoring labels and used as the refactoring label corresponding to the code label.
6. The method according to claim 4, characterized in that The determining a corresponding code conversion method according to the tag type includes: When the tag type is a tree structure tag, determining a corresponding first code conversion mode according to the tree structure tag; When the tag type is a link tag, a script tag, a style tag or a body tag, a corresponding second code conversion mode is determined according to the standard tag; wherein the second code conversion mode is different from the first code conversion mode.
7. The method according to claim 1, characterized in that The Freemarker template file includes multiple lines of code; searching for multiple code tags in the Freemarker template file includes: Using a preset regular expression and / or lexical analyzer, traversal matching is performed in the multiple lines of code in the Freemarker template file to find the multiple code tags from the multiple lines of code.
8. A code file conversion device, characterized in that: include: An acquisition unit is used to acquire a Freemarker template file corresponding to a code file to be converted in the front-end and back-end integrated system; A searching unit, configured to identify that the file type of the Freemarker template file is a preset type, and then search for a plurality of code tags in the Freemarker template file; A first determining unit, configured to determine, for any of the code tags, a tag type corresponding to the code tag; An extraction unit, configured to extract a code snippet corresponding to the code tag in the Freemarker template file according to the tag type; A refactoring unit, configured to refactor the code snippet according to the code tag and the tag type to obtain a corresponding refactored code; A writing unit is used to write the reconstructed code corresponding to any of the code tags into a preset HTML file to obtain a target HTML file; wherein the target HTML file is used to generate the front end and / or back end in a front-end and back-end separation system, and the front-end and back-end separation system corresponds to the front-end and back-end integrated system.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the code file conversion method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the code file conversion method according to any one of claims 1 to 7.
