Template-based Spring application secondary development method and device

By adopting template editing and JVM loader positioning methods in the Spring framework, dynamic code modification and execution are realized, solving the problems of slow response speed and high maintenance costs in traditional development methods, and improving the flexibility and security of the system. Have online deployment capabilities.

CN119065642APending Publication Date: 2024-12-03GANSUHAOBAI INFORMATION SERVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411045326.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-12-03

AI Technical Summary

Technical Problem

Under the Spring framework, the traditional Model-View-Controller model causes business adjustment code to be compiled and released as a whole, with slow response speed, long release cycle, insufficient flexibility, high maintenance cost, and sporadic code adjustment requires developers to intervene, resulting in a response cycle long.

Method used

Using the template-based Spring application secondary development method, the template code is edited on the slot by building a text editor, the source code location is used to locate the JVM loader, and the updated Bean bytecode is generated, and the output is in JSON format is supported, dynamic code is supported Modify and execute, realize online release and secondary development.

Benefits of technology

It significantly improves the scalability and flexibility of the system, reduces maintenance difficulty and maintenance costs, supports dynamic data checks and secure processing, and has the capabilities of secondary development and online deployment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119065642A_ABST
    Figure CN119065642A_ABST
Patent Text Reader

Abstract

The invention provides a Spring application secondary development method and device based on a template, and relates to the technical field of software development, and the method comprises the steps: constructing a text editor, editing a template code of a Spring framework on a defined slot according to annotation and annotation modes, updating the template code to a database, and binding the template code with the slot; obtaining a memory object of the JVM by using a JVM loader so as to position the position of the source code according to the slot position; loading the source code of the controller on demand according to the position of the source code; the controller inputs data in the client according to the updated code for conversion and verification, and generates an updated Bean byte code; generating a JSON object in a JSON format of the template according to the updated Bean byte code; according to the method, the flexibility and the safety of application development are remarkably improved, the maintenance difficulty and the maintenance cost are reduced, and the secondary development and online deployment capabilities are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a template-based Spring application secondary development method and device. Background Art

[0002] The front-end and back-end development under the Spring framework generally adopts the classic Model-View-Controller mode, which has great advantages in scalability, ease of use and maintainability. Its development using conventional JAVA code requires overall compilation for deployment. For the code that has business adjustments after going online, it is compiled and released. When general functional adjustments are made during user use, problems such as slow response speed, long release cycle, and lack of flexibility will occur. In addition, sporadic code adjustments also require the intervention of developers, which often result in problems such as long response cycle and high maintenance cost. Summary of the invention

[0003] The purpose of the present invention is to provide a template-based Spring application secondary development method and device, which can realize secondary development of code in a template definition manner, significantly improving the scalability and flexibility of the system.

[0004] The technical solution of the present invention is:

[0005] In a first aspect, the present application provides a template-based Spring application secondary development method, which comprises the following steps:

[0006] S1. Build a text editor to edit the template code of the Spring framework in the definition slot in the form of annotations and comments, update it to the database, and bind it to the slot;

[0007] S2. After the code editing is completed, the JVM loader is used to obtain the JVM's memory object to locate the source code location by slot;

[0008] S3, loading the source code of the controller on demand according to the source code location;

[0009] S4. The controller converts and verifies the data input in the client according to the updated code and generates updated Bean bytecode;

[0010] S5. The controller generates a JSON object in the JSON format of the template according to the updated Bean bytecode.

[0011] Furthermore, step S1 further includes:

[0012] Maintain the template code of the slot with the prompt of the template; the maintenance methods include variable acquisition, type conversion, data verification and formatting data.

[0013] Further, step S3 includes:

[0014] Determine whether the current slot code loading is valid. If so, load the source code of the controller class on demand according to the source code location. If not, modify the JVM program bytes at runtime and use the spring framework to replace the corresponding Bean object with the updated bytecode.

[0015] Furthermore, the step of modifying the JVM program bytes at runtime includes:

[0016] Mark the current slot source code needs to be loaded;

[0017] Obtain and edit the appropriate template source code, use slots and reflection technology to locate the function, convert the template source code into standard JAVA source code, and adapt it to specific functions and code segments;

[0018] Use javaassist to load the JAVA source code and locate the specific functions and code segments. At the same time, convert the serialized bytecode to the JVM memory and update the memory bytecode of the corresponding class.

[0019] Further, step S5 includes:

[0020] The controller brings the updated Bean bytecode into the template code, parses the key-value pairs and expressions according to the hierarchy, and generates a hierarchical JSON object;

[0021] After desensitizing the relevant data of the hierarchical JSON object, a regular JSON object is output.

[0022] In a second aspect, the present application provides a template-based Spring application secondary development device, comprising:

[0023] The code editing module is used to build a text editor to edit the template code of the Spring framework in the definition slot in the form of annotations and comments, and update it to the database and bind it to the slot;

[0024] A code acquisition module is used to use a JVM loader to acquire a JVM memory object to locate the source code position by slot after the code editing is completed;

[0025] A code loading module is used to load the source code of the controller on demand according to the source code location;

[0026] Templated input module, used by the controller to convert and validate the input data in the client according to the updated code, and generate updated Bean bytecode;

[0027] The templated output module is used by the controller to generate JSON objects in the template's JSON format according to the updated Bean bytecode.

[0028] In a third aspect, the present application provides an electronic device, including:

[0029] A memory for storing one or more programs;

[0030] processor;

[0031] When the one or more programs are executed by the processor, a template-based Spring application secondary development method as described in any one of the first aspects is implemented.

[0032] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a template-based Spring application secondary development method as described in any one of the first aspects above.

[0033] Compared with the prior art, the present invention has at least the following advantages or beneficial effects:

[0034] The present invention provides a template-based Spring application secondary development method and device, which completes code editing and generates Java bytecode on the template by using the Javaassist tool library, uses tags and slot positioning to realize dynamic code modification and execution on the JVM, supports online publishing, and forms secondary development capabilities. Compared with the traditional development method, the method and device have code adaptability maintenance capabilities, better adapt to input format verification and output format definition, enhance system scalability, support dynamic data verification and security response processing capabilities, significantly improve the flexibility and security of application development, reduce maintenance difficulty and maintenance costs, and have the capabilities of secondary development and online deployment. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0036] Figure 1 A step diagram of a template-based Spring application secondary development method of the present invention;

[0037] Figure 2 The figure is a schematic structural block diagram of an electronic device according to an embodiment of the present invention.

[0038] Icon: 101, memory; 102, processor; 103, communication interface. DETAILED DESCRIPTION

[0039] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.

[0040] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0041] It should be noted that, in this article, the term "comprises" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprises..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0042] In conjunction with the accompanying drawings, some implementation methods of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.

[0043] Example 1

[0044] See also Figure 1 , Figure 1 The figure shows a step diagram of a template-based Spring application secondary development method provided in an embodiment of the present application.

[0045] In a first aspect, the present application provides a template-based Spring application secondary development method, which comprises the following steps:

[0046] S1. Build a text editor to edit the template code of the Spring framework in the definition slot in the form of annotations and comments, update it to the database, and bind it to the slot;

[0047] S2. After the code editing is completed, the JVM loader is used to obtain the JVM's memory object to locate the source code location by slot;

[0048] S3, loading the source code of the controller on demand according to the source code location;

[0049] S4. The controller converts and verifies the data input in the client according to the updated code and generates updated Bean bytecode;

[0050] S5. The controller generates a JSON object in the JSON format of the template according to the updated Bean bytecode.

[0051] As a preferred implementation, step S1 further includes:

[0052] Maintain the template code of the slot with the prompt of the template; the maintenance methods include variable acquisition, type conversion, data verification and formatting data.

[0053] As a preferred implementation, step S3 includes:

[0054] Determine whether the current slot code loading is valid. If so, load the source code of the controller class on demand according to the source code location. If not, modify the JVM program bytes at runtime and use the spring framework to replace the corresponding Bean object with the updated bytecode.

[0055] As a preferred implementation, the step of modifying the JVM program bytes at runtime includes:

[0056] Mark the current slot source code needs to be loaded;

[0057] Obtain and edit the appropriate template source code, use slots and reflection technology to locate the function, convert the template source code into standard JAVA source code, and adapt it to specific functions and code segments;

[0058] Use javaassist to load the JAVA source code and locate the specific functions and code segments. At the same time, convert the serialized bytecode to the JVM memory and update the memory bytecode of the corresponding class.

[0059] It should be noted that when the Spring framework is initialized or receives a code update notification, the code update processing logic is started. The template-based secondary maintenance code is first loaded from the data, converted into JAVA source code, and the bytecode is updated to the JVM memory according to the slot location through javaassist, and loaded into the Bean through the Spring framework.

[0060] As a preferred implementation, step S5 includes:

[0061] The controller brings the updated Bean bytecode into the template code, parses the key-value pairs and expressions according to the hierarchy, and generates a hierarchical JSON object;

[0062] After desensitizing the relevant data of the hierarchical JSON object, a regular JSON object is output.

[0063] Example 2

[0064] In a second aspect, the present application provides a template-based Spring application secondary development device, comprising:

[0065] The code editing module is used to build a text editor to edit the template code of the Spring framework in the definition slot in the form of annotations and comments, and update it to the database and bind it to the slot;

[0066] A code acquisition module is used to use a JVM loader to acquire a JVM memory object to locate the source code position by slot after the code editing is completed;

[0067] A code loading module is used to load the source code of the controller on demand according to the source code location;

[0068] Templated input module, used by the controller to convert and validate the input data in the client according to the updated code, and generate updated Bean bytecode;

[0069] The templated output module is used by the controller to generate JSON objects in the template's JSON format according to the updated Bean bytecode.

[0070] The invention provides a template-based Spring application secondary development device, which provides a text editor through a code editing module, edits and loads the code with the help of source code annotations and slot modes of comment tags, and maintains the code by means of variable acquisition, type conversion, data verification, data formatting, etc. through template prompts; then, after the code editing is completed, the JVM loader is used to acquire the memory object of the JVM to locate the source code position according to the slot; then, the source code of the controller is loaded on demand according to the source code position through the code loading module, and the JVM running bytecode is loaded into the JVM memory, and the Bean object in the Spring framework is updated at the same time; then, a template input module is used to define according to simple objects and fixed-named generic column types, and dynamic type conversion is performed by formulating data types, data type verification is realized by plug-in mode, and basic data and object value acquisition is designed according to attribute acquisition mode, and updated Bean bytecode is generated; finally, a template output module is used to dynamically match expressions and domain objects according to the general attributes of JSON object Key and Value and hierarchical output format, and a virtual object processing mode is adopted to realize hierarchical generation of JSON objects.

[0071] Example 3

[0072] See also Figure 2 , Figure 2 A schematic structural block diagram of an electronic device provided in an embodiment of the present application.

[0073] An electronic device includes a memory 101, a processor 102 and a communication interface 103, wherein the memory 101, the processor 102 and the communication interface 103 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. The memory 101 can be used to store software programs and modules, and the processor 102 executes various functional applications and data processing by executing the software programs and modules stored in the memory 101. The communication interface 103 can be used to communicate signaling or data with other node devices.

[0074] Among them, the memory 101 can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), etc.

[0075] The processor 102 may be an integrated circuit chip with signal processing capability. The processor 102 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0076] It is understood that the structure shown in the figure is only for illustration, and a template-based Spring application secondary development method and device may also include more or fewer components than shown in the figure, or have a different configuration than shown in the figure. Each component shown in the figure can be implemented by hardware, software or a combination thereof.

[0077] In the embodiments provided in the present application, it should be understood that the disclosed method can also be implemented in other ways. The embodiments described above are merely schematic, for example, the flowchart or block diagram in the accompanying drawings shows the possible implementation architecture, functions and operations of the method and computer program product according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0078] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0079] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0080] To summarize, the embodiments of the present application provide a template-based Spring application secondary development method and device, which completes code editing and generates Java bytecode on the template by utilizing the Javaassist tool library, and uses tags and slot positioning to implement dynamic code modification and execution on the JVM, which is better adapted to input format verification and output format definition, enhances system scalability, supports dynamic data verification and security response processing capabilities, significantly improves the flexibility and security of application development, reduces maintenance difficulty and maintenance costs, and has the ability of secondary development and online deployment.

[0081] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

[0082] It will be apparent to those skilled in the art that the present application is not limited to the details of the exemplary embodiments described above, and that the present application can be implemented in other specific forms without departing from the spirit or essential features of the present application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the present application is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims be included in the present application. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.

Claims

1. A template-based Spring application secondary development method, characterized in that: The following steps are involved: S1. Build a text editor to edit the template code of the Spring framework in the definition slot in the form of annotations and comments, update it to the database, and bind it to the slot; S2. After the code editing is completed, the JVM loader is used to obtain the JVM's memory object to locate the source code location by slot; S3, loading the source code of the controller on demand according to the source code location; S4. The controller converts and verifies the data input in the client according to the updated code and generates updated Bean bytecode; S5. The controller generates a JSON object in the JSON format of the template according to the updated Bean bytecode.

2. A template-based Spring application secondary development method as claimed in claim 1, characterized in that: Step S1 also includes: Maintain the template code of the slot with the prompt of the template; the maintenance methods include variable acquisition, type conversion, data verification and formatting data.

3. A template-based Spring application secondary development method as claimed in claim 1, characterized in that: Step S3 includes: Determine whether the current slot code loading is valid. If so, load the source code of the controller class on demand according to the source code location. If not, modify the JVM program bytes at runtime and use the spring framework to replace the corresponding Bean object with the updated bytecode.

4. A template-based Spring application secondary development method as claimed in claim 3, characterized in that: The step of modifying the JVM program bytes at runtime includes: Mark the current slot source code needs to be loaded; Obtain and edit the appropriate template source code, use slots and reflection technology to locate the function, convert the template source code into standard JAVA source code, and adapt it to specific functions and code segments; Use javaassist to load the JAVA source code and locate the specific functions and code segments. At the same time, convert the serialized bytecode to the JVM memory and update the memory bytecode of the corresponding class.

5. A template-based Spring application secondary development method as claimed in claim 1, characterized in that: Step S5 includes: The controller brings the updated Bean bytecode into the template code, parses the key-value pairs and expressions according to the hierarchy, and generates a hierarchical JSON object; After desensitizing the relevant data of the hierarchical JSON object, a regular JSON object is output.

6. A template-based Spring application secondary development device as claimed in claim 1, characterized in that: include: The code editing module is used to build a text editor to edit the template code of the Spring framework in the definition slot in the form of annotations and comments, and update it to the database and bind it to the slot; A code acquisition module is used to use a JVM loader to acquire a JVM memory object to locate the source code position by slot after the code editing is completed; A code loading module is used to load the source code of the controller on demand according to the source code location; Templated input module, used by the controller to convert and validate the input data in the client according to the updated code, and generate updated Bean bytecode; The templated output module is used by the controller to generate JSON objects in the template's JSON format according to the updated Bean bytecode.

7. An electronic device, characterized in that: include: A memory for storing one or more programs; processor; When the one or more programs are executed by the processor, a template-based Spring application secondary development method as described in any one of claims 1 to 5 is implemented.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, a template-based Spring application secondary development method as described in any one of claims 1 to 5 is implemented.