CN115480813A - API (application program interface) generating method and device, electronic equipment and storage medium - Google Patents

API (application program interface) generating method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN115480813A
CN115480813A CN202211032904.3A CN202211032904A CN115480813A CN 115480813 A CN115480813 A CN 115480813A CN 202211032904 A CN202211032904 A CN 202211032904A CN 115480813 A CN115480813 A CN 115480813A
Authority
CN
China
Prior art keywords
data source
identity
preset
source connection
primary key
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211032904.3A
Other languages
Chinese (zh)
Inventor
李臻阳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Changan Automobile Co Ltd
Original Assignee
Chongqing Changan Automobile Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chongqing Changan Automobile Co Ltd filed Critical Chongqing Changan Automobile Co Ltd
Priority to CN202211032904.3A priority Critical patent/CN115480813A/en
Publication of CN115480813A publication Critical patent/CN115480813A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/602Providing cryptographic facilities or services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/62Protecting access to data via a platform, e.g. using keys or access control rules
    • G06F21/6218Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Hardware Design (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a method, a device, an electronic device and a storage medium for generating an API, comprising: acquiring an identity of a data source to be used, which is transmitted by a user; acquiring a data source connection pool corresponding to a data source identity to be used from a key value cached in a preset memory according to the data source identity to be used, reading a data source corresponding to the data source to be used from the data source connection pool, filling the data source identity to be used and a data source corresponding to the data source identity to be used into a preset code template character string, and generating a target code template character string; compiling the target code template character string into a target memory, performing bean registration and mapping registration, and generating a target application programming interface API. The problems that in the related art, the configuration of a web system is complex, configuration files need to be modified and the application needs to be restarted, a large amount of repeated work occurs and the like are solved, the management and the use of multiple data sources are realized, and the development efficiency of developers is improved.

Description

API (application program interface) generating method and device, electronic equipment and storage medium
Technical Field
The present Application relates to the field of computer software development technologies, and in particular, to a method and an apparatus for generating an API (Application programming Interface), an electronic device, and a storage medium.
Background
With the development of computer software technology, scenes using multiple data sources in web applications are more and more, and particularly for a web system providing data services, an API needs to be rapidly generated by using different data sources to provide services for the outside, and switching between multiple data sources is often performed.
However, in the related art, it is complex to configure the web system, and it is necessary to modify the configuration file and restart the application, and a lot of repetitive work occurs, which needs to be solved urgently.
Disclosure of Invention
The application provides a method, a device, an electronic device and a storage medium for generating an API (application programming interface), so as to solve the problems that a web system is configured more complicatedly, a configuration file needs to be modified and an application needs to be restarted, a large amount of repeated work occurs and the like in the related art.
An embodiment of a first aspect of the present application provides a method for generating an API, including the following steps: acquiring an identity of a data source to be used, which is transmitted by a user; acquiring a data source connection pool corresponding to the to-be-used data source identity from a key value cached in a preset memory according to the to-be-used data source identity, reading a data source corresponding to the to-be-used data source identity from the data source connection pool, filling the to-be-used data source identity and a data source corresponding to the to-be-used data source identity into a preset code template character string, and generating a target code template character string; compiling the target code template character string into a target memory, and performing bean registration and mapping registration to generate a target application programming interface API.
According to the technical means, the problems that a web system is configured more complicatedly, configuration files need to be modified and application needs to be restarted, a large amount of repeated work occurs and the like in the related technology are solved.
Further, before acquiring the data source corresponding to the to-be-used data source identity from the preset data source connection pool according to the to-be-used data source identity, the method further includes: judging whether a key value pair of a preset memory cache has a primary key identification corresponding to the identity identification of the data source to be used or not; if the key value pair of the preset memory cache does not have a primary key identification corresponding to the identity identification of the data source to be used, searching whether data source connection information corresponding to the primary key identification exists or not from a preset distributed cache database; if the data source connection information corresponding to the primary key identification does not exist in the preset distributed cache database, reading the data source connection information corresponding to the primary key identification from a target database, storing the data source connection information into the preset distributed cache database, generating a connection pool of the data source to be used by combining the data source connection information corresponding to the primary key identification, and storing the data source connection pool to be used into the key value pair of the preset memory cache.
According to the technical means, the main key identification can be obtained from the key value pair of the preset memory cache, and the high-efficiency use of multiple data sources can be ensured by reading the data source connection information from the preset distributed cache database and the target database.
Further, the method for generating the API further includes: if the data source connection information corresponding to the primary key identification exists in the preset distributed cache database, acquiring the data source connection information corresponding to the primary key identification from the preset distributed cache database; and generating the to-be-used data source connection pool according to the data source connection information corresponding to the primary key identification, and storing the to-be-used data source connection pool into the key value pair of the preset memory cache.
According to the technical means, the data source connection information is stored in the database, and dynamic increase and decrease of the data sources do not need to reconfigure files.
Further, before obtaining the identity of the data source to be used, which is transmitted by the user, the method further includes: introducing the data source to be used through a preset operable interface; and symmetrically encrypting the data source to be used.
According to the technical means, the data source is symmetrically encrypted, so that the data source can be conveniently read for use in the follow-up process.
Further, the data source to be used comprises at least one of a field data source type, a data source name, a data source connection url, a data source user name, a data source password and a data source description.
According to the technical means, when a user needs to use the data source, the information of the data source can be accurately and effectively inquired.
An embodiment of a second aspect of the present application provides an apparatus for generating an API, including: the first acquisition module is used for acquiring the identity of the data source to be used, which is transmitted by a user; the first generation module is used for acquiring a data source connection pool corresponding to the to-be-used data source identity from a key value cached in a preset memory according to the to-be-used data source identity, reading a data source corresponding to the to-be-used data source identity from the data source connection pool, filling the to-be-used data source identity and a data source corresponding to the to-be-used data source identity into a preset code template character string, and generating a target code template character string; and the second generation module is used for compiling the target code template character string into a target memory, performing bean registration and mapping registration and generating a target application programming interface API.
Further, the first generation module includes: the judging unit is used for judging whether a key value pair cached in a preset memory has a primary key identifier corresponding to the identity identifier of the data source to be used; a searching unit, configured to search, if a primary key identifier corresponding to the to-be-used data source identity identifier does not exist in the key value pair of the preset memory cache, whether data source connection information corresponding to the primary key identifier exists in a preset distributed cache database; and the storage unit is used for reading the data source connection information corresponding to the primary key identifier from a target database if the data source connection information corresponding to the primary key identifier does not exist in the preset distributed cache database, storing the data source connection information into the preset distributed cache database, generating a connection pool of the data source to be used by combining the data source connection information corresponding to the primary key identifier, and storing the data source connection pool to be used into the key value pair of the preset memory cache.
Further, the apparatus for generating an API described above further includes: a second obtaining module, configured to obtain, if there is data source connection information corresponding to the primary key identifier in the preset distributed cache database, the data source connection information corresponding to the primary key identifier from the preset distributed cache database; and the storage module is used for generating the data source connection pool to be used according to the data source connection information corresponding to the primary key identifier, and storing the data source connection pool to be used into the key value pair of the preset memory cache.
Further, the first obtaining module includes: the leading-in unit is used for leading in the data source to be used through a preset operable interface; and the encryption unit is used for symmetrically encrypting the data source to be used.
Further, the data source to be used comprises at least one of field data source type, data source name, data source connection url, data source user name, data source password and data source description.
An embodiment of a third aspect of the present application provides an electronic device, including: a memory, a processor and a computer program stored on the memory and executable on the processor, the processor executing the program to implement the method of generating an API as described in the above embodiments.
A fourth aspect of the present application provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to implement the method for generating an API according to the foregoing embodiments.
Therefore, the data source connection pool corresponding to the to-be-used data source identity is obtained from the key value cached in the preset memory by obtaining the to-be-used data source identity transmitted by the user, the data source corresponding to the to-be-used data source is read from the data source connection pool, the to-be-used data source identity and the data source corresponding to the to-be-used data source identity are filled into the preset code template character string, the target code template character string is generated, the target code template character string is compiled into the target memory, bean registration and mapping registration are carried out, and the target application programming interface API is generated. The problems that in the related art, the configuration of a web system is complex, configuration files need to be modified, application is restarted, a large amount of repeated work occurs and the like are solved, the management and the use of multiple data sources are realized, and the development efficiency of developers is improved.
Additional aspects and advantages of the present application will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the present application.
Drawings
The above and/or additional aspects and advantages of the present application will become apparent and readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings of which:
fig. 1 is a flowchart of a method for generating an API according to an embodiment of the present application;
FIG. 2 is a diagram of a data table structure according to one embodiment of the present application;
FIG. 3 is a flow diagram of obtaining a data source according to one embodiment of the present application;
FIG. 4 is a block diagram illustrating an apparatus for generating an API in accordance with an embodiment of the present application;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Description of the reference numerals: 10-means to generate API, 100-first obtaining module, 200-first generating module, 300-second generating module, 501-memory, 502-processor, 503-communication interface.
Detailed Description
Reference will now be made in detail to the embodiments of the present application, examples of which are illustrated in the accompanying drawings, wherein like reference numerals refer to the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are illustrative and intended to explain the present application and should not be construed as limiting the present application.
Methods, apparatuses, electronic devices, and storage media for generating an API according to embodiments of the present application are described below with reference to the accompanying drawings.
Before introducing the method for generating the API in the embodiment of the present application, a multi-source data management method in the related art is briefly introduced.
In the related art, a method and a device for implementing operation of multiple data sources based on JdbcTemplate are disclosed, which are used for accessing databases for implementing different data sources.
Related technologies also disclose a multi-data source service processing method, device and storage medium, which are used for performing fast query on different data sources, however, the method needs to configure a config class for each data source, resulting in low data source and code coupling capability.
The method includes obtaining a data source connection pool corresponding to a data source identity to be used from a key value cached in a preset memory by obtaining the data source identity to be used, reading a data source corresponding to the data source to be used from the data source connection pool, filling a data source corresponding to the data source identity to be used and the data source corresponding to the data source identity to be used into a preset code template character string, generating a target code template character string, compiling the target code template character string into a target memory, performing bean registration and mapping registration, and generating a target application programming interface API. Therefore, the problems that in the related technology, the configuration of the web system is complex, the configuration file needs to be modified, the application is restarted, a large amount of repeated work occurs and the like are solved, the management and the use of multiple data sources are realized, and the development efficiency of developers is improved.
Specifically, fig. 1 is a flowchart of a method for generating an API provided in an embodiment of the present application.
As shown in fig. 1, the method for generating the API includes the following steps:
in step S101, a data source identity to be used, which is transmitted by a user, is obtained.
Optionally, in some embodiments, before acquiring the identity of the data source to be used, the method further includes: introducing a data source to be used through a preset operable interface; and symmetrically encrypting the data source to be used.
Optionally, in some embodiments, the data source to be used includes at least one of a field data source type, a data source name, a data source connection url, a data source user name, a data source password, and a data source description.
The preset operable interface may be an operation interface of the computer.
Specifically, the user introduces the data source to be used through the provided operable interface, wherein the data source comprises a field data source type, a data source name, a data source connection url, a data source user name and a data source password.
It should be noted that a user needs to perform a database connection test first to store a data source, where a data table structure of the stored data source is shown in fig. 2, in the embodiment of the present application, a DriverManager may be used to perform a test on data source connection, and the user may check a password when introducing a data source for the first time, and the password is invisible after the data source is successfully stored.
In step S102, a data source connection pool corresponding to the to-be-used data source identifier is obtained from a key value cached in a preset memory according to the to-be-used data source identifier, a data source corresponding to the to-be-used data source identifier is read from the data source connection pool, and a data source corresponding to the to-be-used data source identifier and the to-be-used data source identifier is filled into a preset code template character string to generate a target code template character string.
It should be understood that, after the identity of the data source to be used that is sent by the user is obtained, in order to obtain the data source corresponding to the identity of the data source to be used, the data source connection pool corresponding to the identity of the data source to be used may be obtained from the key value stored in the preset memory, and then the data source corresponding to the identity of the data source to be used may be obtained by reading from the data source connection pool, where an obtaining process of the data source will be described in detail later.
Further, in order to fill the data source to be used and the data source corresponding to the data source to be used identifier into a preset code template character string, in the embodiment of the present application, a code template may be defined first, and the API is generated each time and dynamically compiled using the template. The code template is a code character string of a Controller in the web application, the Controller has only one interface, the interface has the functions of acquiring a corresponding data source connection pool according to an sql statement and a data source identity transmitted by a user by using the tool class managed by multiple data sources and the data source identity, connecting and operating corresponding data by using JDBC (Java data base Connectivity, java DataBase connection) and returning a result. The middle of the code template character string takes 5 parts as parameters, wherein the class name and the interface method name are formed by adding suffixes to a part of fixed character string, repeated class names and method names are prevented from appearing after compiling the code template, two suffixes are taken as the first 2 parameters, the 3 rd parameter is an access path of an interface, the access path of the interface is only executed on the interface method and is not executed on the class, and repetition is prevented, the 4 th parameter is an sql statement transmitted by a user, and the 5 th parameter is a data source identity used by the user.
It should be noted that, each time an API needs to be generated, a user needs to select a used data source identity, send in a corresponding sql statement, specify an interface path, use a code template to replace parameters, use system time as a replacement for a class name and a method name suffix to prevent repetition, and generate a complete code template character string.
Optionally, in some embodiments, before acquiring, according to the identifier of the data source to be used, a data source corresponding to the identifier of the data source to be used from a preset data source connection pool, the method further includes: judging whether a primary key identification corresponding to the identity identification of the data source to be used exists in a key value pair of a preset memory cache; if the key value pair of the preset memory cache does not have a primary key identification corresponding to the identity identification of the data source to be used, searching whether data source connection information corresponding to the primary key identification exists or not from a preset distributed cache database; if the data source connection information corresponding to the primary key identification does not exist in the preset distributed cache database, the data source connection information corresponding to the primary key identification is read from the target database and stored in the preset distributed cache database, a connection pool of the data source to be used is generated by combining the data source connection information corresponding to the primary key identification, and the data source connection pool to be used is stored in the key value pair of the preset memory cache.
Optionally, in some embodiments, the method for generating an API described above further includes: if the data source connection information corresponding to the primary key identification exists in the preset distributed cache database, acquiring the data source connection information corresponding to the primary key identification from the preset distributed cache database; and generating a to-be-used data source connection pool according to the data source connection information corresponding to the primary key identification, and storing the to-be-used data source connection pool into a key value pair of a preset memory cache.
For ease of understanding, the data source acquisition process will be described in detail herein with reference to fig. 3, and fig. 3 is a flowchart of acquiring a data source according to an embodiment of the present application.
In step S301, a primary key id (i.e., primary key identifier) corresponding to the data source identifier is determined.
In step S302, it is determined whether the primary key id exists in the memory cache key value pair, and if so, step S303 is executed; if not, go to step S304.
In step S303, the data source connection pool corresponding to the primary key id is retrieved and returned.
In step S304, it is determined whether data source connection information corresponding to the primary key id exists in redis (i.e., a preset distributed cache database), and if so, steps S305 to S307 are executed; if not, steps S308-S311 are performed.
In step S305, data source connection information corresponding to the primary key id is retrieved from the redis.
In step S306, a connection pool is generated from the connection information.
In step S307, the data connection pool is put into the key value pair of the memory cache and returned.
In step S308, the data source connection information corresponding to the primary key id is retrieved from mysql (i.e., the target database).
In step S309, the data source connection information is stored in the redis.
In step S310, a connection pool is generated from the data source connection information and is placed into the memory cache key value pair.
In step S311, the data source connection pool is returned.
In summary, before acquiring a corresponding data source, the embodiment of the present application may find out, from a key value pair of a preset memory cache, whether a primary key id corresponding to a data source identity to be used exists, and if data source connection information corresponding to the primary key identity exists in the key value pair of the preset memory cache, return a data source connection pool corresponding to the primary key id; if the primary key id does not exist, searching whether data source connection information corresponding to the primary key id exists in redis, if the data source connection information corresponding to the primary key id exists in redis, directly acquiring the corresponding data source connection information, generating a to-be-used data source connection pool, storing the to-be-used data source connection pool into a key value pair of a preset memory cache, and returning; and if the data source connection information corresponding to the primary key id does not exist, storing the data source connection information corresponding to the primary key id into redis from the mysql, generating a connection pool of the data source to be used by combining the data source connection information corresponding to the primary key id, storing the connection pool into a key value pair of a preset memory cache, and returning the data source connection pool.
In step S103, the target code template string is compiled into the target memory, and bean registration and mapping registration are performed to generate the target application programming interface API.
Specifically, the generated code template character string calls a java bottom layer method to be compiled into a memory, bean registration is carried out, mapping registration is finally carried out, and generation of a target Application Programming Interface (API) is further completed.
According to the method for generating the API, the identity of the data source to be used, which is transmitted by a user, is acquired from the key value of the preset memory cache, the data source connection pool corresponding to the identity of the data source to be used is acquired, the data source corresponding to the data source to be used is read from the data source connection pool, the identity of the data source to be used and the data source corresponding to the identity of the data source to be used are filled into the preset code template character string, the target code template character string is generated, the target code template character string is compiled into the target memory, bean registration and mapping registration are carried out, and the target application programming interface API is generated. Therefore, the problems that in the related technology, the configuration of the web system is complex, the configuration file needs to be modified, the application is restarted, a large amount of repeated work occurs and the like are solved, the management and the use of multiple data sources are realized, and the development efficiency of developers is improved.
Next, an apparatus for generating an API proposed according to an embodiment of the present application is described with reference to the accompanying drawings.
Fig. 4 is a block diagram illustrating an apparatus for generating an API according to an embodiment of the present application.
As shown in fig. 4, the apparatus 10 for generating API includes: a first acquisition module 100, a first generation module 200 and a second generation module 300.
The acquiring module 100 is configured to acquire an identity of a data source to be used, which is transmitted by a user; the first generating module 200 is configured to obtain a data source connection pool corresponding to the to-be-used data source identity from a key value cached in a preset memory according to the to-be-used data source identity, read a data source corresponding to the to-be-used data source from the data source connection pool, fill the to-be-used data source identity and a data source corresponding to the to-be-used data source identity into a preset code template character string, and generate a target code template character string; and a second generating module 300, configured to compile the target code template string into a target memory, perform bean registration and mapping registration, and generate a target application programming interface API.
Optionally, in some embodiments, the first generation module 200 includes: the judging unit is used for judging whether a primary key identifier corresponding to the identity identifier of the data source to be used exists in a key value pair cached in a preset memory; the searching unit is used for searching whether data source connection information corresponding to the primary key identification exists in a preset distributed cache database if the primary key identification corresponding to the to-be-used data source identification does not exist in the key value pair of the preset memory cache; and the storage unit is used for reading the data source connection information corresponding to the primary key identifier from the target database if the data source connection information corresponding to the primary key identifier does not exist in the preset distributed cache database, storing the data source connection information into the preset distributed cache database, generating a connection pool of the data source to be used by combining the data source connection information corresponding to the primary key identifier, and storing the data source connection pool to be used into the key value pair of the preset memory cache.
Optionally, in some embodiments, the apparatus 10 for generating an API further includes: the second obtaining module is used for obtaining the data source connection information corresponding to the primary key identifier from the preset distributed cache database if the preset distributed cache database has the data source connection information corresponding to the primary key identifier; and the storage module is used for generating a to-be-used data source connection pool according to the data source connection information corresponding to the primary key identifier, and storing the to-be-used data source connection pool into the key value pair of the preset memory cache.
Optionally, in some embodiments, the first obtaining module 100 includes: the device comprises an introduction unit, a data processing unit and a control unit, wherein the introduction unit is used for introducing a data source to be used through a preset operable interface; and the encryption unit is used for symmetrically encrypting the data source to be used.
Optionally, in some embodiments, the data source to be used includes at least one of a field data source type, a data source name, a data source connection url, a data source user name, a data source password, and a data source description.
It should be noted that the foregoing explanation on the embodiment of the method for generating the API is also applicable to the apparatus for generating the API of this embodiment, and is not repeated here.
According to the device for generating the API, the identity of the data source to be used, which is transmitted by a user, is obtained, the data source connection pool corresponding to the identity of the data source to be used is obtained from the key value cached in the preset memory, the data source corresponding to the data source to be used is read from the data source connection pool, the data source corresponding to the identity of the data source to be used and the data source corresponding to the identity of the data source to be used are filled into the preset code template character string, the target code template character string is generated, the target code template character string is compiled into the target memory, bean registration and mapping registration are carried out, and the target application programming interface API is generated. Therefore, the problems that in the related technology, the configuration of the web system is complex, the configuration file needs to be modified and the application needs to be restarted, a large amount of repeated work occurs and the like are solved, the management and the use of multiple data sources are realized, and the development efficiency of developers is improved.
Fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application. The electronic device may include:
memory 501, processor 502, and computer programs stored on memory 501 and executable on processor 502.
The processor 502, when executing the program, implements the method of generating the API provided in the above embodiments.
Further, the electronic device further includes:
a communication interface 503 for communication between the memory 501 and the processor 502.
A memory 501 for storing computer programs that can be run on the processor 502.
The Memory 501 may include a high-speed RAM (Random Access Memory) Memory, and may also include a non-volatile Memory, such as at least one disk Memory.
If the memory 501, the processor 502 and the communication interface 503 are implemented independently, the communication interface 503, the memory 501 and the processor 502 may be connected to each other through a bus and perform communication with each other. The bus may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 5, but this is not intended to represent only one bus or type of bus.
Optionally, in a specific implementation, if the memory 501, the processor 502, and the communication interface 503 are integrated on one chip, the memory 501, the processor 502, and the communication interface 503 may complete mutual communication through an internal interface.
The processor 502 may be a Central Processing Unit (CPU), an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits configured to implement embodiments of the present Application.
Embodiments of the present application also provide a computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the method for generating an API as above.
In the description herein, reference to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the application. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or N embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In the description of the present application, "N" means at least two, e.g., two, three, etc., unless specifically limited otherwise.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more N executable instructions for implementing steps of a custom logic function or process, and alternate implementations are included within the scope of the preferred embodiment of the present application in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of implementing the embodiments of the present application.
It should be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the N steps or methods may be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. If implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: discrete logic circuits having logic gates for implementing logic functions on data signals, application specific integrated circuits having suitable combinational logic gates, programmable gate arrays, field programmable gate arrays, and the like.
It will be understood by those skilled in the art that all or part of the steps carried by the method for implementing the above embodiments may be implemented by hardware related to instructions of a program, which may be stored in a computer readable storage medium, and when the program is executed, the program includes one or a combination of the steps of the method embodiments.
While embodiments of the present application have been shown and described above, it will be understood that the above embodiments are exemplary and should not be construed as limiting the present application and that changes, modifications, substitutions and alterations in the above embodiments may be made by those of ordinary skill in the art within the scope of the present application.

Claims (10)

1. A method of generating an API, comprising the steps of:
acquiring an identity of a data source to be used, which is transmitted by a user;
acquiring a data source connection pool corresponding to the to-be-used data source identity from a key value cached in a preset memory according to the to-be-used data source identity, reading a data source corresponding to the to-be-used data source identity from the data source connection pool, filling the to-be-used data source identity and a data source corresponding to the to-be-used data source identity into a preset code template character string, and generating a target code template character string; and
compiling the target code template character string into a target memory, and performing bean registration and mapping registration to generate a target application programming interface API.
2. The method according to claim 1, before acquiring, according to the identifier of the data source to be used, a data source corresponding to the identifier of the data source to be used from the preset data source connection pool, further comprising:
judging whether a key value pair of a preset memory cache has a primary key identification corresponding to the identity identification of the data source to be used or not;
if the key value pair of the preset memory cache does not have a primary key identification corresponding to the identity identification of the data source to be used, searching whether data source connection information corresponding to the primary key identification exists or not from a preset distributed cache database;
if the data source connection information corresponding to the primary key identification does not exist in the preset distributed cache database, reading the data source connection information corresponding to the primary key identification from a target database, storing the data source connection information into the preset distributed cache database, generating a connection pool of the data source to be used by combining the data source connection information corresponding to the primary key identification, and storing the data source connection pool to be used into the key value pair of the preset memory cache.
3. The method of claim 2, further comprising:
if the data source connection information corresponding to the primary key identification exists in the preset distributed cache database, acquiring the data source connection information corresponding to the primary key identification from the preset distributed cache database;
and generating the data source connection pool to be used according to the data source connection information corresponding to the primary key identification, and storing the data source connection pool to be used into the key value pair cached in the preset memory.
4. The method according to claim 1, before obtaining the identity of the data source to be used, which is transmitted by the user, further comprising:
introducing the data source to be used through a preset operable interface;
and symmetrically encrypting the data source to be used.
5. The method of claim 4, wherein the data source to be used comprises at least one of a field data source type, a data source name, a data source connection url, a data source user name, a data source password, and a data source description.
6. An apparatus for generating an API, comprising:
the first acquisition module is used for acquiring the identity of the data source to be used, which is transmitted by a user;
the first generation module is used for acquiring a data source connection pool corresponding to the to-be-used data source identity from a key value cached in a preset memory according to the to-be-used data source identity, reading a data source corresponding to the to-be-used data source identity from the data source connection pool, filling the to-be-used data source identity and a data source corresponding to the to-be-used data source identity into a preset code template character string, and generating a target code template character string; and
and the second generation module is used for compiling the target code template character string into a target memory, performing bean registration and mapping registration and generating a target application programming interface API.
7. The apparatus of claim 6, wherein the first generation module comprises:
the judging unit is used for judging whether a primary key identifier corresponding to the identity identifier of the data source to be used exists in a key value pair of a preset memory cache;
a searching unit, configured to search, if a primary key identifier corresponding to the to-be-used data source identity does not exist in the key value pair of the preset memory cache, whether data source connection information corresponding to the primary key identifier exists in a preset distributed cache database;
and the storage unit is used for reading the data source connection information corresponding to the primary key identifier from a target database if the data source connection information corresponding to the primary key identifier does not exist in the preset distributed cache database, storing the data source connection information into the preset distributed cache database, generating a connection pool of the data source to be used by combining the data source connection information corresponding to the primary key identifier, and storing the data source connection pool to be used into the key value pair of the preset memory cache.
8. The apparatus of claim 6, further comprising:
a second obtaining module, configured to obtain, if there is data source connection information corresponding to the primary key identifier in the preset distributed cache database, the data source connection information corresponding to the primary key identifier from the preset distributed cache database;
and the storage module is used for generating the data source connection pool to be used according to the data source connection information corresponding to the primary key identifier, and storing the data source connection pool to be used into the key value pair of the preset memory cache.
9. An electronic device, comprising: memory, processor and computer program stored on the memory and executable on the processor, the processor executing the program to implement a method of generating an API as claimed in any one of claims 1 to 5.
10. A computer-readable storage medium, on which a computer program is stored, the program being executable by a processor for implementing a method of generating an API as claimed in any one of claims 1 to 5.
CN202211032904.3A 2022-08-26 2022-08-26 API (application program interface) generating method and device, electronic equipment and storage medium Pending CN115480813A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211032904.3A CN115480813A (en) 2022-08-26 2022-08-26 API (application program interface) generating method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211032904.3A CN115480813A (en) 2022-08-26 2022-08-26 API (application program interface) generating method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115480813A true CN115480813A (en) 2022-12-16

Family

ID=84423128

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211032904.3A Pending CN115480813A (en) 2022-08-26 2022-08-26 API (application program interface) generating method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115480813A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117453964A (en) * 2023-10-08 2024-01-26 北京融和云链科技有限公司 Template-based data structure acquisition and target template generation method and device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117453964A (en) * 2023-10-08 2024-01-26 北京融和云链科技有限公司 Template-based data structure acquisition and target template generation method and device
CN117453964B (en) * 2023-10-08 2024-04-30 北京融和云链科技有限公司 Template-based data structure acquisition and target template generation method and device

Similar Documents

Publication Publication Date Title
CN111797073A (en) Database management method, electronic device, and computer-readable storage medium
CN108614696B (en) Application making method, static library generation method and device
CN108279882B (en) Framework generation method, device, equipment and computer readable medium
CN113918635A (en) Interface data format conversion method and device
CN115480813A (en) API (application program interface) generating method and device, electronic equipment and storage medium
CN110717050B (en) Knowledge graph database access method and device
CN113722114A (en) Data service processing method and device, computing equipment and storage medium
CN111382179B (en) Data processing method and device and electronic equipment
CN111259619A (en) Control method and device for configuration object, storage medium and verification platform
CN116401171A (en) Test case library generation method, system, equipment and medium
CN113656100B (en) Interface switching method, device, electronic device and computer program product
CN114565285A (en) Flow control method and system
CN115809290A (en) Method, device, equipment and medium for generating data persistence layer entry
CN108334313A (en) Continuous integrating method, apparatus and code management system for large-scale SOC research and development
CN112559346A (en) Service testing method and device
CN115858256A (en) Test method and device for Internet of things equipment and electronic equipment
CN113495723A (en) Method and device for calling functional component and storage medium
CN109635175B (en) Page data splicing method and device, readable storage medium and electronic equipment
CN111459583A (en) Menu creating method and device
CN111881220A (en) Data operation method and device under list storage, electronic equipment and storage medium
CN114637761B (en) Business object generation method and device
CN117369784B (en) Processing system and method of service interface
US20110208945A1 (en) Generating random addresses for verification of distributed computerized devices
CN113111012B (en) Application data locator generation method and application data locating method
CN117389880A (en) Automatic testing method and device for web interface and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination