Software development method and device based on response processing, equipment, medium and product
By providing a response processing annotation plug-in, the writing of exception response processing code in Spring Boot interface development is simplified, the problem of inefficient development is solved, and a more efficient development process and a more unified response processing is achieved.
Patent Information
- Application Number
- CN202411605396.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-11
- Publication Date
- 2025-02-25
Smart Images

Figure CN119512539A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software development, and in particular to a software development method, apparatus, device, medium and product based on response processing. Background Art
[0002] Spring Boot is an open source Java framework. Currently, when using Spring Boot for interface development, developers are required to manually write interface-related exception response processing code, which often results in too much code and low development efficiency. Summary of the invention
[0003] The embodiments of the present application provide a software development method, apparatus, device, medium and product based on response processing, which simplifies coding operations and improves development efficiency.
[0004] In a first aspect, an embodiment of the present application provides a software development method based on response processing, comprising:
[0005] Obtain a response processing annotation plug-in; the response processing annotation plug-in is obtained by encapsulating a response processing annotation, a unified exception response class, a unified exception response class with data, a unified response class, and an annotation processor;
[0006] The response processing annotation plug-in is introduced into the target development project so that developers can use the response processing annotation plug-in to write codes related to the target development project.
[0007] In a possible implementation, it further includes:
[0008] Define response processing annotations;
[0009] Define unified exception response class, unified exception response class with data, and unified response class;
[0010] Writing annotation processors;
[0011] The response processing annotation, the unified exception response class, the unified exception response class with data, the unified response class and the annotation processor are encapsulated into a response processing annotation plug-in.
[0012] In a possible implementation, the unified exception response class inherits from the RuntimeException standard class of SpringBoot; and includes the following multiple reconstruction functions:
[0013] The first exception response message format is used to return an error message;
[0014] The second exception response message format is used to return an error code and an error message;
[0015] The third exception response message format is used to return error messages and error causes;
[0016] The fourth exception response message format is used to return an error code, an error message, and an error cause.
[0017] In a possible implementation, the unified exception response class with data inherits from the unified exception response class and includes the following multiple reconstruction functions:
[0018] The fifth exception response message format is used to return error messages and data;
[0019] The sixth exception response message format is used to return an error code, an error message, and data;
[0020] The seventh abnormal response message format is used to return an error message, an error cause, and data;
[0021] The eighth exception response message format is used to return an error code, an error message, an error cause, and data.
[0022] In a possible implementation, the unified response class includes the following multiple functions:
[0023] A first static exception class, and the exception class thrown by the first static exception class is the unified exception response class;
[0024] A second static exception class, and the exception class thrown by the second static exception class is the unified exception response class with data;
[0025] A first static assertion enhanced reconstruction function, wherein the input parameter of the first static assertion enhanced reconstruction function is the expression to be verified, and the exception type thrown is a unified exception response class of the third exception response message format;
[0026] A second static assertion enhanced reconstruction function, wherein the input parameters of the second static assertion enhanced reconstruction function are an expression to be verified and an error code, and the exception type thrown is a unified exception response class in the fourth exception response message format;
[0027] A third custom static assertion enhanced reconstruction function, wherein the input parameters of the third static assertion enhanced reconstruction function are the expression to be verified, the error code, and the data, and the exception type thrown is a unified exception response class with data in the eighth exception response message format.
[0028] In a possible implementation, it further includes:
[0029] Launching a target application built by the target development project;
[0030] During the loading and initialization process of the inversion of control container, the response processing annotation plug-in is loaded, and the unified exception response class, the unified exception response class with data, and the implementation class objects corresponding to the unified response class are injected into the target application;
[0031] During the operation of the target application, response processing is performed through the response processing annotation plug-in.
[0032] In a possible implementation, the performing response processing by the response processing annotation plug-in during the running of the target application includes at least one of the following:
[0033] In response to the business request message of the front-end service caller, the return message is encapsulated and processed by the response processing annotation plug-in, and returned to the front-end service caller in a preset format;
[0034] In response to the business processing exception message of the front-end service caller, the exception return message is encapsulated and processed by the response processing annotation plug-in, and returned to the front-end service caller in a preset format.
[0035] In a possible implementation manner, before loading the response processing annotation plug-in, the method further includes:
[0036] Read the automatic configuration information and instantiate the read automatic configuration information into the core configuration class.
[0037] In a second aspect, an embodiment of the present application provides a software development device based on response processing, including:
[0038] Obtain a response processing annotation plug-in; the response processing annotation plug-in is obtained by encapsulating a response processing annotation, a unified exception response class, a unified exception response class with data, a unified response class, and an annotation processor;
[0039] The response processing annotation plug-in is introduced into the target development project so that developers can use the response processing annotation plug-in to write codes related to the target development project.
[0040] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory, a processor;
[0041] The memory stores computer-executable instructions;
[0042] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the above first aspect and / or various possible implementations of the first aspect.
[0043] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the first aspect above and / or various possible implementations of the first aspect.
[0044] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the above first aspect and / or various possible implementation methods of the first aspect.
[0045] The software development method, apparatus, device, medium and product based on response processing provided in the embodiments of the present application provide an annotation plug-in for response processing, which encapsulates response processing annotations, unified exception response classes, unified exception response classes with data, unified response classes and annotation processors, and can implement functions such as response processing and exception response processing. During the project development process, developers can directly use the annotation plug-in for coding, thereby simplifying the coding operation and improving development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0047] Figure 1 A schematic diagram of an application scenario provided for this application;
[0048] Figure 2 Schematic diagram of the software development method based on response processing provided for this application Figure 1 ;
[0049] Figure 3 Schematic diagram of the software development method based on response processing provided for this application Figure 2 ;
[0050] Figure 4 Schematic diagram of the software development method based on response processing provided for this application Figure 3 ;
[0051] Figure 5 A schematic diagram of the structure of a software development device based on response processing provided by this application;
[0052] Figure 6 A schematic diagram of the structure of the electronic device provided in this application.
[0053] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0054] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0055] Java: An object-oriented programming language.
[0056] Spring Boot is an open source Java framework. Currently, when using Spring Boot for interface development, developers are required to manually write interface-related exception response processing code, such as code for capturing exceptions and encapsulating execution results. There is often a problem of too much code, resulting in low development efficiency.
[0057] Based on this, the present application proposes a software development method, device, equipment, medium and product based on response processing, aiming to solve the above technical problems.
[0058] Figure 1 is a schematic diagram of an application scenario provided by this application. Figure 1 As shown, the application scenario includes: a user terminal 10 and a server 20. Each device is connected via a network.
[0059] Among them, the user terminal 10 is a terminal device used by developers. Exemplarily, the terminal device can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited to this. In the present application, the developer uses the user terminal 10 to develop software and deploys the developed application to the server 20. Exemplarily, the server 20 can be an independent physical server, or it can be a cloud server that provides cloud computing services, a cloud database, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms. The server 20 can be the background server of the above-mentioned application, used to provide background services for the client of the application.
[0060] The present application provides a response processing annotation plug-in. Accordingly, the present application involves three processes: a plug-in generation process, a project coding process, and an application running process. The plug-in generation process refers to the process of generating a response processing annotation plug-in, the project coding process refers to the process of encoding a target development project using a response processing annotation plug-in, and the application running process refers to the running process of a target application constructed by a target development project, and the response processing annotation plug-in is used to perform response processing during the running process. Optionally, the application running process can be either a software testing scenario or a real production scenario.
[0061] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0062] Figure 2 Schematic diagram of the software development method based on response processing provided for this application Figure 1 ,like Figure 2 As shown, the method specifically relates to a project encoding process and is applied to an electronic device, which is specifically provided as a terminal device. The method includes:
[0063] Step S101, obtaining a response processing annotation plug-in; the response processing annotation plug-in is obtained by encapsulating a response processing annotation, a unified exception response class, a unified exception response class with data, a unified response class and an annotation processor.
[0064] Among them, the response processing annotation plug-in is used for response processing. It can be understood that response processing includes normal response processing and abnormal response processing. Optionally, the generation process of the response processing annotation plug-in is as follows Figure 3 The illustrated embodiment will not be described in detail here. Exemplarily, the response processing annotation plug-in is a jar dependency package.
[0065] Step S102, introducing the response processing annotation plug-in into the target development project, so that the developer can use the response processing annotation plug-in to write codes related to the target development project.
[0066] The target development project is a Spring Boot project, which refers to a software project built on the Spring Boot framework and includes source code, configuration files, dependency libraries, build scripts, etc. During the software development phase, developers will write code, configure applications, add dependencies, etc. in the target development project.
[0067] Optionally, in the Project Object Model (POM) dependency management file of the target development project, introduce the response processing annotation plug-in.
[0068] In actual applications, when coding, the response processing annotation plug-in is referenced in the SpringBoot startup class; in the control layer (Controller), by referencing the response processing annotation plug-in, when the application is running, the response processing annotation plug-in will automatically complete the encapsulation operation, so that developers no longer need to manually write the relevant code of "encapsulating the query results in the returned message", but only need to write the relevant code of "returning the actual results", thereby reducing coding operations and improving development efficiency.
[0069] For example, when the application is running, after receiving the HTTP request, the Controller layer uses the "get" method to receive the parameters in the HTTP request, and returns a MyInfoView object containing the parameters and the corresponding name. No encapsulation operation is performed, but after being processed by the response processing annotation plug-in @MyResponse, the encapsulated response result is obtained.
[0070] For example, at the service layer (Service), when writing code, developers can directly introduce a response processing annotation plug-in on each interface service, with the input parameters being a user-defined error code and the corresponding error information description. Users do not need to maintain the return response code and error message, but only need to write the relevant code of "throwing business exceptions". When the application is running, the response processing annotation plug-in will automatically associate the error code and error message.
[0071] In related technologies, when developers define methods in the Service layer, in order to return error codes in the interface, they often directly define the Service layer methods as Response, which drowns the normal return value of the method and the encoding method is not standardized. The response processing annotation plug-in @MyResponse provided in this application introduces a custom annotation @ExceptionMapping, which associates exceptions and error codes through the response processing annotation plug-in. In this way, the Service method no longer needs to maintain the response code of Response, and directly throws a business exception, and @MyResponse associates the exception with the response code.
[0072] For example, @ExceptionMapping is used as follows:
[0073] @ExceptionMapping(code = "1001", msg = "The requested object does not exist")
[0074] public class NotFoundException extends RuntimeException {}
[0075] Among them, the definition of NotFoundException is modified by @ExceptionMapping annotation; code represents the exception code of the interface; msg represents the exception prompt of the interface.
[0076] Correspondingly, when the queryUser method of the Service layer throws NotFoundException, @MyResponse will capture the exception and encapsulate the exception code and exception information corresponding to NotFoundException into a unified response object. The final interface returns the following JSON format information:
[0077] {
[0078] "status": {
[0079] "code": "1001",
[0080] "msg": "The requested object does not exist"
[0081] },
[0082] "payload": {}
[0083] }
[0084] This embodiment provides an annotation plug-in for response processing, which encapsulates response processing annotations, unified exception response classes, unified exception response classes with data, unified response classes, and annotation processors, and can implement functions such as response processing and exception response processing. During the project development process, developers can directly use the annotation plug-in for coding, thereby simplifying the coding operation and improving development efficiency.
[0085] Figure 3 Schematic diagram of the software development method based on response processing provided for this application Figure 2 ,like Figure 3 As shown, in this embodiment Figure 2 Based on the embodiment, the generation process of the response processing annotation plug-in is described in detail, and the method includes:
[0086] Step S201, define response processing annotations.
[0087] The response processing annotation is a custom annotation defined according to business requirements. The response processing annotation can contain multiple attributes to pass additional information to the annotation processor.
[0088] Step S202, define a unified exception response class, a unified exception response class with data, and a unified response class.
[0089] In a possible implementation, the unified exception response class inherits from the RuntimeException standard class of SpringBoot; and includes the following multiple reconstruction functions:
[0090] The first exception response message format is used to return an error message;
[0091] The second exception response message format is used to return an error code and an error message;
[0092] The third exception response message format is used to return error messages and error causes;
[0093] The fourth exception response message format is used to return an error code, an error message, and an error cause.
[0094] The reconstructed function refers to a function with the same function name but different number or type of input parameters.
[0095] In a possible implementation, the unified exception response class with data inherits from the unified exception response class and includes the following multiple reconstruction functions:
[0096] The fifth exception response message format is used to return error messages and data;
[0097] The sixth exception response message format is used to return an error code, an error message, and data;
[0098] The seventh abnormal response message format is used to return an error message, an error cause, and data;
[0099] The eighth exception response message format is used to return an error code, an error message, an error cause, and data.
[0100] In a possible implementation, the unified response class includes the following multiple functions:
[0101] The first static exception class, and the exception class thrown by the first static exception class is a unified exception response class;
[0102] The second static exception class, and the exception class thrown by the second static exception class is a unified exception response class with data;
[0103] A first static assertion enhanced reconstruction function, wherein the input parameter of the first static assertion enhanced reconstruction function is the expression to be verified, and the exception type thrown is a unified exception response class of the third exception response message format;
[0104] A second static assertion enhanced reconstruction function, wherein the input parameters of the second static assertion enhanced reconstruction function are an expression to be verified and an error code, and the exception type thrown is a unified exception response class in a fourth exception response message format;
[0105] The third custom static assertion enhanced reconstruction function, and the input parameters of the third static assertion enhanced reconstruction function are the expression to be verified, the error code, and the data, and the exception type thrown is a unified exception response class with data in the eighth exception response message format.
[0106] Step S203, writing an annotation processor.
[0107] Among them, the annotation processor is the component that actually processes the response processing annotation logic. Specifically, the annotation processor intercepts the method marked by the response processing annotation and executes the corresponding logic. In Spring Boot, aspect-oriented programming (AOP) is usually used to write annotation processors.
[0108] Step S204, encapsulating the response processing annotation, the unified exception response class, the unified exception response class with data, the unified response class and the annotation processor into a response processing annotation plug-in.
[0109] Optionally, compile the response processing annotation code and generate a jar dependency package to obtain a response processing annotation plug-in.
[0110] By encapsulating the response processing annotations and annotation processors into an independent module or library for reference by other projects, other developers can simply introduce the response processing annotation plug-in and use the functions provided by the response processing annotation plug-in in their own development projects.
[0111] This embodiment encapsulates all related classes and annotation processors in a jar dependency package, which can ensure their consistency and compatibility when used. Developers only need to introduce one jar dependency package to use all functions without having to introduce multiple dependencies separately.
[0112] It should be noted that if some projects only need to use response classes without annotation processors, or vice versa, the required parts can be selectively introduced. Specifically, different components can be modularized as needed to reduce unnecessary dependencies.
[0113] It should be noted that if the unified exception response class, the unified exception response class with data, and the unified response class are not encapsulated together, that is, if these classes and the annotation processor are not encapsulated together, the dependencies between these classes and the annotation processor need to be manually managed in the project to ensure that these dependencies are correctly configured in the project's build tool. And the annotation processor needs to be able to access these response classes so that they can be used when generating code. This means that at compile time, the annotation processor must be able to find these classes.
[0114] Figure 4 Schematic diagram of the software development method based on response processing provided for this application Figure 3 ,like Figure 4 As shown, in this embodiment Figure 2 Based on the embodiment, the application process of the response processing annotation plug-in is described in detail, and the method includes:
[0115] Step S301, starting a target application constructed by a target development project.
[0116] The target application is a Spring Boot application, which refers to a runnable application that is built from the target development project. It can be understood that the target application is a runtime instance of the target development project. The target application can be deployed to various environments, such as a local development environment, a test environment, a production environment, etc. Exemplarily, the target development project is packaged into a target application through a build tool (such as Maven or Gradle).
[0117] When the target application is started, the "run" method of the SpringApplication class is called, which is the entry point for application startup. Starting the target application triggers the loading and initialization of the Inversion of Control (IOC) container.
[0118] Step S302, during the loading and initialization process of the inversion of control container, the response processing annotation plug-in is loaded, and the unified exception response class, the unified exception response class with data, and the implementation class objects corresponding to the unified response class are injected into the target application.
[0119] Among them, the automatic loading of the response processing annotation plug-in is triggered during the loading and initialization process of the IOC container. When the target application starts, the IOC container starts loading and initializing various components and configurations. Specifically, the following are the relevant processes in the startup phase:
[0120] Automatic configuration loading: When the target application starts, the framework scans the application's classpath for classes annotated with @Configuration and @EnableConfigurationProperties. These annotations are used to identify the configuration classes that need to be loaded.
[0121] Instantiate core configuration classes: Classes annotated with @ConfigurationProperties will be automatically recognized by Spring Boot and instantiated based on the configuration information in the application configuration file. This process instantiates the read automatic configuration information (such as response message format style, default return code, and prompt information) into core configuration classes.
[0122] Initialization of the IOC container: During the initialization process of the IOC container, according to the definition of the configuration class and other components, the corresponding beans are created and injected, including the unified exception response class, the unified exception response class with data, and the implementation class objects corresponding to the unified response class.
[0123] Through this mechanism, the target application has all the necessary configurations and components ready when it is started, so that these configurations can be directly used for business logic processing and response encapsulation during the runtime.
[0124] In a possible implementation, during the loading and initialization process of the inversion of control container, before loading the response processing annotation plug-in, the method provided by the present application further includes: reading automatic configuration information and instantiating the read automatic configuration information into a core configuration class.
[0125] The automatic configuration information read includes: the format style of the response message (such as the default style 1), the default success return code, the default success prompt message, the default failure return code, the default failure prompt message, the exception package path, the exception return type, etc.
[0126] Optionally, read the required automatic configuration information through the SpringBoot annotations @Configuration and @EnableConfigurationProperties; through the SpringBoot annotation @ConfigurationProperties, instantiate the read automatic configuration information into a core configuration class so that other classes can easily read the properties in the configuration.
[0127] In Spring Boot, @Configuration and @EnableConfigurationProperties are two commonly used annotations for configuring and managing the configuration properties of an application. Using @ConfigurationProperties, all properties in a configuration file can be automatically mapped to a class, which is the configuration class. When the target application starts, this configuration class will be automatically instantiated. All services in the application can easily read the properties in this configuration file, such as the default success return code is "0" and the default success prompt message is "Success".
[0128] It can be seen that when the target application starts, the configuration class is instantiated first. This is because the application needs to read the information in the configuration file first and convert it into a core configuration class so that the configuration information can be used in the subsequent component loading and initialization process. After the configuration class is instantiated, the IOC container loads and initializes other components and plug-ins based on these configurations. This includes the loading of the response processing annotation plug-in. At this point, the IOC container already has all the necessary configuration information and can load and configure the plug-in correctly based on this information. After the response processing annotation plug-in is loaded, it will be initialized and injected into the context of the application. At this point, the response processing annotation plug-in can use the configuration information obtained from the configuration class to adjust its behavior or function.
[0129] Step S303: During the operation of the target application, response processing is performed through the response processing annotation plug-in.
[0130] In a possible implementation, during the operation of the target application, response processing is performed by a response processing annotation plug-in, including at least one of the following:
[0131] In response to the business request message of the front-end service caller, the return message is encapsulated and processed through the response processing annotation plug-in, and returned to the front-end service caller in a preset format;
[0132] In response to the business processing exception message of the front-end service caller, the exception return message is encapsulated and processed through the response processing annotation plug-in, and returned to the front-end service caller in a preset format.
[0133] Among them, the preset format can be set according to actual needs, and this application does not limit this.
[0134] This application provides a response processing solution that can help developers concisely and efficiently complete the processing processes including unified response format data encapsulation, global exception handling, error code filling, exception message standardization, etc., improving development efficiency, code quality, and code readability and maintainability. Specifically, this application uses a custom annotation method based on the Spring Boot architecture to unify return value encapsulation and exception handling encapsulation, and solves the three main problems left by related technologies:
[0135] To address the problem of poor readability: Unify the processes of response data encapsulation, exception handling, error code filling, etc. to make the code more concise and clear, allowing developers to focus on business code.
[0136] To address the problem of low development efficiency: As a way of using custom annotations, the code of the control layer can be simplified, and the data query results of the interface service can be encapsulated and returned in a unified format.
[0137] Regarding the problem of repeated work: repeated work can be reduced through unified packaging processing.
[0138] Figure 5 A schematic diagram of the structure of the software development device based on response processing provided by this application, such as Figure 5 As shown, the software development device 40 based on response processing provided in this embodiment can be set in an electronic device, and the software development device 40 includes:
[0139] The acquisition module 401 is used to acquire a response processing annotation plug-in; the response processing annotation plug-in is obtained by encapsulating the response processing annotation, the unified exception response class, the unified exception response class with data, the unified response class and the annotation processor;
[0140] The coding module 402 is used to introduce the response processing annotation plug-in into the target development project so that the developer can use the response processing annotation plug-in to write codes related to the target development project.
[0141] In a possible implementation manner, a generation module is further included, and the generation module is used to:
[0142] Define response processing annotations;
[0143] Define unified exception response class, unified exception response class with data, and unified response class;
[0144] Writing annotation processors;
[0145] The response processing annotation, unified exception response class, unified exception response class with data, unified response class and annotation processor are encapsulated into a response processing annotation plug-in.
[0146] In a possible implementation, the unified exception response class inherits from the RuntimeException standard class of SpringBoot; and includes the following multiple reconstruction functions:
[0147] The first exception response message format is used to return an error message;
[0148] The second exception response message format is used to return an error code and an error message;
[0149] The third exception response message format is used to return error messages and error causes;
[0150] The fourth exception response message format is used to return an error code, an error message, and an error cause.
[0151] In a possible implementation, the unified exception response class with data inherits from the unified exception response class and includes the following multiple reconstruction functions:
[0152] The fifth exception response message format is used to return error messages and data;
[0153] The sixth exception response message format is used to return an error code, an error message, and data;
[0154] The seventh abnormal response message format is used to return an error message, an error cause, and data;
[0155] The eighth exception response message format is used to return an error code, an error message, an error cause, and data.
[0156] In a possible implementation, the unified response class includes the following multiple functions:
[0157] The first static exception class, and the exception class thrown by the first static exception class is a unified exception response class;
[0158] The second static exception class, and the exception class thrown by the second static exception class is a unified exception response class with data;
[0159] A first static assertion enhanced reconstruction function, wherein the input parameter of the first static assertion enhanced reconstruction function is the expression to be verified, and the exception type thrown is a unified exception response class of the third exception response message format;
[0160] A second static assertion enhanced reconstruction function, wherein the input parameters of the second static assertion enhanced reconstruction function are an expression to be verified and an error code, and the exception type thrown is a unified exception response class in a fourth exception response message format;
[0161] The third custom static assertion enhanced reconstruction function, and the input parameters of the third static assertion enhanced reconstruction function are the expression to be verified, the error code, and the data, and the exception type thrown is a unified exception response class with data in the eighth exception response message format.
[0162] In a possible implementation, an operation module is further included, and the operation module is used to:
[0163] Start the target application built by the target development project;
[0164] During the loading and initialization of the inversion of control container, the response processing annotation plug-in is loaded, and the unified exception response class, the unified exception response class with data, and the implementation class objects corresponding to the unified response class are injected into the target application;
[0165] When the target application is running, response processing is performed through the response processing annotation plug-in.
[0166] In a possible implementation, the operation module is used for at least one of the following:
[0167] In response to the business request message of the front-end service caller, the return message is encapsulated and processed through the response processing annotation plug-in, and returned to the front-end service caller in a preset format;
[0168] In response to the business processing exception message of the front-end service caller, the exception return message is encapsulated and processed through the response processing annotation plug-in, and returned to the front-end service caller in a preset format.
[0169] In a possible implementation, the running module is further used to read the automatic configuration information and instantiate the read automatic configuration information into a core configuration class before loading the response processing annotation plug-in.
[0170] The response processing-based software development device 40 provided in this embodiment can execute the method provided in the above method embodiment, and its implementation principle and technical effect are similar, which will not be described in detail in this embodiment.
[0171] An embodiment of the present application also provides an electronic device. Figure 6 Schematic diagram of the structure of an electronic device provided by this application. Figure 6 As shown, the electronic device 50 includes: a processor 501 and a memory 502 communicatively connected to the processor 501 .
[0172] The memory 502 stores computer-executable instructions; the processor 501 executes the computer-executable instructions stored in the memory 502 to implement the software development method based on response processing provided in the present application.
[0173] The specific implementation process of the processor 501 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0174] In the embodiment of the present application, the memory 502 and the processor 501 are connected via a bus. The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc.
[0175] The components, their connections and relationships, and their functions shown herein are only examples and are not intended to limit the implementation of the present application described and / or required herein. The various components are interconnected using different buses and can be installed on a common motherboard or in other ways as needed.
[0176] In an exemplary embodiment, a computer-readable storage medium is also provided, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the software development method based on response processing provided in the present application.
[0177] In an exemplary embodiment, a computer program product is also provided, including a computer program. When the computer program in the computer program product is executed by a processor, it is used to implement the software development method based on response processing provided by the present application.
[0178] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, 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 order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0179] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0180] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0181] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.
[0182] If the integrated unit / module is implemented in the form of hardware, the hardware may be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Unless otherwise specified, the processor may be any appropriate hardware processor, such as a central processing unit (CPU), a graphics processing unit (GPU), an application specific integrated circuit (ASIC), a digital signal processor (DSP), a programmable logic device (PLD), a field programmable gate array (FPGA), a controller, a microcontroller, a microprocessor or other electronic components. Unless otherwise specified, the memory can be implemented by any type of volatile or non-volatile storage device or a combination of them, such as a USB flash drive, random-access memory (RAM), static random-access memory (SRAM), dynamic random-access memory (DRAM), enhanced dynamic random-access memory (EDRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), high-bandwidth memory (HBM) or hybrid memory cube (HMC) and other media that can store program code.
[0183] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or the whole or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a memory, including a number of instructions for an electronic device to execute all or part of the steps of the various embodiments of the present application.
[0184] In the above embodiments, the description of each embodiment has its own emphasis. For the part not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0185] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the claims.
[0186] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A software development method based on response processing, characterized in that: include: Obtain a response processing annotation plug-in; the response processing annotation plug-in is obtained by encapsulating a response processing annotation, a unified exception response class, a unified exception response class with data, a unified response class, and an annotation processor; The response processing annotation plug-in is introduced into the target development project so that developers can use the response processing annotation plug-in to write codes related to the target development project.
2. The method according to claim 1, characterized in that Also includes: Define response processing annotations; Define unified exception response class, unified exception response class with data, and unified response class; Writing annotation processors; The response processing annotation, the unified exception response class, the unified exception response class with data, the unified response class and the annotation processor are encapsulated into a response processing annotation plug-in.
3. The method according to claim 2, characterized in that The unified exception response class inherits from the RuntimeException standard class of SpringBoot; and includes the following multiple reconstruction functions: The first exception response message format is used to return an error message; The second exception response message format is used to return an error code and an error message; The third exception response message format is used to return error messages and error causes; The fourth exception response message format is used to return an error code, an error message, and an error cause.
4. The method according to claim 3, characterized in that: The unified exception response class with data inherits from the unified exception response class and includes the following multiple reconstruction functions: The fifth exception response message format is used to return error messages and data; The sixth exception response message format is used to return an error code, an error message, and data; The seventh abnormal response message format is used to return an error message, an error cause, and data; The eighth exception response message format is used to return an error code, an error message, an error cause, and data.
5. The method according to claim 4, characterized in that The unified response class includes the following functions: A first static exception class, and the exception class thrown by the first static exception class is the unified exception response class; A second static exception class, and the exception class thrown by the second static exception class is the unified exception response class with data; A first static assertion enhanced reconstruction function, wherein the input parameter of the first static assertion enhanced reconstruction function is the expression to be verified, and the exception type thrown is a unified exception response class of the third exception response message format; A second static assertion enhanced reconstruction function, wherein the input parameters of the second static assertion enhanced reconstruction function are an expression to be verified and an error code, and the exception type thrown is a unified exception response class in the fourth exception response message format; A third custom static assertion enhanced reconstruction function, wherein the input parameters of the third static assertion enhanced reconstruction function are the expression to be verified, the error code, and the data, and the exception type thrown is a unified exception response class with data in the eighth exception response message format.
6. The method according to claim 1, characterized in that Also includes: Launching a target application built by the target development project; During the loading and initialization process of the inversion of control container, the response processing annotation plug-in is loaded, and the unified exception response class, the unified exception response class with data, and the implementation class objects corresponding to the unified response class are injected into the target application; During the operation of the target application, response processing is performed through the response processing annotation plug-in.
7. The method according to claim 6, characterized in that The performing response processing by the response processing annotation plug-in during the operation of the target application includes at least one of the following: In response to the business request message of the front-end service caller, the return message is encapsulated and processed by the response processing annotation plug-in, and returned to the front-end service caller in a preset format; In response to the business processing exception message of the front-end service caller, the exception return message is encapsulated and processed by the response processing annotation plug-in, and returned to the front-end service caller in a preset format.
8. The method according to claim 6, characterized in that Before loading the response processing annotation plug-in, it also includes: Read the automatic configuration information and instantiate the read automatic configuration information into the core configuration class.
9. A software development device based on response processing, characterized in that: include: Obtain a response processing annotation plug-in; the response processing annotation plug-in is obtained by encapsulating a response processing annotation, a unified exception response class, a unified exception response class with data, a unified response class, and an annotation processor; The response processing annotation plug-in is introduced into the target development project so that developers can use the response processing annotation plug-in to write codes related to the target development project.
10. An electronic device, characterized in that: include: Memory, processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 8 when executed by a processor.
12. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 8 when being executed by a processor.