Interface generation method and device, storage medium and terminal

By defining dependency annotations and automatically generating interface file packages, the problems of multiple interface definition steps and complex project structure are solved, and the efficiency and simplicity of service development are improved.

CN119536849APending Publication Date: 2025-02-28GUANGZHOU SHIYUAN ELECTRONICS CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311102785.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-29
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

In the prior art, there are many steps for interface definition and complex project structure, resulting in inefficient development and maintenance of service interfaces.

Method used

By defining dependency annotations, identifying the dependencies of the annotated method, and adding dependency annotations to the target method, an interface file package is automatically generated for calling the target method.

Benefits of technology

The human resource development process of the interface is reduced, the automatic generation of interface file packages is realized, the overall efficiency of service development is improved, and the project structure is simplified.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536849A_ABST
    Figure CN119536849A_ABST
Patent Text Reader

Abstract

The invention discloses an interface generation method and device, a storage medium and a terminal, and the method comprises the steps: defining a dependency annotation which is used for identifying a dependency party corresponding to an annotated method; determining a target method with a target dependency party, adding a target dependency annotation to the target method according to the target dependency party corresponding to the target method, each target dependency annotation independently identifying one target dependency party of the target method; and determining the target method added with the target dependency annotation, and generating an interface file package for calling the target method based on the target method. The dependency annotation used for identifying the dependency party corresponding to the annotated method is defined, and the dependency annotation is added to the target method needing to be depended and called, so that the target method needing to generate the dependency interface can be directly determined from all the methods based on the dependency annotation; and automatically generating an interface file package for calling the target method based on the target method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an interface generation method, device, storage medium and terminal. Background Art

[0002] There are a large number of services that have been developed and can be used directly on the Internet. These services are usually deployed on different machines. In order to achieve smooth communication between different machines, service consumers need to rely on the corresponding service interfaces to call the services. Currently, service interfaces are developed separately and defined in different engineering modules with service implementation classes. When new services are added or changed, both the service interface package and the service implementation package need to be developed. Summary of the invention

[0003] The present application provides an interface generation method, device, storage medium and terminal, which can solve the technical problems of multiple interface definition steps and complex project structure in related technologies.

[0004] In a first aspect, an embodiment of the present application provides an interface generation method, the method comprising:

[0005] Define dependency annotations, which are used to identify the dependent party corresponding to the annotated method;

[0006] Determine a target method having a target dependent party, and add a target dependency annotation to the target method according to the target dependent party corresponding to the target method, each of the target dependency annotations individually identifying a target dependent party of the target method;

[0007] The target method to which the target dependency annotation is added is determined, and an interface file package for calling the target method is generated based on the target method.

[0008] In a second aspect, an embodiment of the present application provides an interface generation device, the device comprising:

[0009] An annotation definition module is used to define dependency annotations, where the dependency annotations are used to identify the dependent party corresponding to the annotated method;

[0010] An annotation adding module is used to determine a target method having a target dependent party, and add a target dependency annotation to the target method according to the target dependent party corresponding to the target method, each of the target dependency annotations separately identifies a target dependent party of the target method;

[0011] The interface generation module is used to determine the target method with the target dependency annotation added, and generate an interface file package for calling the target method based on the target method.

[0012] In a third aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the steps of the above-mentioned method.

[0013] In a fourth aspect, an embodiment of the present application provides a terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is suitable for being loaded by the processor and executing the steps of the above method.

[0014] The beneficial effects brought about by the technical solutions provided by some embodiments of the present application include at least:

[0015] The present application provides an interface generation method, which defines dependency annotations, which are used to identify the dependent party corresponding to the annotated method; determines a target method with a target dependent party, adds a target dependency annotation to the target method according to the target dependent party corresponding to the target method, and each target dependency annotation separately identifies a target dependent party of the target method; determines the target method with the target dependency annotation added, and generates an interface file package for calling the target method based on the target method. Since the dependency annotation for identifying the dependent party corresponding to the annotated method is defined, and the dependency annotation is added to the target method that needs to be relied on and called, it means that the annotated method is relied on and called by the dependent party identified by the dependency annotation, that is, when all methods are written, compiled and packaged, the target method for which the dependency interface needs to be generated can be directly determined from all methods based on the dependency annotation, and then the interface file package for calling the target method can be automatically generated based on the target method, which reduces the human development process of the interface, realizes the automatic generation of the interface file package, and improves the overall efficiency of service development. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.

[0017] Figure 1 An exemplary system architecture diagram of an interface generation method provided in an embodiment of the present application;

[0018] Figure 2 A flowchart of an interface generation method provided in an embodiment of the present application;

[0019] Figure 3 A flowchart of an interface generation method provided in an embodiment of the present application;

[0020] Figure 4A structural block diagram of an interface generation device provided in an embodiment of the present application;

[0021] Figure 5 A schematic diagram of the structure of a terminal provided in an embodiment of the present application. DETAILED DESCRIPTION

[0022] In order to make the features and advantages of the present application more obvious and easy to understand, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0023] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.

[0024] In the field of Internet development, some website applications with relatively small traffic initially usually use a single application architecture (ORM). The single application architecture can deploy all functions together through one application to reduce deployment nodes and costs. As the number of visits gradually increases, it is more troublesome to expand the capacity of the single application architecture, so the various parts of the system are split into several unrelated applications, forming a vertical application architecture (MVC), and each application is independently developed and deployed to improve efficiency. However, with the development of Internet technology, facing large and small business needs, the business functions provided by products are becoming more and more onerous, and the scale of website applications is constantly expanding. Conventional vertical application architectures can no longer cope with it. As vertical applications increase in number, the same logic code of each system cannot be reused, and it is inevitable that different applications need to interact. Therefore, the core business is extracted as an independent service, gradually forming a stable service center, that is, a distributed application architecture (RPC), so that front-end applications can respond to changing market demands more quickly. At the same time, as more and more services are provided, problems such as capacity evaluation and waste of small service resources gradually emerge. At this time, it is necessary to provide a scheduling center based on the flow computing architecture (SOA) to manage cluster capacity in real time based on access pressure and improve cluster utilization.

[0025] Based on this, the Dubbo microservice architecture emerged. Dubbo is a high-performance distributed service framework that is committed to providing high-performance and transparent RPC remote service call solutions and SOA service governance solutions, so that applications can implement service output and input functions through high-performance RPC, and can be seamlessly integrated with the Spring framework. Generally, to provide dubbo services, you need to define an interface (API) in another project module (maven module), and then the service consumer relies on the interface to call the service corresponding to this interface.

[0026] However, the implementation class of the service is the implementation code of the function, which needs to be placed in the code package corresponding to the implementation class, and the interface class of the service needs to be placed in the interface package separately. In addition, if there are multiple different dependent parties, in order to meet the interface isolation principle, that is, the dependent party should not rely on the interface it does not need, then each dependent party needs to define its own corresponding interface class, that is, it is necessary to provide each dependent party with a separate corresponding interface package. The more dependent parties there are, the more Maven modules there are, and the more complex the project structure is. On the other hand, when the interface definition or implementation method code changes, both the implementation package and the interface package need to be modified at the same time. When a new dependent interface needs to be added to a method, the data transfer object class (dto class) corresponding to the return value of the method parameter needs to be migrated to the interface package when developing the interface. This will cause all other dependencies involving the same dto class to need to be manually developed and modified, and the scope of change is very large.

[0027] Therefore, an embodiment of the present application provides an interface generation method to solve the above-mentioned technical problems of multiple interface definition steps and complex project structure.

[0028] See also Figure 1 , Figure 1 An exemplary system architecture diagram of an interface generation method provided in an embodiment of the present application.

[0029] like Figure 1 As shown, the system architecture may include a terminal 101, a network 102, and a server 103. The network 102 is used to provide a medium for a communication link between the terminal 101 and the server 103. The network 102 may include various types of wired communication links or wireless communication links, for example, the wired communication link includes an optical fiber, a twisted pair, or a coaxial cable, and the wireless communication link includes a Bluetooth communication link, a Wireless-Fidelity (Wi-Fi) communication link, or a microwave communication link.

[0030] The terminal 101 can interact with the server 103 through the network 102 to receive messages from the server 103 or send messages to the server 103, or the terminal 101 can interact with the server 103 through the network 102 to receive messages or data sent by other users to the server 103. The terminal 101 can be hardware or software. When the terminal 101 is hardware, it can be various electronic devices, including but not limited to smart watches, smart phones, tablet computers, laptop portable computers and desktop computers. When the terminal 101 is software, it can be installed in the electronic devices listed above, which can be implemented as multiple software or software modules (for example: used to provide distributed services), or it can be implemented as a single software or software module, which is not specifically limited here.

[0031] In an embodiment of the present application, the terminal 101 first defines a dependency annotation, which is used to identify the dependent party corresponding to the annotated method; then the terminal 101 can determine the target method with the target dependent party, and add a target dependency annotation to the target method according to the target dependent party corresponding to the target method, and each target dependency annotation separately identifies a target dependent party of the target method; finally, the terminal 101 generates an interface file package for calling the target method based on the target method according to the determined target method with the target dependency annotation.

[0032] The server 103 may be a business server that provides various services. It should be noted that the server 103 may be hardware or software. When the server 103 is hardware, it may be implemented as a distributed server cluster consisting of multiple servers, or it may be implemented as a single server. When the server 103 is software, it may be implemented as multiple software or software modules (for example, for providing distributed services), or it may be implemented as a single software or software module, which is not specifically limited here.

[0033] Alternatively, the system architecture may not include the server 103. In other words, the server 103 may be an optional device in the embodiments of this specification. That is, the method provided in the embodiments of this specification may be applied to a system structure that only includes the terminal 101, and the embodiments of this application do not limit this.

[0034] It should be understood that Figure 1 The number of terminals, networks and servers in the figure is only for illustration and any number of terminals, networks and servers may be used according to implementation requirements.

[0035] See also Figure 2 , Figure 2A flowchart of an interface generation method provided for an embodiment of the present application. The execution subject of the embodiment of the present application can be a terminal that executes interface generation, or a processor in the terminal that executes the interface generation method, or an interface generation service in the terminal that executes the interface generation method. For the convenience of description, the specific execution process of the interface generation method is introduced below by taking the execution subject as an example of a processor in a terminal.

[0036] like Figure 2 As shown, the interface generation method may at least include:

[0037] S202. Define dependency annotations, which are used to identify dependent parties corresponding to the annotated methods.

[0038] Optionally, services and functions are implemented through codes compiled by developers. In a complete service project (maven), a method is a set of code that organizes code blocks with independent functions into a whole to make it have special functions. A method must be created before it can be used. This process is called a method definition. A method cannot be run directly after it is created. It needs to be used manually before it can be executed. This process is called a method call, that is, a method is a set of code that implements specific functions. A class is a collection of entities with certain common characteristics. It is an abstraction of entities with the same characteristics. There may be multiple methods in a class.

[0039] Optionally, in the code compilation mechanism, there is also an annotation mechanism, which is a metadata mechanism in computer programming languages. It can add additional information to the code to facilitate the understanding and processing of the program. In the Java programming language, an annotation is a special syntax structure starting with the @ symbol. It can be used in various locations in the code, including classes, methods, attributes, parameters, etc., to describe the characteristics of various programs such as classes, methods, attributes, such as authors, versions, permissions, etc. That is, annotations can describe the characteristics of the annotated program elements.

[0040] Optionally, in an embodiment of the present application, for services that need to expose interfaces for external dependent parties to call, dependency annotations can be defined to identify the dependent parties corresponding to the annotated methods, dependency annotations can be added to the methods corresponding to the services, and dependency annotations can be used to identify which dependent parties correspond to the annotated methods. In this way, when laying out services, methods that need to be called by dependency and methods that do not need to be called by dependency can be distinguished, and methods that require interfaces can be directly determined at one time based on dependency annotations. This makes it easy to develop interfaces for all methods that require interfaces, and there is no need to develop interfaces required by dependent parties every time a method to implement a function is developed. At the same time, in order to reduce manual programming development, a dynamic proxy service that parses and processes annotations can be configured. In this way, methods with annotations can be discovered through the dynamic proxy service, and dependency interfaces corresponding to each method can be automatically generated based on each method, reducing the human development process of the interface and improving the overall efficiency of service development.

[0041] Optionally, the code representation of a custom dependency annotation can be:

[0042] annotation class DubboAPI(

[0043] val dependentServices:Array <string> );

[0045] Among them, dependentServices is a dependent party parameter, and its value is the dependent party corresponding to the annotated method S204, determine the target method with a target dependent party, add a target dependency annotation to the target method according to the target dependent party corresponding to the target method, and each target dependency annotation separately identifies a target dependent party of the target method.

[0046] Optionally, after defining the dependency annotation, it is possible to determine the existence of one or more target methods of the target dependent party, and determine the target dependent parties corresponding to each target method, and add the target dependency annotation to the target method according to the target dependent party corresponding to the target method. Specifically, the dependency annotation can be expressed as @DubboAPI, and the content of the annotation can indicate which target dependent party this is the dependency annotation of. For example, if there is a target method login method, and the corresponding target dependent party is a-service, then the target dependency annotation is expressed as:

[0047] @DubboAPI(["A-Service"])

[0048] fun login(loginDto:ReqDto):ResponseDto{

[0049] };

[0050] It should be noted that in order to maintain the interface isolation principle, each target dependency annotation separately identifies a target dependent party of the target method. For example, there are target methods A and B. The target dependent parties of target method A are a and b, and the target dependent parties of target method B are b and c. Then, target method A adds the target dependency annotations @DubboAPI(["a"]) corresponding to target dependent party a and @DubboAPI(["b"]) corresponding to target dependent party b; target method B adds the target dependency annotations @DubboAPI(["b"]) corresponding to target dependent party b and @DubboAPI(["c"]) corresponding to target dependent party c.

[0051] Optionally, dependency annotations can be added not only directly on methods, but also on classes that integrate multiple methods that need to be called. If you annotate a class directly, then after the class generates a dependency interface based on the annotation, all methods under the annotated class can be called through this dependency interface. It should be noted that when the relying party calls the class corresponding to the dependency interface, it can call any method in it, or call some or all methods at once, depending on the functional requirements of the relying party.

[0052] S206: Determine a target method with a target dependency annotation added, and generate an interface file package for calling the target method based on the target method.

[0053] Optionally, after dependency annotations are performed on all target methods or classes that need to expose interfaces, the target method with the target dependency annotation is determined, and an interface file package for calling the target method can be generated directly based on the target method. In this way, all interface packages do not need to be defined separately, but are automatically generated, making the project structure more concise during development. At the same time, when the interface method in the program code changes, only the interface packaging tool class needs to be automatically regenerated without the need for adjustment on the calling side, thus achieving decoupling of the program and the interface. In addition, based on the dependency annotations added to the implementation method and implementation class, the dependent party that needs to call the target method can be found quickly and conveniently.

[0054] In an embodiment of the present application, an interface generation method is provided, which defines a dependency annotation, which is used to identify the dependent party corresponding to the annotated method; a target method with a target dependent party is determined, and a target dependency annotation is added to the target method according to the target dependent party corresponding to the target method, and each target dependency annotation separately identifies a target dependent party of the target method; a target method with a target dependency annotation added is determined, and an interface file package for calling the target method is generated based on the target method. Since a dependency annotation for identifying the dependent party corresponding to the annotated method is defined, and a dependency annotation is added to the target method that needs to be relied on and called, it means that the annotated method is relied on and called by the dependent party identified by the dependency annotation, that is, when all methods are written, compiled and packaged, the target method for which the dependency interface needs to be generated can be directly determined from all methods based on the dependency annotation, and then an interface file package for calling the target method can be automatically generated based on the target method, thereby reducing the human development process of the interface, realizing the automatic generation of the interface file package, and improving the overall efficiency of service development.

[0055] See also Figure 3 , Figure 3 A flowchart of an interface generation method provided in an embodiment of the present application.

[0056] like Figure 3 As shown, the interface generation method may at least include:

[0057] S302. Define dependency annotations, which are used to identify dependent parties corresponding to the annotated methods.

[0058] S304: Determine a target method that has a target dependent party, and add a target dependency annotation to the target method according to the target dependent party corresponding to the target method, each target dependency annotation individually identifies a target dependent party of the target method.

[0059] Regarding steps S302-S304, please refer to the detailed description in steps S202-S204, which will not be repeated here.

[0060] S306 , traverse all methods in the abstract tree based on the annotation processing interface, and determine the target method with the target dependency annotation added. The abstract tree is a tree representation of the abstract syntax structure of the program source code.

[0061] Optionally, when generating an interface corresponding to a target method based on a dependency annotation, it is first necessary to determine a target method to which a target dependency annotation is added. It can be seen from the above embodiments that in order to realize the automatic generation of an interface, it is necessary to predefine an annotation processing interface, and to implement the parsing and processing of dependency annotations through the annotation processing interface. In a specific programming process, the annotation processing interface can be a Processor interface.

[0062] Optionally, when generating interface code based on the annotation processing interface, the first step is to analyze the source code of all methods in the program to determine the target methods with target dependency annotations added. When analyzing the source code, an abstract tree corresponding to all methods in the program can be generated. The abstract tree is a tree representation of the abstract syntax structure of the program source code, which can describe the syntax relationship between methods and categories from the perspective of data structure. Further, all methods in the abstract tree can be traversed based on the annotation processing interface to find all target methods with target dependency annotations added.

[0063] S308. In the compilation phase of the target method, an interface program code for calling the target method is generated based on the method program code of the target method.

[0064] Optionally, after all target methods are collected based on the annotation processing interface, the target methods are in the compilation stage. The annotation processing interface can generate an interface program code for calling the target method based on the method program code of the target method based on its own defined processing logic. In order to distinguish each interface, when generating the program code of the interface class, the target method, dependent party and other information corresponding to the interface can be reflected in the name of the interface class. In a feasible embodiment, the interface class name can be the implementation class plus the dependent party plus the dependent annotation. For example, taking the dependent party as a-service and the dependent annotation as @DubboAPI, the corresponding target method of the implementation class is com.manager.UserManager, then the name of the resulting interface class should be UserManagerAServiceDubboApi.

[0065] Furthermore, when the method program code of the target method is used to generate the interface program code for calling the target method, a variety of plug-in tools can be used to complete the automatic generation of the interface program code. In a feasible implementation, the mapstruct tool can be used to complete it. Mapstruct is an entity class mapping framework that can safely assign the attributes of an entity class to another entity class through annotations. With mapstruct, you only need to define a mapper interface and declare the method to be mapped. During the compilation process, mapstruct will automatically generate the implementation class of the interface to achieve the effect of mapping the source object to the target object. Specifically, mapstruct is implemented based on JSR269, which is a specification introduced by JDK. Based on it, it can realize the processing of annotations at compile time, and read, modify and add the content in the abstract syntax tree. JSR269 uses Annotation Processor to process annotations during compilation. Annotation Processor is a plug-in equivalent to a compiler. When implementing JSR269, first inherit the AbstractProcessor class and re-customize the process method according to its own annotation processing requirements to obtain a new custom annotation processing interface. Register the new annotation processing interface implemented after customization, so that the annotation processing interface will be automatically called during the program compilation process. The annotation processing interface modifies the abstract syntax tree and inserts the implementation logic of annotation processing. Then the compiler will generate the corresponding code file according to the modified abstract syntax tree. In this way, the interface program code for calling the target method is obtained based on each target method, and the new abstract syntax tree is directly obtained.

[0066] In another feasible implementation, the Lombok program can be used to realize the automatic generation of interface program code. Similar to the mapstruct tool, Lombok is also implemented based on the JSR269 specification. During the compilation phase of the target method, the annotation processing interface defined in the Lombok program is automatically called, and then the abstract syntax tree of the program is modified based on the annotation processing interface. The compiler generates the interface program code for calling the target method according to the modified abstract syntax tree, and thus directly obtains a new abstract syntax tree.

[0067] S3010. In the packaging phase of the target method, the interface program code is packaged to obtain an interface file package.

[0068] Optionally, during the development process, developers usually layout classes, methods, etc. in units of project modules (maven modules), and the maven tool has a life cycle feature. This is because the project construction usually includes steps such as cleaning, compiling, testing, packaging, verification, deployment, and document generation. Maven uniformly organizes and abstracts them into three life cycles and multiple corresponding phases. In this way, each phase can become an extension point, and each phase can be implemented in a different way, which improves scalability and flexibility and standardizes and unifies the execution path of maven. Based on the life cycle feature of maven, in the packaging stage of the target method, the interface program code can be packaged synchronously to obtain an interface file package, and when the implementation file package of the program is released, all corresponding interface file packages can be released synchronously, so that the generation, packaging, and release of the interface file package can be imperceptible to the service provider.

[0069] Optionally, in the packaging stage of the target method, firstly, the interface files corresponding to each target dependent party are created respectively, and the interface program codes corresponding to each target dependent party are added to the interface files corresponding to each target dependent party respectively, and each interface file is packaged to obtain the interface file package corresponding to each target dependent party. In this way, it is ensured that each dependent party corresponds to its own interface file package, and its own interface file package includes all the interfaces it needs to rely on, so that each dependent party can initiate a call to the service it needs based on the interface file package it obtains.

[0070] Optionally, for a complete Maven file package, not only code is needed, but also POM file is needed. POM is the abbreviation of Project Object Model, which is expressed in XML and is called pom.xml. This file is used to manage: source code, configuration files, developer information and roles, problem tracking system, organizational information, project authorization, project URL, project dependencies, etc. It also means that in the embodiment of the present application, the interface program code corresponding to each target dependent party is added to the interface file corresponding to each target dependent party respectively, and each interface file is packaged to obtain the interface file package corresponding to each target dependent party. Specifically, it is necessary to create a new project object model file (pom.xml file) of the interface file corresponding to each target dependent party that can describe the construction information and dependency information of the interface file; the interface program code corresponding to each target dependent party and the new project object model file are added to the interface file corresponding to each target dependent party respectively, and then each interface file is packaged to obtain the interface file package corresponding to each target dependent party, and the subsequent release and launch are carried out based on the interface file package.

[0071] Furthermore, the interface program code of the target method is generated based on the method program code mapping of the target method, which means that the interface program code and the method program code have some commonality of attribute information. Therefore, the newly created project object model file of the interface file corresponding to each target dependent party can also be modified based on the original project object model file of the target method.

[0072] For example, the original project object model file of the target method, that is, the original pom.xml file, contains the following content:

[0073] <project>

[0074] <modelversion> 4.0.0< / modelversion>

[0075] <groupid> com.test< / groupid>

[0076] <artifactid> user< / artifactid>

[0077] <version> 0.0.1-SNAPSHOT< / version>

[0078] <packaging> pom< / packaging>

[0079] < / project> ;

[0080] Among them, the artifactId item is used to describe the module name, collectively referred to as the coordinates, which is proposed to ensure the uniqueness of the project. For interface file packages that belong to different modules from the target method, it is necessary to modify the unique name of the interface file package according to the target dependent party corresponding to the interface file package. For example, if the target dependent party is a-service, the "user" of this item can be changed to "userA-Service". Next, after the interface file package is released, each target dependent party can determine the interface corresponding to the service call requirement through the pom.xml file of its own interface file package, and rely on this interface to implement the service call.

[0081] Alternatively, in the implementation of a service, it is often necessary to access the database and use the data obtained from the database. However, the data displayed on the user page and the data obtained from the database are often quite different. In this case, it is often necessary to send multiple requests to the server to gather the data for display on the page. That is, a data demand may require multiple remote calls to obtain all the required data. Each call requires serialization and deserialization of the return value, which will inevitably reduce the performance of the network. When the client wants to write data to the server, it will also call a method with multiple parameters. When the number of parameters is large, the implementation of the entire method will appear bloated. The Data Transfer Object (DTO) is a solution for exchanging large amounts of data between the client and the server without multiple fine-grained calls, reducing the number of remote calls, and avoiding related network loads.

[0082] Optionally, a DTO class may not only define data transmission methods, but may also be responsible for some other simple methods such as factory methods, dto to do methods, etc. However, these methods are usually not exposed to external calls. Therefore, in order to implement the dependent call of the data transmission method, when implementing other methods, it is necessary to create a separate factory class to convert dto and do, that is, it is impossible to implement data transmission methods and other non-exposed methods in the same DTO class, which limits the use of DTO. In an embodiment of the present application, when there is a data transmission object in the target method, based on the dependency annotation added to the target method that needs to expose the interface, other methods that do not need to be exposed can be automatically isolated, and only the data transmission method corresponding to the data transmission object is determined, and then the interface file package for calling the target method is generated based on the target method and the data transmission method, thus avoiding the use restrictions of multiple functions of DTO.

[0083] In an embodiment of the present application, an interface generation method is provided, which defines a dependency annotation for identifying the dependent party corresponding to the annotated method, and adds a dependency annotation on the target method that needs to be dependent and called, which means that the annotated method is dependent and called by the dependent party identified by the dependency annotation, that is, when all methods are written, compiled and packaged, all interface packages do not need to be defined separately, but are automatically generated, so that the project structure during development will be simpler; at the same time, when the interface method in the program code changes, only the interface packaging tool class needs to be automatically regenerated, without the need for adjustment on the calling side, thereby realizing the program and interface The interface is decoupled from the implementation method and the implementation class; and based on the dependency annotations added to the implementation method and the implementation class, the dependent party that needs to call the target method can be found quickly and conveniently; at the same time, the generation, packaging, and release of the interface file package are synchronized with the generation, packaging, and release of the program's implementation file package, that is, it is imperceptible to the service provider; and when there is a data transmission object in the target method, based on the dependency annotations added to the target method that needs to expose the interface, other methods that do not need to be exposed can be automatically isolated, and only the data transmission method corresponding to the data transmission object is determined, and then the interface file package is generated, avoiding the use restrictions of multiple functions of the data transmission object.

[0084] See also Figure 4 , Figure 4 A structural block diagram of an interface generation device provided in an embodiment of the present application.

[0085] like Figure 4 As shown, the interface generating device 400 includes:

[0086] An annotation definition module 410 is used to define dependency annotations, where dependency annotations are used to identify dependent parties corresponding to annotated methods;

[0087] An annotation adding module 420 is used to determine a target method having a target dependent party, and add a target dependency annotation to the target method according to the target dependent party corresponding to the target method, each target dependency annotation individually identifies a target dependent party of the target method;

[0088] The interface generation module 430 is used to determine the target method with the target dependency annotation added, and generate an interface file package for calling the target method based on the target method.

[0089] Optionally, the interface generation module 430 is also used to generate an interface program code for calling the target method based on the method program code of the target method during the compilation phase of the target method; and to package the interface program code to obtain an interface file package during the packaging phase of the target method.

[0090] Optionally, the interface generation module 430 is also used to create interface files corresponding to each target dependent party during the packaging stage of the target method; add the interface program code corresponding to each target dependent party to the interface file corresponding to each target dependent party, and package each interface file to obtain an interface file package corresponding to each target dependent party.

[0091] Optionally, the interface generation module 430 is also used to create a new project object model file for the interface file corresponding to each target dependent party, and the new project object model file is at least used to describe the construction information and dependency information of the interface file; the interface program code corresponding to each target dependent party and the new project object model file are respectively added to the interface file corresponding to each target dependent party, and each interface file is packaged to obtain an interface file package corresponding to each target dependent party.

[0092] Optionally, the interface generation module 430 is further used to generate a new project object model file of an interface file corresponding to each target dependent party based on the original project object model file of the target method.

[0093] Optionally, the interface generation module 430 is further used to traverse all methods in the abstract tree based on the annotation processing interface to determine the target method with the target dependency annotation added, and the abstract tree is a tree representation of the abstract syntax structure of the program source code.

[0094] Optionally, when there is a data transmission object in the target method, the interface generation module 430 is further used to determine the data transmission method corresponding to the data transmission object, and generate an interface file package for calling the target method based on the target method and the data transmission method.

[0095] In an embodiment of the present application, an interface generation device is provided, wherein an annotation definition module is used to define dependency annotations, and the dependency annotations are used to identify the dependent party corresponding to the annotated method; an annotation adding module is used to determine the target method with the target dependent party, and add the target dependency annotation to the target method according to the target dependent party corresponding to the target method, and each target dependency annotation separately identifies a target dependent party of the target method; an interface generation module is used to determine the target method with the target dependency annotation added, and generate an interface file package for calling the target method based on the target method. Since the dependency annotation for identifying the dependent party corresponding to the annotated method is defined, and the dependency annotation is added to the target method that needs to be relied on and called, it means that the annotated method is relied on and called by the dependent party identified by the dependency annotation, that is, when all methods are written, compiled and packaged, the target method for generating the dependent interface can be directly determined from all methods based on the dependency annotation, and then the interface file package for calling the target method can be automatically generated based on the target method, thereby reducing the human development process of the interface, realizing the automatic generation of the interface file package, and improving the overall efficiency of service development.

[0096] An embodiment of the present application further provides a computer storage medium, which can store multiple instructions, and the instructions are suitable for being loaded by a processor and executing the steps of any method in the above embodiments.

[0097] See also Figure 5 , Figure 5 A schematic diagram of the structure of a terminal provided in an embodiment of the present application. Figure 5 As shown, the terminal 500 may include: at least one terminal processor 501 , at least one network interface 504 , a user interface 503 , a memory 505 , and at least one communication bus 502 .

[0098] The communication bus 502 is used to realize the connection and communication between these components. The user interface 503 may include a display screen (Display), a camera (Camera), and the optional user interface 503 may also include a standard wired interface and a wireless interface. The network interface 504 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).

[0099] Among them, the terminal processor 501 may include one or more processing cores. The terminal processor 501 uses various interfaces and lines to connect various parts in the entire terminal 500, and executes various functions and processes data of the terminal 500 by running or executing instructions, programs, code sets or instruction sets stored in the memory 505, and calling data stored in the memory 505. Optionally, the terminal processor 501 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The terminal processor 501 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communication. It can be understood that the above-mentioned modem may not be integrated into the terminal processor 501, and it can be implemented separately through a chip.

[0100] Among them, the memory 505 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory, ROM). Optionally, the memory 505 includes a non-transitory computer-readable storage medium. The memory 505 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 505 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 505 may also be optionally at least one storage device located away from the aforementioned terminal processor 501. As Figure 5 As shown, the memory 505 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an interface generation program.

[0101] exist Figure 5 In the terminal 500 shown, the user interface 503 is mainly used to provide an input interface for the user and obtain data input by the user; and the terminal processor 501 can be used to call the interface generation program stored in the memory 505 and specifically perform the following operations:

[0102] Define dependency annotations, which are used to identify the dependent parties corresponding to the annotated methods;

[0103] Determine the target method with the target dependent party, add the target dependency annotation to the target method according to the target dependent party corresponding to the target method, and each target dependency annotation separately identifies a target dependent party of the target method;

[0104] Determine the target method with the target dependency annotation added, and generate an interface file package for calling the target method based on the target method.

[0105] In some embodiments, when the terminal processor 501 generates an interface file package for calling a target method based on a target method, it specifically performs the following steps: in the compilation phase of the target method, an interface program code for calling the target method is generated based on the method program code of the target method; in the packaging phase of the target method, the interface program code is packaged to obtain an interface file package.

[0106] In some embodiments, when the terminal processor 501 is executing in the packaging phase of the target method and packaging the interface program code to obtain an interface file package, the following steps are specifically performed: in the packaging phase of the target method, interface files corresponding to each target dependent party are created respectively; the interface program code corresponding to each target dependent party is added to the interface file corresponding to each target dependent party respectively, and each interface file is packaged to obtain an interface file package corresponding to each target dependent party.

[0107] In some embodiments, when the terminal processor 501 executes the steps of adding the interface program code corresponding to each target dependent party to the interface file corresponding to each target dependent party, and packaging each interface file to obtain the interface file package corresponding to each target dependent party, it specifically performs the following steps: creating a new project object model file for the interface file corresponding to each target dependent party, the new project object model file is at least used to describe the construction information and dependency information of the interface file; adding the interface program code corresponding to each target dependent party and the new project object model file to the interface file corresponding to each target dependent party, and packaging each interface file to obtain the interface file package corresponding to each target dependent party.

[0108] In some embodiments, when the terminal processor 501 creates a new project object model file for the interface files corresponding to each target dependent party, it specifically performs the following steps: generating a new project object model file for the interface files corresponding to each target dependent party based on the original project object model file of the target method.

[0109] In some embodiments, when the terminal processor 501 determines the target method with the target dependency annotation added, it specifically performs the following steps: traverses all methods in the abstract tree based on the annotation processing interface, and determines the target method with the target dependency annotation added. The abstract tree is a tree representation of the abstract syntax structure of the program source code.

[0110] In some embodiments, when there is a data transmission object in the target method, the terminal processor 501 specifically performs the following steps when generating an interface file package for calling the target method based on the target method: determining the data transmission method corresponding to the data transmission object, and generating an interface file package for calling the target method based on the target method and the data transmission method.

[0111] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.

[0112] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0113] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The above computer program product includes one or more computer instructions. When the above computer program instructions are loaded and executed on a computer, the above process or function according to the embodiment of this specification is generated in whole or in part. The above computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The above computer instructions can be stored in a computer-readable storage medium or transmitted by the above computer-readable storage medium. The above computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (Digital Subscriber Line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The above computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, data center, etc. that contains one or more available media integrated. The above-mentioned available media can be magnetic media (for example, floppy disks, hard disks, tapes), optical media (for example, digital versatile discs (DVD)), or semiconductor media (for example, solid state drives (SSD)), etc.

[0114] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0115] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0116] The above is a description of an interface generation method, device, storage medium and terminal provided in the present application. For technicians in this field, according to the ideas of the embodiments of the present application, there may be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present application.< / string>

Claims

1. An interface generation method, characterized in that: The method comprises: Define dependency annotations, which are used to identify the dependent party corresponding to the annotated method; Determine a target method having a target dependent party, and add a target dependency annotation to the target method according to the target dependent party corresponding to the target method, each of the target dependency annotations individually identifying a target dependent party of the target method; The target method to which the target dependency annotation is added is determined, and an interface file package for calling the target method is generated based on the target method.

2. The method according to claim 1, characterized in that The generating, based on the target method, an interface file package for calling the target method comprises: In the compilation phase of the target method, an interface program code for calling the target method is generated based on the method program code of the target method; In the packaging phase of the target method, the interface program code is packaged to obtain an interface file package.

3. The method according to claim 2, characterized in that In the packaging stage of the target method, the interface program code is packaged to obtain an interface file package, including: In the packaging phase of the target method, interface files corresponding to each target dependent party are created respectively; The interface program codes corresponding to each target dependent party are added to the interface files corresponding to each target dependent party respectively, and each interface file is packaged to obtain the interface file package corresponding to each target dependent party.

4. The method according to claim 3, characterized in that The interface program codes corresponding to each target relying party are added to the interface files corresponding to each target relying party respectively, and each interface file is packaged to obtain the interface file package corresponding to each target relying party, including: Creating a new project object model file of an interface file corresponding to each target dependent party, wherein the new project object model file is used to describe at least the construction information and dependency information of the interface file; The interface program code corresponding to each target dependent party and the newly created project object model file are respectively added to the interface file corresponding to each target dependent party, and each interface file is packaged to obtain the interface file package corresponding to each target dependent party.

5. The method according to claim 4, characterized in that The new project object model file for creating the interface files corresponding to each target relying party includes: A new project object model file of an interface file corresponding to each target dependent party is generated based on the original project object model file of the target method.

6. The method according to claim 1, characterized in that The determining the target method to which the target dependency annotation is added includes: Based on the annotation processing interface, all methods in the abstract tree are traversed to determine the target method to which the target dependency annotation is added, and the abstract tree is a tree representation of the abstract syntax structure of the program source code.

7. The method according to claim 1, characterized in that When there is a data transfer object in the target method, generating an interface file package for calling the target method based on the target method includes: The data transmission method corresponding to the data transmission object is determined, and an interface file package for calling the target method is generated based on the target method and the data transmission method.

8. An interface generation device, characterized in that: The device comprises: An annotation definition module is used to define dependency annotations, where the dependency annotations are used to identify the dependent party corresponding to the annotated method; An annotation adding module is used to determine a target method having a target dependent party, and add a target dependency annotation to the target method according to the target dependent party corresponding to the target method, each of the target dependency annotations separately identifies a target dependent party of the target method; The interface generation module is used to determine the target method with the target dependency annotation added, and generate an interface file package for calling the target method based on the target method.

9. A computer storage medium, characterized in that: The computer storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the steps of the method according to any one of claims 1 to 7.

10. A terminal, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 7 when executing the program.