Model access method and device, storage medium and computer device
By combining RESTful interfaces and reflection mechanisms, a unified interface for model access is achieved, solving the problems of scattered and complex model access interfaces, and improving development efficiency and code reusability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- YGSOFT INC
- Filing Date
- 2021-12-31
- Publication Date
- 2026-05-05
AI Technical Summary
In existing technologies, the interfaces for accessing models are scattered and complex to extend, resulting in low development efficiency.
By receiving access requests through a RESTful interface and using reflection to invoke business capabilities in the target model, a unified model access method is achieved, enabling dynamic invocation of the model's business capabilities.
It reduces the number of interfaces when extending the model, improves development efficiency, ensures code reuse, and simplifies the model extension process.
Smart Images

Figure CN114357334B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and more particularly to a method, apparatus, storage medium, and computer device for accessing a model. Background Technology
[0002] In the functional development phase of model-based software development, there is a problem with model access. Model access is typically involved in the functional development phase of model-based software, where a set of interfaces is used to provide the model's business capabilities. If the model adds new business capabilities, new interfaces need to be added accordingly, leading to problems such as scattered model interfaces and complex expansion capabilities. Summary of the Invention
[0003] This application provides a method, apparatus, storage medium, and computer device for accessing models, which can solve the problem of complex operation when expanding the business capabilities of models in the prior art. The technical solution is as follows:
[0004] In a first aspect, embodiments of this application provide a method for accessing a model, the method comprising:
[0005] Access requests are received via a RESTful interface; the access request carries the user identifier, model name, business capability name, and business parameters.
[0006] The target model is determined from the model set based on the model name; wherein multiple models in the model set share the RESTful interface;
[0007] Using reflection, the class object indicated by the business capability name is invoked in the target model;
[0008] Return the call result obtained by the class object in response to the business parameters to the user indicated by the user identifier.
[0009] Secondly, embodiments of this application provide a model access device, the device comprising:
[0010] The transceiver unit is used to receive access requests through a RESTful interface; wherein the access request carries a user identifier, a model name, a business capability name, and business parameters.
[0011] A determining unit is used to determine a target model in a model set based on the model name; wherein multiple models in the model set share the RESTful interface;
[0012] A reflection unit is used to invoke the class object indicated by the business capability name in the target model using a reflection mechanism.
[0013] The transceiver unit is also configured to return the call result obtained by the class object in response to the business parameters to the user indicated by the user identifier.
[0014] Thirdly, embodiments of this application provide a computer storage medium storing a plurality of instructions adapted for loading by a processor and executing the above-described method steps.
[0015] Fourthly, embodiments of this application provide a computer device, which may include: a processor and a memory; wherein the memory stores a computer program, the computer program being adapted to be loaded by the processor and to execute the above-described method steps.
[0016] The beneficial effects of the technical solutions provided in some embodiments of this application include at least the following:
[0017] This application provides a unified RESTful interface to expose the model's business capabilities. When invoking these capabilities, the access request passes the model name, business capability name, and business parameters. The system dynamically invokes the model's business capabilities based on reflection, thus enabling access to these capabilities. When adding a new model or a new business capability, the model has exactly one RESTful interface. Therefore, this application enables extended development based on model business capabilities, avoiding the need to configure a separate RESTful interface for each new business capability. This saves time in model development and extension, prevents the addition of numerous interfaces during model expansion, improves development efficiency, and ensures code reusability. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a schematic diagram of the network architecture provided in the embodiments of this application;
[0020] Figure 2 This is a flowchart illustrating the model access method provided in the embodiments of this application;
[0021] Figure 3 This is a schematic diagram of the model set provided in the embodiments of this application;
[0022] Figure 4 This is a schematic diagram of the structure of an access device for a model provided in this application;
[0023] Figure 5This is a schematic diagram of the structure of a computer device provided in this application. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0025] It should be noted that the model access method provided in this application is generally executed by computer equipment, and correspondingly, the model access device is generally set in the computer equipment.
[0026] Figure 1 An exemplary system architecture is shown for an access method or access device for a model that can be applied to the model described in this application.
[0027] like Figure 1 As shown, the system architecture may include a computer device 101 and a server 102. The computer device 101 and the server 102 can communicate via a network, which serves as the medium for providing communication links between the various units. The network may include various types of wired or wireless communication links, such as wired communication links including fiber optic cables, twisted-pair cables, or coaxial cables, and wireless communication links including Bluetooth communication links, Wi-Fi communication links, or microwave communication links.
[0028] Server 102 is equipped with a distributed cache, which stores a model collection containing multiple models. This model collection is managed by a model manager. Computer device 101 can invoke the business capabilities of each model based on the RESTful interface provided by the model collection.
[0029] It should be noted that computer device 101 and server 102 can be either hardware or software. When computer device 101 and server 102 are hardware, they can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When computer device 101 and server 102 are software, they can be implemented as multiple software programs or software modules (e.g., used to provide distributed services), or as a single software program or software module; no specific limitations are made here.
[0030] The computer device described in this application can be equipped with various communication client applications, such as video recording applications, video playback applications, voice interaction applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0031] Computer devices can be either hardware or software. When a computer device is hardware, it can be any computer device with a display screen, including but not limited to smartphones, tablets, laptops, and desktop computers. When a computer device is software, it can be installed on the computer devices listed above. It can be implemented as multiple software programs or software modules (e.g., used to provide distributed services) or as a single software program or software module; no specific limitation is made here.
[0032] When a computer device is used as hardware, it can also be equipped with a display device and a camera. The display device can be any device capable of displaying information, and the camera is used to capture video streams. Examples of display devices include cathode ray tube displays (CR), light-emitting diode displays (LED), e-ink screens, liquid crystal displays (LCD), and plasma display panels (PDP). Users can utilize the display device on their computer to view displayed text, images, videos, and other information.
[0033] It should be understood that Figure 1 The number of computer devices, networks, and servers shown is for illustrative purposes only. The number of computer devices, networks, and servers can be any number, depending on the implementation requirements.
[0034] The following will be combined with the appendix Figure 2 This application provides a detailed description of the model access method provided in the embodiments. The model access device in the embodiments of this application can be... Figure 1 The computer equipment shown.
[0035] Please see Figure 2 This is a flowchart illustrating a method for accessing a model, as provided in an embodiment of this application. Figure 2 As shown, the method described in this application embodiment may include the following steps:
[0036] S201. Receive access requests through the RESTful interface.
[0037] Among them, the access request is used to access the business capabilities of the model, and the business capabilities are provided by the class objects in the model. The model is an instance that provides business capabilities externally. The model provides business capabilities externally through a uniformly set restful interface. For example: The business model is set with user data, and it provides business capabilities such as adding users, deleting users, or modifying users externally. The data structure of the model is customized. The access request carries a user identifier, a model name, a business capability name, and business parameters. The user identifier represents the identity of the user who发起 the access request. The model name represents the name of the target model to be called. The business capability name represents the name of the class object included in the target model to be called. The business parameters represent the fields and attribute values passed to the class object. The format of the access request can be URL (Uniform Resource Locator).
[0038] For example: When requesting the business capability of adding a user to the model, the access request is expressed as {vipAddress} / sv / model / system_user / saveReturn, and the business parameters carried by the access request are expressed as: {"username":"张三","gid":"afadccdc525856522060f9b9c9362a3b","sex":1}; where, system_user represents the model name, and saveReturn represents the business capability name.
[0039] In one or more possible embodiments, before S201, the computer device creates a model and adds the created model to the model set. The creation method can be:
[0040] Configure the attribute information of the model; where, the attribute information includes: model name, category, entity attribution, type ID, and type name;
[0041] Based on the model configuration page, configure the model item information of the model in an itemized manner and store the model item information in the database; where, the model configuration page includes a model item table, and one row of each model item table is an item. The user can perform interaction operations on the model configuration page to add items, delete items, modify items, or adjust the positions of items in the model item table.
[0042] Based on the business capability extension page, model capability extension information is configured in an itemized manner, and this information is stored in the database. The business capability extension page includes an extension information table, where each row represents an entry, and each entry corresponds to a business capability. Users can perform interactive operations on the model configuration page to add, delete, modify, or adjust the position of entries in the model item table, thereby extending business capabilities. The model is then added to the model collection belonging to the model manager.
[0043] S202. Determine the target model from the model set based on the model name.
[0044] The model set includes multiple models, each with a different model name. The target model is determined from among the multiple models based on the model name parsed in S201. All models have a unified RESTful interface deployed.
[0045] For example, the model collection is managed by the model manager. The model collection contains model A (model name A) and model B (model name B). Both model A and model B can provide the business capabilities of adding, updating, querying, and deleting user information. The model manager receives access requests from visitors, parses them to obtain the model name A, and determines model A as the target model in the model collection.
[0046] In one or more possible embodiments, this application utilizes a whitelist mechanism to verify the identity of the caller, and the verification process includes:
[0047] Determine whether the user identifier is in a preset whitelist. If yes, then execute the step of determining the target model in the model set based on the model name.
[0048] If not, then access is denied to the user indicated by the user identifier, and an access failure response may be returned to that user.
[0049] In one or more possible embodiments, this application performs flow control on the model to improve its response speed. The flow control method includes:
[0050] Monitor the number of access requests on the target model; if the number of access requests exceeds a first threshold, deny access to all users; or
[0051] The number of accesses within a preset time period is counted. If the number of accesses exceeds a second threshold, the user indicated by the user identifier is denied access.
[0052] The computer equipment can periodically monitor or count the number of access requests and accesses. The size of the first and second quantity thresholds can be determined according to actual needs, and this application does not impose any restrictions.
[0053] S203. Using reflection, call the class object indicated by the business capability name in the target model.
[0054] Reflection, in this context, refers to a program's ability to obtain information about itself at runtime. In Java, given the name of a class object, reflection allows you to obtain all its information—dynamically retrieving a specified class object and dynamically accessing its contents. This application invokes the class object indicated by the business capability name while the class object is in a running state. For example, based on the example in S201, the determined class objects are `BizEntityModelManager` and `saveReturn`, and the fields and attribute values included in the business parameters are passed into the class object.
[0055] S204. Return the call result obtained from the business parameters to the user class object indicated by the user identifier.
[0056] In this process, the class object retrieves business parameters during runtime, obtains the call result based on the business parameters, and then returns the call result to the caller. Optionally, the individual models in the model collection can be deployed in a distributed cache to improve the model's response speed.
[0057] This application provides a unified RESTful interface to expose the model's business capabilities. When invoking a model's business capabilities, the access request passes the model name, business capability name, and business parameters. The model's business capabilities are dynamically invoked based on reflection, thus enabling access to the model's business capabilities. When adding a new model or a new business capability, the model has exactly one RESTful interface. Therefore, this application enables extended development based on model business capabilities, avoiding the need to configure a separate RESTful interface for each new business capability, saving time in model development and extension, preventing the addition of numerous interfaces during model extension, improving development efficiency, and ensuring code reusability.
[0058] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0059] Please see Figure 4This illustration shows a schematic diagram of the structure of an access device for a model provided in an exemplary embodiment of this application, hereinafter referred to as device 4. Device 4 can be implemented as all or part of a computer device through software, hardware, or a combination of both. Device 4 includes: a transceiver unit 401, a determination unit 402, and a reflection unit 403.
[0060] The transceiver unit 401 is used to receive access requests through a RESTful interface; wherein the access request carries a user identifier, a model name, a business capability name, and business parameters.
[0061] The determining unit 402 is used to determine the target model in the model set according to the model name; wherein, multiple models in the model set share the RESTful interface;
[0062] Reflection unit 403 is used to invoke the class object indicated by the business capability name in the target model using the reflection mechanism;
[0063] The transceiver unit 401 is also used to return the call result obtained by the class object in response to the business parameters to the user indicated by the user identifier.
[0064] In one or more possible embodiments, it also includes:
[0065] A configuration unit is used to configure the attribute information of the model; wherein the attribute information includes: model name, category, entity affiliation, type ID, and type name;
[0066] Based on the model configuration page, the model project information is configured in an itemized manner, and the model project information is stored in the database;
[0067] Based on the business capability extension page, model capability extension information is configured in an itemized manner, and the model capability extension information is stored in the database;
[0068] Add the model to the model collection belonging to the model manager.
[0069] In one or more possible embodiments, it also includes:
[0070] The user verification unit is used to determine whether the user identifier is in a preset whitelist. If yes, the user identifier is used to determine the target model in the model set based on the model name.
[0071] If not, then access is denied to the user indicated by the user identifier.
[0072] In one or more possible embodiments, it also includes:
[0073] A traffic control unit is used to monitor the number of access requests on the target model. If the number of access requests exceeds a first threshold, access from all users is denied; or
[0074] The number of accesses within a preset time period is counted. If the number of accesses exceeds a second threshold, the user indicated by the user identifier is denied access.
[0075] In one or more possible embodiments, the set of models is deployed in a distributed cache.
[0076] It should be noted that the device 4 provided in the above embodiments is only illustrated by the division of the above functional modules when executing the model access method. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the above functions. In addition, the model access device and the model access method embodiments provided in the above embodiments belong to the same concept, and the implementation process is detailed in the method embodiments, which will not be repeated here.
[0077] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0078] This application also provides a computer storage medium that can store multiple instructions, which are adapted to be loaded and executed by a processor as described above. Figure 2 The method steps of the illustrated embodiment can be found in the following documentation for detailed execution. Figure 2 The specific details of the illustrated embodiments will not be elaborated here.
[0079] This application also provides a computer program product that stores at least one instruction, which is loaded and executed by the processor to implement the access method of the model as described in the above embodiments.
[0080] Please see Figure 5 This document provides a schematic diagram of the structure of a computer device according to an embodiment of this application. Figure 5 As shown, the computer device 500 may include: at least one processor 501, at least one network interface 504, user interface 503, memory 505, and at least one communication bus 502.
[0081] The communication bus 502 is used to enable communication between these components.
[0082] The user interface 503 may include a display screen and a camera. Optionally, the user interface 503 may also include a standard wired interface and a wireless interface.
[0083] The network interface 504 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0084] The processor 501 may include one or more processing cores. The processor 501 connects to various parts within the terminal 500 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 505, and by calling data stored in the memory 505. Optionally, the processor 501 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 501 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also be implemented as a separate chip without being integrated into the processor 501.
[0085] The memory 505 may include random access memory (RAM) or read-only memory. Optionally, the memory 505 may include a non-transitory computer-readable storage medium. The memory 505 can be used to store instructions, programs, code, 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 touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 505 may also be at least one storage device located remotely from the aforementioned processor 501. Figure 5 As shown, the memory 505, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and application programs.
[0086] exist Figure 5 In the computer device 500 shown, the user interface 503 is mainly used to provide an input interface for the user and to obtain the user's input data; while the processor 501 can be used to call the application program stored in the memory 505 and specifically execute, such as Figure 2 The method shown can be referred to for details. Figure 2 As shown, it will not be elaborated further here.
[0087] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory, or random access memory, etc.
[0088] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A method for accessing a model, characterized in that, include: Access requests are received through a RESTful interface; the access request carries a user identifier, model name, business capability name, and business parameters; the access request is used to access the business capabilities of the model, and the business capabilities are provided by class objects in the model; The target model is determined from the model set based on the model name; wherein, multiple models in the model set share the RESTful interface; each model in the model set can provide the business capabilities of adding user information, updating user information, querying user information, and deleting user information; Using reflection, the class object indicated by the business capability name is invoked in the target model. The reflection mechanism refers to the ability of the program to obtain its own information at runtime, that is, the reflection mechanism invokes the class object indicated by the business capability name when the class object is in the running state. Return the call result obtained by the class object in response to the business parameters to the user indicated by the user identifier; The access method also includes: Configure the model's attribute information; wherein, the attribute information includes: model name, category, entity affiliation, type ID, and type name; Based on the model configuration page, the model project information is configured in an itemized manner, and the model project information is stored in the database; Based on the business capability extension page, model capability extension information is configured in an itemized manner, and the model capability extension information is stored in the database; Add the model to the model collection belonging to the model manager.
2. The method according to claim 1, characterized in that, Also includes: Determine whether the user identifier is in a preset whitelist. If yes, then execute the step of determining the target model in the model set based on the model name. If not, then access is denied to the user indicated by the user identifier.
3. The method according to claim 2, characterized in that, Also includes: Monitor the number of access requests on the target model. If the number of access requests exceeds a first threshold, then deny access to all users. or The system counts the number of accesses within a preset time period. If the number of accesses exceeds a second threshold, the user indicated by the user identifier is denied access.
4. The method according to claim 1, characterized in that, The model set is deployed in a distributed cache.
5. A model access device, characterized in that, include: The transceiver unit is used to receive access requests through a RESTful interface; wherein, the access request carries a user identifier, model name, business capability name, and business parameters; the access request is used to access the business capabilities of the model, and the business capabilities are provided by class objects in the model; A determining unit is used to determine a target model in a model set based on the model name; wherein multiple models in the model set share the RESTful interface; A reflection unit is used to invoke the class object indicated by the business capability name in the target model using a reflection mechanism. The reflection mechanism refers to the ability of a program to obtain its own information at runtime, that is, the reflection mechanism invokes the class object indicated by the business capability name when the class object is in a running state. The transceiver unit is also configured to return the call result obtained by the class object in response to the business parameters to the user indicated by the user identifier; The access device further includes: A configuration unit is used to configure the attribute information of the model; wherein the attribute information includes: model name, category, entity affiliation, type ID, and type name; Based on the model configuration page, the model project information is configured in an itemized manner, and the model project information is stored in the database; Based on the business capability extension page, model capability extension information is configured in an itemized manner, and the model capability extension information is stored in the database; Add the model to the model collection belonging to the model manager.
6. The apparatus according to claim 5, characterized in that, Also includes: The user verification unit is used to determine whether the user identifier is in a preset whitelist. If yes, the user identifier is used to determine the target model in the model set based on the model name. If not, then access is denied to the user indicated by the user identifier.
7. A computer storage medium, characterized in that, The computer storage medium stores a plurality of instructions, which are adapted to be loaded by a processor and executed as method steps as claimed in any one of claims 1 to 4.
8. A computer device, characterized in that, include: A processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and executed the method steps as claimed in any one of claims 1 to 4.
Citation Information
Patent Citations
Interface information generation method and apparatus, computer device, and storage medium
CN109542412A
Platform login method, device and equipment and computer readable storage medium
CN111355730A