Java-based method and apparatus for dynamic mapping of database to API, device, and medium
By automatically generating database and API mapping solutions through Java reflection and Javassist bytecode technology, this approach solves the problems of high cost and low efficiency in traditional methods. It achieves efficient and flexible database and API integration, supports multiple database types, simplifies stored procedure calls, and promotes rapid enterprise iteration and digital transformation.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- SHANGHAI PARAVIEW SOFTWARE CO LTD
- Filing Date
- 2025-10-13
- Publication Date
- 2026-06-18
AI Technical Summary
Traditional systems suffer from high integration costs, low development efficiency, insufficient flexibility, and inability to effectively utilize stored procedures, leading to high costs and increased complexity for enterprises when integrating databases and APIs.
By using a Java-based dynamic mapping method, leveraging Java reflection and Javassist bytecode technology, database drivers, data source objects, and API interface controller classes are automatically generated, achieving automated mapping between the database and the API.
It significantly reduces coding requirements, improves development efficiency, supports multiple database types, enhances flexibility, simplifies stored procedure calls, enables rapid iteration and efficient integration, and drives enterprise digital transformation.
Smart Images

Figure CN2025127321_18062026_PF_FP_ABST
Abstract
Description
Java-based methods, devices, equipment, and media for dynamic mapping from databases to APIs.
[0001] This application claims priority to Chinese Patent Application No. 202411817166.2, filed with the Chinese Patent Office on December 11, 2024, the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of database technology, and in particular to a method, apparatus, device, and medium for dynamic mapping from Java-based databases to APIs. Background Technology
[0003] In modern applications, the interaction between databases and APIs is becoming increasingly important. Currently, many enterprises face the following technical challenges when integrating with databases:
[0004] 1. High cost of integrating with traditional systems: When integrating with legacy systems or third-party services, enterprises usually need to spend a lot of time and manpower to manually write interface code, which leads to a significant increase in development costs.
[0005] 2. Low development efficiency: The development methods in related technologies often require writing a large amount of similar code repeatedly, especially in the process of mapping from database to API. This not only consumes the time of developers, but also easily leads to human error and increases the difficulty of system maintenance.
[0006] 3. Insufficient flexibility: Solutions in related technologies often have a strong dependence on specific database types or API patterns, which means that when it is necessary to change the database or modify the API, redevelopment is required, which increases the complexity and cost of system maintenance.
[0007] 4. Insufficient support for stored procedures: Many enterprises already have a large number of stored procedures in their databases, but the relevant technologies often cannot effectively map these stored procedures to APIs, making it impossible for enterprises to make full use of existing resources. Summary of the Invention
[0008] This application provides a Java-based method, apparatus, device, and medium for dynamic mapping from database to API, thereby significantly improving the integration efficiency between database and API.
[0009] According to one aspect of this application, a Java-based dynamic database-to-API mapping method is provided, comprising:
[0010] Determine and store the database driver for the target database, and obtain the connection information for the target database;
[0011] Based on the database driver and the connection information, a data source object corresponding to the target database is created using Java reflection, and the data source object is registered to the connection pool.
[0012] Obtain the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object, and database operation;
[0013] Generate a controller class corresponding to the target API interface based on the interface information, and process the target API request based on the controller class.
[0014] In one possible implementation, the process of determining and storing the database driver for the target database includes:
[0015] Based on the user's actions in the front-end settings interface, the database driver uploaded by the user is determined and the database driver is persistently stored.
[0016] In one possible implementation, obtaining the connection information of the target database includes: obtaining the connection information of the target database based on the user's configuration operation in the front-end page, wherein the configuration operation includes: inputting the database connection information, the connection information including URL, username and password.
[0017] In one possible implementation, the connection pool includes data source objects corresponding to at least one type of database; the database is Oracle, SQL Server, MySQL, PostgreSQL, or DM database.
[0018] In one possible implementation, obtaining the interface information corresponding to the target API interface includes: obtaining the API request path, request method, target data source object, and database operation defined by the user on the front-end page corresponding to the target API interface; and determining the API request path, request method, data source object, and database operation as the interface information.
[0019] In one possible implementation, generating the controller class corresponding to the target API interface based on the interface information includes: dynamically generating the controller class corresponding to the target API interface using Javassist bytecode technology based on the interface information; and automatically registering the controller class to the application context using the Spring Framework.
[0020] In one possible implementation, processing the target API request based on the controller class includes: performing an operation on the target database according to the URL and HTTP interface corresponding to the target API request, and returning the result.
[0021] According to another aspect of this application, a Java-based dynamic database-to-API mapping apparatus is provided, comprising:
[0022] The database information determination module is configured to determine and store the database driver of the target database and obtain the connection information of the target database;
[0023] The data source object registration module is configured to create a data source object corresponding to the target database using Java reflection based on the database driver and the connection information, and register the data source object to the connection pool;
[0024] The interface information determination module is configured to obtain the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object, and database operation.
[0025] The target API request processing module is configured to generate a controller class corresponding to the target API interface based on the interface information, so as to process the target API request based on the controller class.
[0026] According to another aspect of this application, an electronic device is provided, the electronic device comprising:
[0027] At least one processor;
[0028] and a memory communicatively connected to the at least one processor; wherein,
[0029] The memory stores a computer program that can be executed by the at least one processor, which enables the at least one processor to perform the Java-based dynamic database-to-API mapping method described in any embodiment of this application.
[0030] According to another aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the Java-based dynamic database-to-API mapping method described in any embodiment of this application.
[0031] The technical solution of this application embodiment includes: determining and storing the database driver of the target database, and obtaining the connection information of the target database; based on the database driver and the connection information, creating a data source object corresponding to the target database using Java reflection mechanism, and registering the data source object to a connection pool; obtaining the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object, and database operation; generating a controller class corresponding to the target API interface according to the interface information, and processing the target API request based on the controller class. This solves the problems in related technologies, such as the need to write a large amount of code for dynamic mapping from Java databases to APIs, resulting in low development efficiency, insufficient flexibility, and ineffective utilization of existing stored procedures in the database. By automatically generating corresponding APIs, the coding requirements are significantly reduced, and development efficiency is improved. It supports multiple database types, allowing for rapid adaptation to different database environments and enhancing flexibility. It simplifies stored procedure calls, as the system automatically handles the mapping of stored procedures, reducing the complexity of using stored procedures. It enables rapid iteration and efficient integration; through dynamic API generation and registration, enterprises can quickly respond to business changes, achieving rapid iteration and efficient integration, and driving enterprise digital transformation.
[0032] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this application, nor is it intended to limit the scope of this application. Other features of this application will become readily apparent from the following description. Attached Figure Description
[0033] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0034] Figure 1 is a flowchart of a Java-based dynamic database to API mapping method provided in Embodiment 1 of this application;
[0035] Figure 2 is an architecture diagram of a Java-based dynamic database to API mapping system provided in Embodiment 2 of this application;
[0036] Figure 3 is a schematic diagram of a Java-based dynamic database to API mapping device provided according to Embodiment 3 of this application;
[0037] Figure 4 is a schematic diagram of the structure of the electronic device provided in Embodiment 4 of this application. Detailed Implementation
[0038] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0039] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0040] Example 1
[0041] Figure 1 is a flowchart of a Java-based dynamic database to API mapping method provided in Embodiment 1 of this application. This embodiment is applicable to situations that simplify the integration process between a database and an API. This method can be executed by a Java-based dynamic database to API mapping device / system. The device can be implemented in hardware and / or software and can be configured in a computer device. As shown in Figure 1, the method specifically includes the following steps:
[0042] S110. Determine and store the database driver of the target database, and obtain the connection information of the target database.
[0043] The target database can be the database that needs to be mapped to the API; the database driver can be the database driver of the target database; the connection information can be understood as the information required to connect to the target database, such as the URL of the target database, which may include, but is not limited to, the URL of the target database.
[0044] In one possible implementation, determining and storing the database driver of the target database includes: determining the database driver uploaded by the user based on the user's operation in the front-end settings interface, and persistently storing the database driver.
[0045] In this embodiment of the application, the Java-based dynamic database to API mapping device / system (hereinafter referred to as the mapping system) can provide a front-end page, on which various database driver names and corresponding database versions can be displayed.
[0046] Users can select the driver name and version through the front-end page. After confirmation, the database driver matching the driver name and version can be automatically uploaded to the mapping system's database, thus achieving persistent storage of the database driver.
[0047] In one possible implementation, obtaining the connection information of the target database includes: obtaining the connection information of the target database based on the user's configuration operation in the front-end page.
[0048] The configuration process includes inputting database connection information, which includes the URL, username, and password.
[0049] Specifically, the mapping system can provide a front-end page through which users can perform configuration operations. These operations may involve entering the target database's connection information on the front-end page, facilitating the establishment of a connection with the target database later. The connection information includes the target database's URL, and the username and password required to log in.
[0050] S120. Based on the database driver and the connection information, a data source object corresponding to the target database is created using Java reflection mechanism, and the data source object is registered to the connection pool.
[0051] Specifically, based on database drivers and connection information, the mapping system can dynamically create data source objects using Java reflection and register them in the connection pool. This allows the mapping system to flexibly switch between different data source environments as needed, enhancing scalability.
[0052] For example, when connecting to a SQL Server database, a user can enter the database connection information through a front-end page. The mapping system can then use this connection information to dynamically create a SQL Server data source and register it in the connection pool. Afterward, the user can interact with the SQL Server database through the data source.
[0053] In one possible implementation, the connection pool includes data source objects corresponding to at least one type of database; the database is Oracle, SQL Server, MySQL, PostgreSQL, or DM database.
[0054] It should be noted that different types of database data source objects can be registered in the connection pool, which allows for quick adaptation to different database environments and enhances flexibility.
[0055] S130. Obtain the interface information corresponding to the target API interface.
[0056] The target API interface can be a generated API interface, which allows access to the target database to perform corresponding database operations. Interface information includes the API request path, request method, data source object, and database operation.
[0057] In one possible implementation, obtaining the interface information corresponding to the target API interface may include: obtaining the API request path, request method, data source object, and database operation defined by the user on the front-end page corresponding to the target API interface; and determining the API request path, request method, target data source object, and database operation as the interface information.
[0058] The target data source object can be a user-defined data source object. Understandably, multiple data source objects are registered in the connection pool, and the user selects one to establish a connection between the database and the API.
[0059] Specifically, users can define API request paths and methods on the front-end page, and specify the corresponding database operations for these APIs, such as query, insert, and update.
[0060] S140. Generate a controller class corresponding to the target API interface based on the interface information, so as to process the target API request based on the controller class.
[0061] In one possible implementation, generating the controller class corresponding to the target API interface based on the interface information includes: dynamically generating the controller class corresponding to the target API interface using Javassist bytecode technology based on the interface information; and automatically registering the controller class to the application context using the Spring Framework.
[0062] Specifically, users define API request method paths and methods on the front-end page, specifying their corresponding database operations. The mapping system uses Javassist bytecode technology to dynamically generate controller classes based on user-defined information. These controller classes are automatically registered with the mapping system's context via the Spring Framework. This allows users to access data in the database through the defined API interface paths. In this way, the mapping system can quickly generate API interfaces based on user needs without manually writing large amounts of controller code.
[0063] For example, a user might want to create an API interface that can query user information. The API request method path (e.g., / users / {id}) can be defined on the front-end page, specifying that the database operation corresponding to this path is querying user information, and specifying the data source object. The mapping system dynamically generates a controller class based on this information. This class contains a method that handles GET requests, which can query user information from the database and return the results to the client—that is, processing the target API request.
[0064] In one possible implementation, processing the target API request based on the controller class may include: performing an operation on the target database according to the URL and HTTP interface corresponding to the target API request, and returning the result.
[0065] Specifically, when a request arrives, the mapping system performs the corresponding database operation based on the URL and HTTP method, and returns the result to the client.
[0066] For example, when a user sends a GET request to / users / {id} through a browser or client, the system will find the corresponding controller class and method based on the URL and HTTP method (GET), and execute the method to query user information. The query result will be encapsulated into a response object and returned to the client.
[0067] The technical solution of this application embodiment includes: determining and storing the database driver of the target database, and obtaining the connection information of the target database; based on the database driver and the connection information, creating a data source object corresponding to the target database using Java reflection mechanism, and registering the data source object to a connection pool; obtaining the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object, and database operation; generating a controller class corresponding to the target API interface according to the interface information, and processing the target API request based on the controller class. This solves the problems in related technologies, such as the need to write a large amount of code for dynamic mapping from Java databases to APIs, resulting in low development efficiency, insufficient flexibility, and ineffective utilization of existing stored procedures in the database. By automatically generating corresponding APIs, the coding requirements are significantly reduced, and development efficiency is improved. It supports multiple database types, allowing for rapid adaptation to different database environments and enhancing flexibility. It simplifies stored procedure calls, as the system automatically handles the mapping of stored procedures, reducing the complexity of using stored procedures. It enables rapid iteration and efficient integration; through dynamic API generation and registration, enterprises can quickly respond to business changes, achieving rapid iteration and efficient integration, and driving enterprise digital transformation.
[0068] Example 2
[0069] Figure 2 is an architecture diagram of a Java-based dynamic database-to-API mapping system provided in Embodiment 2 of this application. This embodiment is a preferred embodiment of the above embodiments, and its specific implementation can be found in the technical solution of this embodiment. Technical terms that are the same as or corresponding to those in the above embodiments will not be repeated here.
[0070] This application provides a Java-based dynamic database-to-API mapping system. By automating the process, this application aims to simplify the integration between databases and APIs, reduce the need for manual coding, and improve development efficiency. This application utilizes Java reflection's Javassist bytecode mechanism to automatically generate RESTful APIs. Developers only need to define the database model to automatically generate corresponding API interfaces, covering common operations such as GET, POST, PUT, and DELETE. Furthermore, this application supports multiple database types (such as Oracle, SQL Server, MySQL, PostgreSQL, and DM databases) and can effectively handle the mapping of (Oracle, SQL Server) stored procedures. This method can dynamically register data sources and APIs, helping enterprises quickly adapt to business changes and reduce system maintenance costs.
[0071] This application automates the dynamic mapping from database to API. Its core functionality utilizes Java reflection, annotations, and Javassist bytecode technology to simplify the integration process between the database and API, reduce the need for manual coding, and improve development efficiency.
[0072] The execution process of this method mapping system includes the following steps:
[0073] Dynamically defined database driver: Users select and upload a database driver on the front-end page, and the system persists the information of the database driver selected by the user for subsequent database operations.
[0074] Dynamically defined data sources: Users configure the required data source on the front-end page and input connection information (such as URL, username, password, etc.) and database driver. The system then uses Java reflection to dynamically create the data source object and register it in the connection pool. This process ensures the system can flexibly switch between different data source environments, enhancing scalability.
[0075] Dynamically define API interface paths: The user page defines the API request path and request method, and specifies the corresponding database operation. The system uses Javassist bytecode technology to dynamically generate controller classes based on the user-defined information (request path, request method, data source, database operation), and stores them in the system's runtime memory.
[0076] Register as an API interface: When an API interface is generated, it is automatically registered to the application context through the Spring Framework, enabling dynamic request routing. When a request arrives, the system executes the corresponding database based on the URL and HTTP interface.
[0077] This invention, through a Java-based dynamic database-to-API mapping method, significantly improves the integration efficiency between databases and APIs. Specific benefits include:
[0078] Developers only need to define the database model to automatically generate the corresponding RESTful API, significantly reducing coding requirements and improving development efficiency.
[0079] This method supports multiple database types (such as Oracle, SQL Server, MySQL, PostgreSQL, and DM Database) and can quickly adapt to different database environments, enhancing flexibility.
[0080] Simplify stored procedure calls; the system automatically handles stored procedure mappings, reducing the complexity of using stored procedures.
[0081] Rapid iteration and efficient integration: By dynamically generating APIs and registering, enterprises can quickly respond to business changes, achieve rapid iteration and efficient integration, and drive enterprise digital transformation.
[0082] Example 3
[0083] Figure 3 is a schematic diagram of a Java-based dynamic database-to-API mapping device provided in Embodiment 3 of this application. As shown in Figure 3, the device includes:
[0084] The database information determination module 310 is configured to determine and store the database driver information of the target database and obtain the connection information of the target database;
[0085] The data source object registration module 320 is configured to create a data source object corresponding to the target database using Java reflection mechanism based on the database driver and the connection information, and register the data source object to the connection pool;
[0086] The interface information determination module 330 is configured to obtain the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object and database operation;
[0087] The target API request processing module 340 is configured to generate a controller class corresponding to the target API interface based on the interface information, so as to process the target API request based on the controller class.
[0088] The technical solution of this application embodiment includes: determining and storing the database driver of the target database, and obtaining the connection information of the target database; based on the database driver and the connection information, creating a data source object corresponding to the target database using Java reflection mechanism, and registering the data source object to a connection pool; obtaining the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object, and database operation; generating a controller class corresponding to the target API interface according to the interface information, and processing the target API request based on the controller class. This solves the problems in related technologies, such as the need to write a large amount of code for dynamic mapping from Java databases to APIs, resulting in low development efficiency, insufficient flexibility, and ineffective utilization of existing stored procedures in the database. By automatically generating corresponding APIs, the coding requirements are significantly reduced, and development efficiency is improved. It supports multiple database types, allowing for rapid adaptation to different database environments and enhancing flexibility. It simplifies stored procedure calls, as the system automatically handles the mapping of stored procedures, reducing the complexity of using stored procedures. It enables rapid iteration and efficient integration; through dynamic API generation and registration, enterprises can quickly respond to business changes, achieving rapid iteration and efficient integration, and driving enterprise digital transformation.
[0089] Based on the above technical solution, the database information determination module 310 includes:
[0090] The database driver upload submodule is configured to determine the database driver uploaded by the user based on the user's operation in the front-end settings interface, and persistently store the database driver.
[0091] Based on the above technical solution, the database information determination module 310 includes:
[0092] The connection information acquisition submodule is configured to acquire the connection information of the target database based on the user's configuration operation on the front-end page. The configuration operation includes: inputting the database connection information, which includes the URL, username, and password.
[0093] Based on the above technical solution, the connection pool includes data source objects corresponding to at least one type of database;
[0094] The database is Oracle, SQL Server, MySQL, PostgreSQL, or DM database.
[0095] Based on the above technical solution, the interface information determination module 330 is configured as follows:
[0096] Obtain the API request path, request method, target data source object, and database operation defined by the user on the front-end page corresponding to the target API interface;
[0097] The API request path, request method, data source object, and database operation are determined as the interface information.
[0098] Based on the above technical solution, the target API request processing module 340 includes:
[0099] The controller class generation submodule is configured to dynamically generate the controller class corresponding to the target API interface based on the interface information using Javassist bytecode technology.
[0100] The controller class is automatically registered to the application context via the Spring Framework.
[0101] Based on the above technical solution, the target API request processing module 340 includes:
[0102] The request processing submodule is configured to perform operations on the target database based on the URL and HTTP interface corresponding to the target API request, and return the results.
[0103] The Java-based dynamic database to API mapping device provided in this application embodiment can execute the Java-based dynamic database to API mapping method provided in any embodiment of this application, and has the corresponding functional modules and beneficial effects of the execution method.
[0104] Example 4
[0105] Figure 4 is a schematic diagram of the structure of the electronic device provided in Embodiment 4 of this application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.
[0106] As shown in Figure 4, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded into the RAM 13 from storage unit 18. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0107] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0108] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as Java-based dynamic database-to-API mapping methods.
[0109] In some embodiments, the Java-based dynamic database to API mapping may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or mounted on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the Java-based dynamic database to API mapping described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform Java-based dynamic database to API mapping by any other suitable means (e.g., by means of firmware).
[0110] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0111] Computer programs used to implement the methods of this application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0112] In the context of this application, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0113] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0114] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0115] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0116] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this application can be achieved, and this is not limited herein.
Claims
1. A Java-based method for mapping dynamic databases to APIs, comprising: Determine and store the database driver for the target database, and obtain the connection information for the target database; Based on the database driver and the connection information, a data source object corresponding to the target database is created using Java reflection, and the data source object is registered to the connection pool. Obtain the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object, and database operation; Generate a controller class corresponding to the target API interface based on the interface information, and process the target API request based on the controller class.
2. The method according to claim 1, wherein, The database driver for determining and storing the target database includes: Based on the user's actions in the front-end settings interface, the database driver uploaded by the user is determined and the database driver is persistently stored.
3. The method according to claim 2, wherein, The step of obtaining the connection information of the target database includes: Based on the user's configuration operation on the front-end page, the connection information of the target database is obtained. The configuration operation includes: inputting the database connection information, which includes the URL, username, and password.
4. The method according to claim 1, wherein, The connection pool includes data source objects corresponding to at least one type of database; The database is Oracle, SQL Server, MySQL, PostgreSQL, or DM database.
5. The method according to claim 1, wherein, The step of obtaining the interface information corresponding to the target API interface includes: Obtain the API request path, request method, target data source object, and database operation defined by the user on the front-end page corresponding to the target API interface; The API request path, request method, data source object, and database operation are determined as the interface information.
6. The method according to claim 1, wherein, The step of generating the controller class corresponding to the target API interface based on the interface information includes: Based on the interface information, the controller class corresponding to the target API interface is dynamically generated using Javassist bytecode technology. The controller class is automatically registered to the application context via the Spring Framework.
7. The method according to claim 1, wherein, The process of handling the target API request based on the controller class includes: Based on the URL and HTTP interface corresponding to the target API request, perform operations on the target database and return the results.
8. A Java-based dynamic database-to-API mapping device, comprising: The database information determination module is configured to determine and store the database driver of the target database and obtain the connection information of the target database; The data source object registration module is configured to create a data source object corresponding to the target database using Java reflection based on the database driver and the connection information, and register the data source object to the connection pool; The interface information determination module is configured to obtain the interface information corresponding to the target API interface, wherein the interface information includes the API request path, request method, data source object, and database operation. The target API request processing module is configured to generate a controller class corresponding to the target API interface based on the interface information, so as to process the target API request based on the controller class.
9. An electronic device, comprising: At least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the Java-based dynamic database to API mapping method according to any one of claims 1-7.
10. A computer-readable storage medium storing computer instructions for causing a processor to execute and implement the Java-based dynamic database-to-API mapping method according to any one of claims 1-7.