Method for generating api interface based on dynamic sql configuration
The method of generating API interfaces through dynamic SQL configuration and using a visual system to automatically generate API interfaces solves the problem of lengthy traditional development processes, achieves rapid response and efficient system development, and reduces development and maintenance costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- LINEWELL SOFTWARE
- Filing Date
- 2022-08-24
- Publication Date
- 2026-04-17
AI Technical Summary
Traditional API development processes are lengthy, impacting response speed and development costs, and making it difficult to quickly respond to changes in requirements.
A visual interface configuration system based on dynamic SQL configuration is adopted. SQL statements and parameters are written through a visual interface, and API interfaces are automatically generated. It supports multiple protocols and security checks, reduces coding workload, and improves iteration efficiency.
Significantly reduce development and maintenance costs, improve system development efficiency, support rapid requirement changes and security verification, and reduce the risk of system security vulnerabilities.
Smart Images

Figure CN115309387B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method for generating API interfaces based on dynamic SQL configuration. Background Technology
[0002] In software system development, API service interface development is one of the most common tasks. Data interaction between the front-end and back-end, as well as data transmission between various microservice modules, all rely on communication and data exchange between API interfaces; therefore, the efficiency of API data interface development can significantly impact the development and delivery efficiency of the software system.
[0003] In traditional business system development, the completion of an API interface often requires a lengthy software development process, such as requirement design, review, coding, testing, deployment, and release. Especially in the later optimization and iteration stages, unlike the concentrated development of a large number of requirements in the early stages, it is a process of increasing program iteration. If each API interface requirement has to wait for a lengthy development process, this will affect the requirement response speed and increase development cost efficiency. Summary of the Invention
[0004] To address the shortcomings and deficiencies of existing technologies, this invention proposes a method for generating API interfaces based on dynamic SQL configuration. This method aims to quickly generate API interfaces and methods from SQL statements in common scenarios, thereby meeting the requirements of low-code or zero-code development and improving system development efficiency to some extent.
[0005] Based on the provided interface configuration system, it offers a visual interface configuration function. It can be used to automatically provide service interfaces to the outside world based on existing SQL statements for different scenarios. Developers or operations personnel can directly generate corresponding API service interfaces through the visual interface by writing SQL statements and configuring related parameters, which can then be called by the front-end system or used to provide data services externally. This eliminates the need for a series of lengthy processes such as submitting interface development requirements to back-end developers, communicating business logic, scheduling development, writing code, packaging, deployment, and release. Furthermore, it allows for timely modification of existing SQL logic and configuration items in response to changes in requirements, achieving rapid response to changes in requirements and significantly reducing system development and maintenance costs to a certain extent.
[0006] To achieve the above objectives, the present invention specifically adopts the following technical solution:
[0007] A method for generating API interfaces based on dynamic SQL configuration, characterized by an interface configuration system with visual interface configuration functionality, comprising the following steps:
[0008] Step S1: Through the visual interface configuration page, write information including: SQL query statement, interface parameters, configuration interface address, calling protocol, calling method, and return result method, and submit it to the configuration system backend for review;
[0009] Step S2: After the review is completed, the interface configuration system parses the SQL statement and configuration parameters through the configured information, automatically generates an executable program class method based on JDK dynamic proxy, and generates the corresponding API interface service for the front-end or downstream system to call according to different protocol requirements.
[0010] Step S3: Receive the call request from the caller, parse the interface address and call parameters, and call the relevant business method; at the same time, perform legality and security checks on the call parameters to avoid system security vulnerabilities;
[0011] Step S4: Construct the corresponding SQL and SQL parameters according to the configuration information and business requirements, and execute the corresponding SQL statement through the executor to obtain the result;
[0012] Step S5: Package the SQL execution interface result object according to the configuration requirements and return it to the interface caller.
[0013] Furthermore, in step S2, the method for generating the executable program class specifically involves parsing the SQL statement and configuration information, and using the engineering mode to construct the executable method of the Mapper.
[0014] Furthermore, the interface configuration system presets a mapper template and automatically generates executable Java class methods using pre-written SQL statements and configuration information; it then uses the JDK dynamic proxy in the Java backend to bind the generated class methods to the interface controller.
[0015] Furthermore, in step S3, the security verification of the written parameters specifically involves: checking for potential SQL injection and sensitive data words in the SQL statement, and performing a secondary verification on the concatenated executable SQL statement; for request interfaces that fail verification, an error is automatically returned and a call failure message is sent to the caller.
[0016] Furthermore, in step S3, the generated API interface provides support for multiple protocol calls such as REST and RPC, and supports GET and POST call configurations; the generated API interface supports dynamic request parameters, dynamically generates SQL statements based on the input parameters, passes the concatenated SQL to the database executor for execution and returns the results.
[0017] Furthermore, in steps S4 and S5, based on the template method pattern, the interface return information is automatically classified and processed, including pagination, fragmentation, caching, and static data switching of the return results.
[0018] And an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, when the processor executes the program, it implements the steps of the method for generating API interfaces based on dynamic SQL configuration as described above.
[0019] And, a non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, when the computer program is executed by a processor, it implements the steps of the working method of the method for generating API interfaces based on dynamic SQL configuration as described above.
[0020] Compared with the prior art, the beneficial effects of the present invention and its preferred embodiments mainly include:
[0021] 1) Automatically generating data interfaces based on SQL can greatly reduce the amount of coding work in the development process, improve the efficiency of function iteration, reduce repetitive and simple code, allow developers to focus more on the development of complex business logic, and save human resources costs.
[0022] 2) It can simultaneously support the maintenance of functional code for both developers and implementers, reducing the maintenance threshold. Attached Figure Description
[0023] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments:
[0024] Figure 1 This is a schematic diagram of the method flow steps in an embodiment of the present invention. Detailed Implementation
[0025] To make the features and advantages of this patent more apparent and understandable, specific embodiments are provided below, along with accompanying drawings, for detailed explanation:
[0026] like Figure 1 As shown, the method for generating API interfaces based on dynamic SQL configuration provided in this embodiment offers an interface configuration system and provides visual interface configuration functionality; it is implemented according to the following steps:
[0027] Step S1: Developers or operations personnel use the visual interface configuration page to write SQL query statements, interface parameters, configuration interface address, calling protocol, calling method, return result method, and other information, and submit them to the configuration system backend for review.
[0028] Step S2: After the review is completed, the interface configuration system parses the SQL statement and configuration parameters through the configured information, automatically generates an executable program class method based on JDK dynamic proxy, and generates the corresponding API interface service for the front-end or downstream system to call according to different protocol requirements.
[0029] Step S3: Receive the call request from the caller, parse the interface address and call parameters, and call the relevant business methods; at the same time, perform compliance and security checks on the call parameters to avoid system security vulnerabilities;
[0030] Step S4: Construct the corresponding SQL and SQL parameters according to the configuration information and business requirements, and execute the corresponding SQL statement through the executor to obtain the result;
[0031] Step S5: Package the SQL execution interface result object according to the configuration requirements and return it to the interface caller.
[0032] In step S2 of this embodiment, the generated executable program class method parses the SQL statement and configuration information, and uses the engineering mode to construct the executable method of the Mapper.
[0033] In step S3 of this embodiment, the security verification of the written parameters mainly involves checking for potential SQL injection, sensitive data words, etc., and performing secondary verification on the concatenated executable SQL statement. For request interfaces that fail verification, an error will be automatically returned and a call failure message will be sent to the caller.
[0034] In steps S4 and S5 of this embodiment, the automatic classification and processing of interface return information is realized based on the template method pattern, including pagination, fragmentation, caching, and static data switching of the return results.
[0035] The design points of this embodiment also include:
[0036] 1. Provides a visual user configuration management system, allowing developers, real-time personnel, and R&D administrators to flexibly write SQL statements and parameter configurations based on interface requirements, and perform unified interface configuration, review, and release tasks;
[0037] 2. Drawing inspiration from the Mapper constructor in MyBatis, a pre-defined mapper template is used to automatically generate executable Java class methods based on pre-written SQL statements and configuration information. The generated class methods are then bound to the interface controller using JDK dynamic proxies in the Java backend.
[0038] 3. The generated API interface supports multiple protocol calls including REST and RPC, and also supports GET and POST call configuration.
[0039] 4. Returns data results in a general JSON data structure, and allows configuration of case mapping for data keys; for interfaces returning large lists of data, it supports processing and returning data results by pagination, sharding, truncation, sorting, etc.
[0040] 5. The generated API interface supports dynamic request parameters, and can dynamically generate SQL statements based on the input parameters. The concatenated SQL is then passed to the database executor for execution and returns the results.
[0041] 6. High-frequency interfaces can be cached, and the cache validity period can be configured to improve the concurrent access efficiency of the interfaces and reduce the pressure on the database;
[0042] 7. Developers and implementers can update and release interface configurations at any time, supporting version management of data interfaces and the parallel use of multiple version interfaces.
[0043] The above-mentioned solutions provided in this embodiment can be stored in a computer-readable storage medium in the form of code, implemented in the form of a computer program, and the basic parameter information required for calculation can be input through computer hardware, and the calculation results can be output.
[0044] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0045] This invention is described with reference to flowchart illustrations of methods, apparatus (devices), and computer program products according to embodiments of the invention. It will be understood that each step in the flowchart, and combinations of steps in the flowchart, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing device, generate instructions for implementing the steps in the flowchart. Figure 1 A device for a function specified in one or more processes.
[0046] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 A function specified in one or more flowcharts.
[0047] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 Steps of a specified function in one or more processes.
[0048] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the protection scope of the claims of the present invention.
[0049] This patent is not limited to the above-described preferred embodiments. Anyone can derive other methods for generating API interfaces based on dynamic SQL configuration under the guidance of this patent. All equivalent changes and modifications made within the scope of this patent application shall fall within the scope of this patent.
Claims
1. A method for generating an API interface based on dynamic SQL configuration, characterized in that, An interface configuration system with visual interface configuration capabilities includes the following steps: Step S1: Through the visual interface configuration page, write information including: SQL query statement, interface parameters, configuration interface address, calling protocol, calling method, and return result method, and submit it to the configuration system backend for review; Step S2: After the review is completed, the interface configuration system parses the SQL statement and configuration parameters using the configured information, and automatically generates an executable program class method based on JDK dynamic proxy. It then generates API interface services with corresponding access paths for frontend or downstream systems to call, according to different protocol requirements. The interface configuration system presets a mapper template and automatically generates executable Java class methods using the written SQL statement and configuration information. Using the JDK dynamic proxy in the Java backend, the generated class methods are bound to the interface controller. Step S3: Receive the call request from the caller, parse the interface address and call parameters, and call the relevant business method; at the same time, perform legality and security checks on the call parameters to avoid system security vulnerabilities; the security check of the written parameters specifically includes: checking for potential SQL injection and sensitive data words in the SQL statement, and performing secondary checks on the concatenated executable SQL statement; for request interfaces that fail the checks, automatically return an error and return a call failure message to the caller; Step S4: Construct the corresponding SQL and SQL parameters according to the configuration information and business requirements, and execute the corresponding SQL statement through the executor to obtain the result; Step S5: Package the SQL execution interface result object according to the configuration requirements and return it to the interface caller; based on the template method pattern, automatically classify and process the interface return information, including pagination, fragmentation, caching, and static data switching of the return results.
2. The method for generating API interfaces based on dynamic SQL configuration according to claim 1, characterized in that: In step S2, the method for generating the executable program class specifically involves parsing the SQL statement and configuration information, and using the engineering mode to construct the executable method of the Mapper.
3. The method for generating API interfaces based on dynamic SQL configuration according to claim 1, characterized in that: In step S3, the generated API interface provides support for multiple protocol calls including REST and RPC, and supports GET and POST call configuration. The generated API interface supports dynamic request parameters, dynamically generates SQL statements based on the input parameters, passes the concatenated SQL to the database executor for execution, and returns the results.
Citation Information
Patent Citations
Java system application programming interface calling method and system using the same
CN103164270A
Business development method and device based on configuration SQL, equipment and medium
CN111857672A