CN-114357334-B - Model access method and device, storage medium and computer equipment
Abstract
The embodiment of the application discloses a method and a device for accessing a model, a storage medium and computer equipment, and relates to the field of computers. The method comprises the steps of receiving an access request through a restful interface, wherein the access request carries a user identifier, a model name, a service capability name and a service parameter, determining a target model in a model set according to the model name, enabling a plurality of models in the model set to share the restful interface, calling a class object indicated by the service capability name in the target model by utilizing a reflection mechanism, and returning a calling result, obtained by the class object in response to the service parameter, to a user indicated by the user identifier.
Inventors
- CHEN WEIMIN
- BI WEI
- GUO HUA
- Wu Renqiao
- QIU YUFENG
- YU XIA
- LI CHUANZHENG
Assignees
- 远光软件股份有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20211231
Claims (8)
- 1. A method for accessing a model, comprising: Receiving an access request through a restful interface, wherein the access request carries a user identifier, a model name, a service capability name and a service parameter, and the access request is used for accessing the service capability of the model, and the service capability is provided by a class object in the model; Determining a target model in a model set according to the model name; each model in the model set can provide service capability of adding user information, updating user information, inquiring user information and deleting user information; calling the class object indicated by the service capability name in the target model by using a reflection mechanism, wherein the reflection mechanism refers to the class object indicated by the service capability name, which can be called by the reflection mechanism when the program can acquire the information of the program when the program runs, namely when the class object is in a running state; Returning a calling result obtained by the class object in response to the service parameter to the user indicated by the user identifier; the access method further comprises the following steps: configuring attribute information of a model, wherein the attribute information comprises a model name, a category, an entity attribution, a type ID and a type name; configuring model item information of a model in an item mode based on a model configuration page, and storing the model item information into a database; Configuring model capability extension information in an item mode based on a service capability extension page, and storing the model capability extension information into the database; the model is added to the set of models to which the model manager belongs.
- 2. The method as recited in claim 1, further comprising: Judging whether the user identifier is positioned in a preset white list, if so, executing the step of determining a target model in a model set according to the model name; if not, rejecting the user indicated by the user identification to access.
- 3. The method as recited in claim 2, further comprising: Monitoring the number of access requests on the target model, rejecting access to all users if the number of access requests is greater than a first number threshold, or And counting the access times in a preset time period, and refusing the user indicated by the user identifier to access if the access times are larger than a second number threshold.
- 4. The method of claim 1, wherein the set of models is deployed in a distributed cache.
- 5. An access device for a model, comprising: the system comprises a receiving and transmitting unit, a service request processing unit and a service request processing unit, wherein the receiving and transmitting unit is used for receiving an access request through a restful interface, and the access request carries a user identifier, a model name, a service capability name and a service parameter; the determining unit is used for determining a target model in a model set according to the model name, wherein a plurality of models in the model set share the restful interface; The reflecting unit is used for calling the class object indicated by the service capability name in the target model by utilizing a reflecting mechanism, wherein the reflecting mechanism refers to the class object indicated by the service capability name, and the program can acquire the information of the reflecting mechanism when running, namely the reflecting mechanism calls the class object indicated by the service capability name when the class object is in a running state; The receiving and transmitting unit is further configured to return a calling result obtained by the class object in response to the service parameter to the user indicated by the user identifier; The access device further includes: The configuration unit is used for configuring attribute information of the model, wherein the attribute information comprises a model name, a category, an entity attribution, a type ID and a type name; configuring model item information of a model in an item mode based on a model configuration page, and storing the model item information into a database; Configuring model capability extension information in an item mode based on a service capability extension page, and storing the model capability extension information into the database; the model is added to the set of models to which the model manager belongs.
- 6. The apparatus as recited in claim 5, further comprising: The user verification unit is used for judging whether the user identifier is positioned in a preset white list, if so, executing the process of determining a target model in a model set according to the model name; if not, rejecting the user indicated by the user identification to access.
- 7. A computer storage medium storing a plurality of instructions adapted to be loaded by a processor and to perform the method steps of any one of claims 1 to 4.
- 8. A computer device comprising a processor and a memory, wherein the memory stores a computer program adapted to be loaded by the processor and to perform the method steps of any of claims 1-4.
Description
Model access method and device, storage medium and computer equipment Technical Field The present application relates to the field of computers, and in particular, to a method and apparatus for accessing a model, a storage medium, and a computer device. Background In the functional development link of software development based on the model, the problem of model access realization is solved. The link of software function research and development based on the model generally involves model access, and service capability of the model is provided outwards through a set of interfaces. If the model is added with new service capability, a new interface needs to be correspondingly added, so that the problem that the interfaces of the model are scattered and expanded more complex exists. Disclosure of Invention The embodiment of the application provides a method and a device for accessing a model, a storage medium and computer equipment, which can solve the problem of complex operation when the service capability of the model is expanded in the prior art. The technical scheme is as follows: In a first aspect, an embodiment of the present application provides a method for accessing a model, where the method includes: receiving an access request through a restful interface, wherein the access request carries a user identifier, a model name, a service capability name and a service parameter; Determining a target model in a model set according to the model name, wherein a plurality of models in the model set share the restful interface; Invoking the class object indicated by the business capability name in the target model by using a reflection mechanism; And returning a calling result obtained by the class object in response to the service parameter to the user indicated by the user identifier. In a second aspect, an embodiment of the present application provides an access apparatus for a model, where the apparatus includes: the receiving and transmitting unit is used for receiving the access request through the restful interface; the access request carries a user identifier, a model name, a service capability name and a service parameter; the determining unit is used for determining a target model in a model set according to the model name, wherein a plurality of models in the model set share the restful interface; the reflecting unit is used for calling the class object indicated by the service capability name in the target model by utilizing a reflecting mechanism; and the receiving and transmitting unit is also used for returning a calling result obtained by the class object in response to the service parameter to the user indicated by the user identifier. In a third aspect, embodiments of the present application provide a computer storage medium storing a plurality of instructions adapted to be loaded by a processor and to perform the above-described method steps. In a fourth aspect, embodiments of the present application provide a computer device, which may comprise a processor and a memory, wherein the memory stores a computer program adapted to be loaded by the processor and to perform the above-described method steps. The technical scheme provided by the embodiments of the application has the beneficial effects that at least: The service capability of the model is provided outwards through providing a unified restful interface, and when the service capability of the model is called, the service capability of the model is dynamically called based on a reflection mechanism through accessing the name of the request incoming model, the name of the service capability and the service parameters, so that the access of the service capability of the model is realized. The application adds new model or adds new business ability, the number of restful interfaces of model is 1. Therefore, the application can realize the expansion development based on the model service capability, avoid configuring a restful interface for each new service capability, save the time of model development and expansion links, avoid increasing a large number of interfaces for model expansion, improve the development efficiency and ensure code multiplexing. Drawings In order to more clearly illustrate the embodiments of the application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art. Fig. 1 is a schematic diagram of a network architecture according to an embodiment of the present application; FIG. 2 is a flow chart of a method for accessing a model provided by an embodiment of the present application; FIG. 3 is a schematic diagram of a model set provided by an embodiment of the present application; FIG. 4