WO2020192134A1 - 基于Spring MVC的异常处理方法、装置、计算机设备和存储介质 - Google Patents
基于Spring MVC的异常处理方法、装置、计算机设备和存储介质 Download PDFInfo
- Publication number
- WO2020192134A1 WO2020192134A1 PCT/CN2019/117506 CN2019117506W WO2020192134A1 WO 2020192134 A1 WO2020192134 A1 WO 2020192134A1 CN 2019117506 W CN2019117506 W CN 2019117506W WO 2020192134 A1 WO2020192134 A1 WO 2020192134A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- processor
- resource request
- view object
- abnormal
- exception
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
- G06F9/449—Object-oriented method invocation or resolution
Definitions
- This application relates to a Spring MVC-based exception handling method, device, computer equipment and storage medium.
- the Spring MVC framework is designed around a DispatcherServlet interface class.
- This interface class implements the basic functions of the front controller, distributes received data requests to each handler object (Handler), and supports configurable processor mapping, View rendering, localization.
- the DispatcherServlet interface class is implemented through various configuration files. By defining various implementation classes in these configuration files, the basic functions of the front controller can be realized.
- a Spring MVC-based exception handling method, device, computer equipment, and storage medium are provided.
- An exception handling method based on Spring MVC includes:
- the front-end controller generates an abnormal page view object according to the new model view object; the abnormal page view object is used to enable the client to display a page including abnormal information corresponding to the abnormal type code.
- a Spring MVC-based exception handling device includes:
- the resource request acquisition module is used to acquire the resource request sent by the client through the front controller;
- the target processor object acquisition module is configured to determine the corresponding target processor object according to the resource identifier in the resource request, and process the resource request through the target processor object to obtain a model view object;
- the callback processing module is used to call the callback function of the interceptor interface class to verify the model view object
- the exception handling module is used to call the exception handling object to process the exception type code to obtain a new model view object when the callback function returns the exception type code; generate a new model view object by the front controller according to the new model view object An abnormal page view object; the abnormal page view object is used to make the client display a page that includes abnormal information corresponding to the abnormal type code.
- a computer device including a memory and one or more processors, the memory stores computer readable instructions, when the computer readable instructions are executed by the processor, the one or more processors execute The following steps:
- the front-end controller generates an abnormal page view object according to the new model view object; the abnormal page view object is used to enable the client to display a page including abnormal information corresponding to the abnormal type code.
- One or more non-volatile computer-readable storage media storing computer-readable instructions.
- the one or more processors execute the following steps:
- the front-end controller generates an abnormal page view object according to the new model view object; the abnormal page view object is used to enable the client to display a page including abnormal information corresponding to the abnormal type code.
- Fig. 1 is an application scenario diagram of an exception handling method based on Spring MVC according to one or more embodiments.
- Fig. 2 is a schematic flowchart of an exception handling method based on Spring MVC according to one or more embodiments.
- Fig. 3 is a schematic diagram of a framework of an exception handling method based on Spring MVC according to one or more embodiments.
- Fig. 4 is a block diagram of an exception handling device based on Spring MVC according to one or more embodiments.
- Figure 5 is a block diagram of a computer device according to one or more embodiments.
- the Spring MVC-based exception handling method provided in this application can be applied to the application environment shown in Figure 1.
- the terminal 102 and the web server 104 communicate through the network.
- the terminal 102 obtains the resource request triggered by the user in the browser, and sends the resource request to the web server 104 through the network.
- the web server 104 obtains the resource request sent by the client through the front-end controller, and according to the resource identifier in the resource request
- the symbol determines the corresponding target processor object, and processes the resource request through the obtained target processor object to obtain the model view object; then calls the callback function of the interceptor interface class to verify the model view object; when the callback function returns the exception type code ,
- the front controller can call the exception handling object to process the exception type code to obtain a new model view object; the front controller generates an exception page view object according to the new model view object; when the client receives the exception page view object, it can render Display the page that includes the exception information corresponding to the exception type code.
- the terminal 102 may be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices.
- the web server 104 may be implemented by an independent server or a server cluster composed of multiple servers.
- a Spring MVC exception handling method is provided. Taking the method applied to the web server 104 in FIG. 1 as an example for description, the method includes the following steps:
- Step S202 Obtain the resource request sent by the client through the front-end controller.
- the resource request is an HTTP message generated by the client according to the currently acquired resource identifier (URL).
- the resource identifier is used to uniquely identify the resource to be requested.
- the client When a user visits a website, the client generates a resource request according to the URL corresponding to the visited website, and sends the resource request to the web server through the network.
- the web server After the web server receives the resource request, it checks the resource identifier in the resource request. If it is found to be a static resource request, it forwards the request to the default server program (Default-servlet-handler) of the web server Through processing, the target data corresponding to the resource request is obtained, and the target resource carrier object corresponding to the resource request is generated according to the target data and returned to the client.
- Default-servlet-handler the default server program
- the server program If it is not a request for a static resource, match the server program corresponding to the resource identifier according to the configuration file, and forward the resource request to the front controller of the server program. After the front controller receives the resource request, it calls the The other components included in the server program process the resource request.
- the client requests a static resource (*.htm, a file with a suffix of *.htm), it will forward the request directly to the web server, and then the web server will retrieve the content from the file system and send it back to the client browser Perform analysis and execution.
- a static resource *.htm, a file with a suffix of *.htm
- the web server will retrieve the content from the file system and send it back to the client browser Perform analysis and execution.
- dynamic resources (*.jsp, *.asp, *.aspx, *.php)
- the front controller is a pre-defined implementation class inherited from the SpringDispatcherServlet interface class in the Spring MVC framework.
- the front controller can be, for example, WebSupportDispatcherServlet. It is the center of the entire process control and controls the scheduling and execution of other interface classes.
- the data corresponding to the URL in the resource request is processed by the processor defined by the business processing layer and then encapsulated into a model (Model) in the MVC architecture, and then the model (Model) is returned to the corresponding interface (View) for display.
- the implementation class is the specific implementation method of the interface class. For example, an interface class has three implementation classes A, B, and C, which are different types of implementation classes. By determining that the object referenced by the interface class is the implementation class of type A, You can call the method in the implementation class of type A for processing when calling the method in the interface class.
- Step S204 Determine the corresponding target processor object according to the resource identifier in the resource request, and process the resource request through the target processor object to obtain the model view object.
- the processor object is an object defined by the business processing layer for processing resource requests, including multiple processing functions, also called processing methods.
- the processing functions in the processor object process the resource request and return the processing result.
- the front controller can search for the processor mapper corresponding to the resource request according to the URL in the resource request, and the processor mapper can map the request to the target processor object according to the configuration file or annotation.
- the model view object (ModelAndView) is used to store the processed result data and the view information used to display the result data.
- Model represents the model
- View represents the view.
- the target processor object processes the resource request, it stores the result data in the model attribute of the model view object, and stores the view information to be returned in the view attribute of the model view object, and then
- the model view object is returned to the front controller, and the front controller can call the view parser defined in the configuration file to parse the model view object, and display the result data obtained by the analysis on the page specified by the view information.
- determining the corresponding target processor object according to the resource identifier in the resource request includes: extracting the resource identifier from the resource request; calling the corresponding mapper object according to the resource identifier through the front controller; The processor object obtains the processor object corresponding to the resource request; searches for the processor adapter corresponding to the processor object through the front controller; determines the target processor object from the processor object through the processor adapter.
- the implementation class that inherits from the default annotation controller mapping processor (DefaultAnnotationHandlerMapping) interface class in the Spring MVC framework can be customized in advance, that is, the custom mapper object (WebSupportHandlerMapping), and the front controller can call the custom
- the processor acquisition function (getHandler) in the mapper object the processor acquisition function can find the processor object (Handler) and multiple interceptor objects (HandlerInterceptor) through the URL in the resource request, the processor that the mapper object will find
- the object and multiple interceptor objects are encapsulated into a processor execution chain (HandlerExecuteChain) and returned to the front controller.
- the front controller traverses all the configured processor adapters and searches for the processing in the processor execution chain from all adapter objects.
- Handler object (Handler) corresponds to the handler adapter (HandlerAdapter), which calls a specific target handler object from the handler object to process the user's resource request.
- the front controller before processing the resource request through the target processor object to obtain the model view object, the front controller also calls the preprocessing function (preHandler) in each interceptor object in the execution chain to preprocess the resource request , When it returns false, it means that the whole process of the request is over. When the return value is true, the preprocessing function of the next interceptor object will continue to be called, and when the last interceptor object also returns true, step S206 will be executed to process the resource request through the function in the target processor object.
- preprocessing function preHandler
- the target processor object inherits from the same processor interface class; processing the resource request through the target processor object to obtain the model view object includes: obtaining the parameter processing function defined by the processor interface class; The request parameters are passed to the parameter processing function as function parameters, and the model view object corresponding to the resource request returned by the parameter processing function is obtained.
- the parameter processing function in the processor object can be customized according to business logic.
- the processor objects corresponding to different resource requests can be different. Different processor objects Can inherit from the same processor interface class or implement the same processor interface.
- the parameter processing function can be pre-defined in the processor interface class, and the processor object inherited from the processor interface class can be created according to different business logic.
- the model view object corresponding to the resource request is returned .
- the step of determining the target processor object adapted to the processor object by the front-end controller specifically includes: the front-end controller traverses all the processor adapters, searches for the processor adapter corresponding to the processor object, and passes The processor adapter calls a specific target processor adapted to the processor object, and processes the user's request through the target processor.
- the processor object uses the predetermined annotation type @ControllerService to write the properties of the processor object class, and the resource request can be received in the front controller
- the processor object is automatically obtained according to the context, the corresponding parameter processing function is introduced in the processor object through a custom annotation type, so that the processor object directly references the parameter processing function to process the resource request.
- Step S206 call the callback function of the interceptor interface class to verify the model view object.
- the front controller calls the callback function in the interceptor object determined by the mapper object (that is, the function executed after the resource request is processed) to verify the obtained model view object and realize the processing
- the post-processing of the processor can be processed through the result data or view information in the model view object to check the result data included in the model view object.
- Step S208 when the callback function returns the code of the exception type, call the exception handling object to process the code of the exception type to obtain a new model view object.
- Anomaly type codes are unified codes corresponding to respective abnormal information after classification.
- the implementation class that inherits from the exception handling interface class in the Spring MVC framework can be customized in advance as the exception handling object.
- the exception handling object WebSupportDispatcherServlet inherits from SimpleMappingExceptionResolver
- SimpleMappingExceptionResolver is the implementation class of the exception handling interface class HandlerExceptionResolver in the Spring MVC framework.
- the exception handling object has the processing methods included in the exception handling interface class, and there is no need to repeat coding. Specifically, when the callback function in the interceptor interface class verifies the model view object and returns the exception code type, the processing method included in the exception handling object can be called to process the exception type code to obtain a new model view object.
- the new model view object includes abnormal information data and view information needed to display the abnormal information corresponding to the abnormal type code.
- the corresponding exception type will be determined by the interceptor's callback function, and the corresponding exception information will be displayed by returning a new model view object, which can realize the unification of various complex exception information deal with.
- the above method further includes: obtaining abnormal information and classifying each abnormal information; and encoding according to the type of each abnormal information to obtain the abnormal type code.
- the exception handling function in the exception handling object can be customized according to the business logic.
- the exception handling function in the unified exception handling object can be used to process the exception encoding type, and the returned A new model view object that includes abnormal information data.
- the model view object includes the logical view name and the model data
- the method further includes: when the callback function does not return the abnormal type code, obtain the view resolution object through the front controller; perform the logical view name through the view resolution object Resolve to obtain the view object; render the model data through the view object to obtain the response data; and return the response data to the client through the front controller.
- the front controller directly requests the view parser to parse the model view object, obtains the view object, and returns the view object to the front-end control Then, the front controller renders the model data through the view object to obtain the response data, and returns the response data to the client.
- the client can display the web page according to the response data.
- Step 210 Generate an abnormal page view object according to the new model view object through the front controller; the abnormal page view object is used to make the client display a page including abnormal information corresponding to the code of the abnormal type.
- the front controller can call the view analysis object to analyze and obtain the abnormal page view object, and generate response data based on the abnormal page view object and then feed it back to the client.
- the client can use the response data
- the included abnormal page view information displays pages including abnormal information.
- generating the abnormal page view object according to the new model view object through the front controller includes: calling the view resolution object through the front controller; and parsing the logical view name in the new model view object through the view resolution object to obtain Page address; according to the model data and page address in the new model view object, generate the abnormal page view object; return the abnormal page view object to the client, so that the client can render and display according to the abnormal page view object including the code corresponding to the abnormal type Exception information page.
- the front controller calls the view resolution object and requests the view resolution object to parse the new model view object. After the view resolution object is parsed, the page address is obtained. The page in the page address is used to display the error corresponding to the exception type code Information, the front controller can generate an abnormal page object based on the returned page address and the model data in the new model view object. In this way, the client can render and display the abnormal information corresponding to the type of the abnormality code that occurs according to the abnormal page object. On the page, users can clarify the cause of the exception based on the exception information.
- the above-mentioned Spring MVC-based exception handling method after the front controller finds the target processor object to process the resource request sent by the client to obtain the model view object, before the model view object is parsed, the interceptor interface class is called through the front controller
- the callback function verifies the obtained model view object. When the model view object has an exception, it will not pass the verification.
- the callback function will return the exception type code corresponding to the exception.
- FIG. 3 it is a schematic diagram of the framework of a Spring MVC-based exception handling method in a specific embodiment.
- the method specifically includes the following steps:
- the processor mapper is not found, the corresponding static resource will be obtained according to the resource identifier. If the corresponding static resource cannot be found, a 404 error will be reported;
- mapping processor maps the request to the execution chain object (HandlerExecutionChain) according to its own configuration or annotation (WebSupportWeb2AppBeanPostProcessor), and returns the execution chain object to the front controller.
- the execution chain object includes one Handler object (Handler) and multiple interceptor objects (HandlerInterceotor);
- the front controller traverses all the configured adapters and finds the processor adapter HandlerAdapter corresponding to the processor object;
- Step 6 will be executed when the method is called and returns true;
- the processor adapter calls the specific target processor adapted to the processor object, processes the resource request through the target processor, and returns to the model view object (ModelAndView) after the target processor is processed;
- the front controller passes the new model view object to the view resolver ViewResolver, and the view resolver resolves the logical view name in the new model view object into a specific view object (View) according to the configuration, and returns it to the front controller;
- the controller renders the incoming model data according to the view object to obtain the response data.
- a Spring MVC-based exception handling device 400 including: a resource request acquisition module 402, a target processor object acquisition module 404, a model view object acquisition module 406, and a callback The processing module 408 and the exception processing module 410, wherein:
- the resource request obtaining module 402 is configured to obtain the resource request sent by the client through the front controller;
- the model view object acquisition module 404 is configured to determine the corresponding target processor object according to the resource identifier in the resource request, and process the resource request through the target processor object to obtain the model view object;
- the callback processing module 406 is used to call the callback function of the interceptor interface class to verify the model view object
- the exception handling module 408 is used to call the exception handling object to process the exception type code to obtain a new model view object when the callback function returns the exception type code; generate an exception page view object based on the new model view object through the front controller; the exception page The view object is used to make the client display a page that includes the exception information corresponding to the exception type code.
- the model view object acquisition module 404 is also used to extract the resource identifier from the resource request; call the corresponding mapper object according to the resource identifier through the front controller; acquire the corresponding resource request through the mapper object Processor object; find the processor adapter corresponding to the processor object through the front controller; determine the target processor object from the processor object through the processor adapter.
- the target processor object inherits from the same processor interface class; the model view object obtaining module 404 is also used to obtain the parameter processing function defined by the processor interface class; and pass the request parameters in the resource request as function parameters For the parameter processing function, obtain the model view object corresponding to the resource request returned by the parameter processing function.
- the exception handling object inherits from the same exception handling interface class; the exception handling module 408 is also used to obtain the exception handling function defined by the exception handling interface class; the exception type code is passed to the exception handling function as a function parameter to obtain The new model view object returned by the exception handling function.
- the exception handling module 408 is also used to call the view resolution object through the front controller; to parse the logical view name in the new model view object through the view resolution object to obtain the page address; according to the new model view object
- the abnormal page view object is generated from the model data and the page address of the abnormal page view object; the abnormal page view object is returned to the client, so that the client renders and displays the page including the abnormal information corresponding to the abnormal type code according to the abnormal page view object.
- the model view object includes a logical view name and model data
- the device further includes a view resolution module.
- the view resolution module is used to obtain the view resolution object through the front controller when the callback function does not return an abnormal type code;
- the view resolution object parses the logical view name to obtain the view object; renders the model data through the view object to obtain the response data; and returns the response data to the client through the front controller.
- the device further includes an anomaly information encoding module, which is used to obtain anomaly information and classify each anomaly information; encode according to the type of each anomaly information to obtain an anomaly type code.
- an anomaly information encoding module which is used to obtain anomaly information and classify each anomaly information; encode according to the type of each anomaly information to obtain an anomaly type code.
- the above-mentioned Spring MVC-based exception handling device after finding the target processor object through the front controller to process the resource request sent by the client to obtain the model view object, before parsing the model view object, the interceptor interface class is called through the front controller
- the callback function verifies the obtained model view object. When the model view object has an exception, it will not pass the verification.
- the callback function will return the exception type code corresponding to the exception.
- Each module in the above-mentioned Spring MVC-based exception handling device can be implemented in whole or in part by software, hardware, and a combination thereof.
- the foregoing modules may be embedded in the form of hardware or independent of the processor in the computer device, or may be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the foregoing modules.
- a computer device is provided.
- the computer device may be a server, and its internal structure diagram may be as shown in FIG. 5.
- the computer equipment includes a processor, a memory, a network interface and a database connected through a system bus.
- the processor of the computer device is used to provide calculation and control capabilities.
- the memory of the computer device includes a non-volatile storage medium and an internal memory.
- the non-volatile storage medium stores an operating system, computer readable instructions, and a database.
- the internal memory provides an environment for the operation of the operating system and computer-readable instructions in the non-volatile storage medium.
- the database of the computer equipment is used to store web page resource data.
- the network interface of the computer device is used to communicate with an external terminal through a network connection.
- FIG. 5 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied.
- the specific computer device may Including more or fewer parts than shown in the figure, or combining some parts, or having a different arrangement of parts.
- the Spring MVC-based exception handling apparatus may be implemented in a form of computer-readable instructions, and the computer-readable instructions may run on the computer device as shown in FIG. 5.
- the memory of the computer device can store various program modules that make up the Spring MVC-based exception handling device, such as the resource request acquisition module 402, the model view object acquisition module 404, the callback processing module 406, and the exception processing module 408 shown in FIG. 4 .
- the computer-readable instructions formed by each program module cause the processor to execute the steps in the Spring MVC-based exception handling method of each embodiment of the application described in this specification.
- the computer device shown in FIG. 5 may execute step S202 through the resource request acquisition module 402 in the Spring MVC-based exception handling apparatus shown in FIG. Z.
- the computer device may execute step S204 through the model view object acquisition module 404.
- the computer device can execute step S208 through the callback processing module 406.
- the computer device may execute step S210 through the exception processing module 408.
- a computer device includes a memory and one or more processors.
- the memory stores computer-readable instructions.
- the one or more processors execute the Spring-based The steps in the exception handling method of MVC.
- One or more non-volatile computer-readable storage media storing computer-readable instructions.
- the computer-readable instructions execute the Steps in the exception handling method of Spring MVC.
- Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
- Volatile memory may include random access memory (RAM) or external cache memory.
- RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain Channel (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
- SRAM static RAM
- DRAM dynamic RAM
- SDRAM synchronous DRAM
- DDRSDRAM double data rate SDRAM
- ESDRAM enhanced SDRAM
- SLDRAM synchronous chain Channel
- memory bus Radbus direct RAM
- RDRAM direct memory bus dynamic RAM
- RDRAM memory bus dynamic RAM
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
- Stored Programmes (AREA)
Abstract
一种基于Spring MVC的异常处理方法,包括:通过前端控制器获取客户端发送的资源请求;根据资源请求中的资源标识符确定对应的目标处理器对象,并通过目标处理器对象处理资源请求,得到模型视图对象;调用拦截器接口类的回调函数对模型视图对象进行验证;当回调函数返回异常类型编码时,则调用异常处理对象对异常类型编码进行处理得到新模型视图对象;通过前端控制器根据新模型视图对象生成异常页面视图对象;异常页面视图对象用于令客户端显示包括与异常类型编码对应的异常信息的页面。
Description
本申请要求于2019年03月28日提交中国专利局,申请号为201910243158.4,申请名称为“基于Spring MVC的异常处理方法、装置、计算机设备和存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及一种基于Spring MVC的异常处理方法、装置、计算机设备和存储介质。
Spring MVC框架是围绕一个DispatcherServlet接口类来设计的,这个接口类实现前端控制器的基本功能,会把接收到的数据请求分发给各个处理器对象(Handler),并支持可配置的处理器映射、视图渲染、本地化。DispatcherServlet接口类是通过各种配置文件实现的,在这些配置文件中定义各种实现类,就可以实现前端控制器的基本功能。
然而,发明人意识到,现有的对DispatcherServlet接口类配置较为混乱,导致前置控制器只能处理简单的异常信息。如何利用Spring MVC框架实现对不同业务场景下返回的各种复杂的异常信息进行统一处理,是一个需要解决的问题。
发明内容
根据本申请公开的各种实施例,提供一种基于Spring MVC的异常处理方法、装置、计算机设备和存储介质。
一种基于Spring MVC的异常处理方法包括:
通过前端控制器获取客户端发送的资源请求;
根据所述资源请求中的资源标识符确定对应的目标处理器对象;并通过所述目标处理器对象处理所述资源请求,得到模型视图对象;
调用拦截器接口类的回调函数对所述模型视图对象进行验证;
当所述回调函数返回异常类型编码时,则调用异常处理对象对所述异常类型编码进行 处理得到新模型视图对象;及
通过所述前端控制器根据所述新模型视图对象生成异常页面视图对象;所述异常页面视图对象用于令所述客户端显示包括与所述异常类型编码对应的异常信息的页面。
一种基于Spring MVC的异常处理装置包括:
资源请求获取模块,用于通过前端控制器获取客户端发送的资源请求;
目标处理器对象获取模块,用于根据所述资源请求中的资源标识符确定对应的目标处理器对象,并通过所述目标处理器对象处理所述资源请求,得到模型视图对象;
回调处理模块,用于调用拦截器接口类的回调函数对所述模型视图对象进行验证;及
异常处理模块,用于当所述回调函数返回异常类型编码时,则调用异常处理对象对所述异常类型编码进行处理得到新模型视图对象;通过所述前端控制器根据所述新模型视图对象生成异常页面视图对象;所述异常页面视图对象用于令所述客户端显示包括与所述异常类型编码对应的异常信息的页面。
一种计算机设备,包括存储器和一个或多个处理器,所述存储器中储存有计算机可读指令,所述计算机可读指令被所述处理器执行时,使得所述一个或多个处理器执行以下步骤:
通过前端控制器获取客户端发送的资源请求;
根据所述资源请求中的资源标识符确定对应的目标处理器对象,并通过所述目标处理器对象处理所述资源请求,得到模型视图对象;
调用拦截器接口类的回调函数对所述模型视图对象进行验证;
当所述回调函数返回异常类型编码时,则调用异常处理对象对所述异常类型编码进行处理得到新模型视图对象;及
通过所述前端控制器根据所述新模型视图对象生成异常页面视图对象;所述异常页面视图对象用于令所述客户端显示包括与所述异常类型编码对应的异常信息的页面。
一个或多个存储有计算机可读指令的非易失性计算机可读存储介质,计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行以下步骤:
通过前端控制器获取客户端发送的资源请求;
根据所述资源请求中的资源标识符确定对应的目标处理器对象,并通过所述目标处理 器对象处理所述资源请求,得到模型视图对象;
调用拦截器接口类的回调函数对所述模型视图对象进行验证;
当所述回调函数返回异常类型编码时,则调用异常处理对象对所述异常类型编码进行处理得到新模型视图对象;及
通过所述前端控制器根据所述新模型视图对象生成异常页面视图对象;所述异常页面视图对象用于令所述客户端显示包括与所述异常类型编码对应的异常信息的页面。
本申请的一个或多个实施例的细节在下面的附图和描述中提出。本申请的其它特征和优点将从说明书、附图以及权利要求书变得明显。
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。
图1为根据一个或多个实施例中基于Spring MVC的异常处理方法的应用场景图。
图2为根据一个或多个实施例中基于Spring MVC的异常处理方法的流程示意图。
图3为根据一个或多个实施例中基于Spring MVC的异常处理方法的框架示意图。
图4为根据一个或多个实施例中基于Spring MVC的异常处理装置的框图。
图5为根据一个或多个实施例中计算机设备的框图。
为了使本申请的技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
本申请提供的基于Spring MVC的异常处理方法,可以应用于如图1所示的应用环境中。终端102与网页服务器104通过网络进行通信。终端102获取用户在浏览器中触发的资源请求,并通过网络将该资源请求发送至网页服务器104,网页服务器104通过前端控制器获取客户端发送的资源请求,并根据该资源请求中的资源标识符确定对应的目标处理 器对象,通过获取的目标处理器对象处理该资源请求,得到模型视图对象;然后调用拦截器接口类的回调函数对模型视图对象进行验证;当回调函数返回异常类型编码时,则前端控制器可以调用异常处理对象对异常类型编码进行处理得到新模型视图对象;前端控制器根据新模型视图对象生成异常页面视图对象;当客户端接收到该异常页面视图对象,就可以渲染显示包括与异常类型编码对应的异常信息的页面。终端102可以但不限于是各种个人计算机、笔记本电脑、智能手机、平板电脑和便携式可穿戴设备,网页服务器104可以用独立的服务器或者是多个服务器组成的服务器集群来实现。
在其中一个实施例中,如图2所示,提供了一种Spring MVC的异常处理方法,以该方法应用于图1中的网页服务器104为例进行说明,包括以下步骤:
步骤S202,通过前端控制器获取客户端发送的资源请求。
资源请求是客户端根据当前获取的资源标识符(URL)生成的HTTP报文。资源标识符用于唯一标识要请求的资源,当用户访问一个网站时,客户端根据访问的网站对应的URL生成一个资源请求,并通过网络将该资源请求发送至网页服务器。在网页服务器接收到该资源请求后,对该资源请求中的资源标识符进行检查,如果发现是静态资源的请求,就将该请求转由网页服务器默认的服务端程序(Default-servlet-handler)处理,得到与该资源请求对应的目标数据,根据目标数据生成与资源请求对应的目标资源载体对象并返回至客户端。如果不是静态资源的请求,则根据配置文件匹配与该资源标识符对应的服务端程序,将该资源请求转发给该服务端程序的前端控制器,由前端控制器接收该资源请求后,调用该服务端程序所包括的其它组件处理该资源请求。
例如,如果客户端请求的是静态资源(*.htm,后缀名为*.htm的文件),则将请求直接转交给网页服务器,之后网页服务器从文件系统中取出内容,发送回客户端浏览器进行解析执行。如果客户端请求的是动态资源(*.jsp、*.asp、*.aspx、*.php),则先将请求转交给服务端程序的前端控制器,经业务层处理后从数据库中取出数据后动态拼凑页面的展示内容,再将所有的展示内容返回给网页服务器,通过网页服务器将展示内容返回至客户端浏览器进行解析、渲染并显示。
前端控制器是预先自定义的继承自Spring MVC框架中的SpringDispatcherServlet接口类的实现类,前端控制器比如可以是WebSupportDispatcherServlet,它是整个流程 控制的中心,控制其它接口类的调度和执行,它把用户的资源请求中的URL对应的数据经过业务处理层定义的处理器处理之后封装成MVC架构中的模型(Model),然后再将该模型(Model)返回给对应的界面(View)进行展示。实现类是接口类的具体实现方法,比如某个接口类有3个实现类A,B,C,分别为不同类型的实现类,通过确定被接口类引用的对象是类型A的实现类,就可以在调用接口类中的方法时调用类型A的实现类中方法进行处理。
步骤S204,根据资源请求中的资源标识符确定对应的目标处理器对象,并通过目标处理器对象处理资源请求,得到模型视图对象。
处理器对象是业务处理层定义的用于资源请求进行处理的对象,包括多个处理函数,也叫处理方法,通过该处理器对象中的处理函数,对资源请求进行处理,返回处理结果。前端控制器可以根据该资源请求中的URL查找与该资源请求对应的处理器映射器,处理器映射器就可以根据配置文件或注解把请求映射成目标处理器对象。
模型视图对象(ModelAndView)用来存储处理完后的结果数据以及用于显示该结果数据的视图信息。Model代表模型,View代表视图,目标处理器对象处理完资源请求后,将结果数据存储在该模型视图对象的模型属性中,将要返回的视图信息存储在该模型视图对象的视图属性中,然后将模型视图对象返回至前端控制器,前端控制器可以调用配置文件中定义的视图解析器,对该模型视图对象进行解析,将解析得到的结果数据显示在视图信息所指定的页面上。
在其中一个实施例中,根据资源请求中的资源标识符确定对应的目标处理器对象包括:从资源请求中提取资源标识符;通过前端控制器根据资源标识符调用相应的映射器对象;通过映射器对象获取与资源请求对应的处理器对象;通过前端控制器查找与处理器对象对应的处理器适配器;通过处理器适配器从处理器对象中确定目标处理器对象。
具体地,可以预先自定义继承自Spring MVC框架中的默认注解控制器映射处理器(DefaultAnnotationHandlerMapping)接口类的实现类,也就是自定义的映射器对象(WebSupportHandlerMapping),前端控制器可以调用自定义的映射器对象中的处理器获取函数(getHandler),处理器获取函数可以通过资源请求中的URL查找处理器对象(Handler)和多个拦截器对象(HandlerInterceptor),映射器对象将查找到的处理器对 象和多个拦截器对象封装成一个处理器执行链(HandlerExecuteChain)并返回给前端控制器,前端控制器遍历配置的所有处理器适配器,从所有的适配器对象中查找与处理器执行链中的处理器对象(Handler)对应的处理器适配器(HandlerAdapter),由处理器适配器从处理器对象中调用具体的目标处理器对象来处理用户的资源请求。
在其中一个实施例中,在通过目标处理器对象处理资源请求,得到模型视图对象之前,前端控制器还调用执行链中各个拦截器对象中的预处理函数(preHandler),对资源请求进行预处理,当它返回为false时,表示请求的整个过程结束。当返回值为true时,就会继续调用下一个拦截器对象的预处理函数,直至最后一个拦截器对象也返回true时,就会执行步骤S206,通过目标处理器对象中的函数处理资源请求。
在其中一个实施例中,目标处理器对象继承自同一处理器接口类;通过目标处理器对象处理资源请求,得到模型视图对象包括:获取处理器接口类定义的参数处理函数;将资源请求中的请求参数作为函数参数传递给参数处理函数,获取参数处理函数返回的与资源请求对应的模型视图对象。
具体地,可以根据业务逻辑自定义处理器对象中的参数处理函数,与资源请求对应的处理器对象有多种类型,不同的资源请求对应的处理器对象可以是不同的,不同的处理器对象可以继承自同一处理器接口类或实现了同一个处理器接口。参数处理函数可以预先定义在该处理器接口类中,可以根据不同的业务逻辑创建继承自该处理器接口类的处理器对象。在对该资源请求进行处理时,可将资源请求中的请求参数作为函数参数传递给处理器接口类中的参数处理函数,经过该参数处理函数的处理后,返回与资源请求对应的模型视图对象。
在其中一个实施例中,通过前端控制器确定与处理器对象适配的目标处理器对象的步骤具体包括:前端控制器遍历所有的处理器适配器,查找与处理器对象对应的处理器适配器,通过该处理器适配器调用与处理器对象适配的具体的目标处理器,通过目标处理器处理用户的请求。
在其中一个实施例中,基于Spring MVC框架的注解功能,在处理器对象的注解@Controller之后利用预先确定的注解类型@ControllerService写入处理器对象类的属性,可以在前端控制器接收到资源请求时,自动根据上下文获取到处理器对象,在该处理 器对象中通过自定义的注解类型引入对应的参数处理函数,以便处理器对象直接引用该参数处理函数对资源请求进行处理。
步骤S206,调用拦截器接口类的回调函数对模型视图对象进行验证。
具体地,在处理资源请求之后,前端控制器调用通过映射器对象确定的拦截器对象中的回调函数(即在处理了资源请求之后执行的函数),对得到的模型视图对象进行验证,实现处理器的后处理,可以通过模型视图对象中的结果数据或视图信息进行处理,以对模型视图对象包括的结果数据进行检查。
步骤S208,当回调函数返回异常类型编码时,则调用异常处理对象对异常类型编码进行处理得到新模型视图对象。
异常类型编码是对各自异常信息进行分类后各自对应的统一编码。可以预先自定义继承自Spring MVC框架中异常处理接口类的实现类,作为异常处理对象。比如,异常处理对象WebSupportDispatcherServlet继承自SimpleMappingExceptionResolver,SimpleMappingExceptionResolver是Spring MVC框架中异常处理接口类HandlerExceptionResolver的实现类。该异常处理对象就具有了该异常处理接口类中所包括的处理方法,无需重复编码。具体地,当拦截器接口类中的回调函数对模型视图对象进行验证并返回异常编码类型时,则可以调用异常处理对象所包括的处理方法对异常类型编码进行处理,得到新模型视图对象。新模型视图对象包括显示该异常类型编码所对应的异常信息所需要的异常信息数据和视图信息。本实施例中,对于任意业务中出现的异常,都会被拦截器的回调函数确定相应的异常类型,并通过返回新模型视图对象来显示相应的异常信息,能够实现对各种复杂异常信息的统一处理。
在其中一个实施例中,上述方法还包括:获取异常信息,对各异常信息进行分类;按照各异常信息的类型进行编码,得到异常类型编码。
具体地,可以根据实际的业务需要将不同的异常信息进行分类并进行统一编码,还可以指定一个处理方式,以提示用户。以下为拦截器中的回调函数返回的异常类型编码与前端控制器要返回的各种异常信息的对应关系的示例:
000000——验证通过;
100002——没有找到对应接口;
100003——保存失败;
100004——编辑保存失败。
在其中一个实施例中,异常处理对象继承自同一异常处理接口类;调用异常处理对象对异常类型编码进行处理得到新模型视图对象包括:获取异常处理接口类定义的异常处理函数;将异常类型编码作为函数参数传递给异常处理函数,获取异常处理函数返回的新模型视图对象。
具体地,可以根据业务逻辑自定义异常处理对象中的异常处理函数,在对异常编码类型进行处理时,可以均采用统一的异常处理对象中的异常处理函数对异常编码类型进行处理,获取返回的包括异常信息数据的新模型视图对象。
在其中一个实施例中,模型视图对象包括逻辑视图名和模型数据,方法还包括:当回调函数未返回异常类型编码时,则通过前端控制器获取视图解析对象;通过视图解析对象对逻辑视图名进行解析,得到视图对象;通过视图对象渲染模型数据,得到响应数据;通过前端控制器将响应数据返回至客户端。
具体地,当拦截器接口类的回调函数对模型视图对象进行验证未出现异常时,则直接通过前端控制器请求视图解析器对模型视图对象进行解析,得到视图对象,并返回视图对象至前端控制器,再由前端控制器通过视图对象渲染模型数据,得到响应数据,并将响应数据返回至客户端,客户端就可以根据响应数据显示网页页面。
步骤210,通过前端控制器根据新模型视图对象生成异常页面视图对象;异常页面视图对象用于令客户端显示包括与异常类型编码对应的异常信息的页面。
具体地,对于得到的新模型视图对象,前端控制器可以调用视图解析对象进行解析后得到异常页面视图对象,并根据异常页面视图对象生成响应数据后反馈至客户端,客户端可以根据响应数据中所包括的异常页面视图信息显示包括异常信息的页面。
在其中一个实施例中,通过前端控制器根据新模型视图对象生成异常页面视图对象包括:通过前端控制器调用视图解析对象;通过视图解析对象对新模型视图对象中的逻辑视图名进行解析,得到页面地址;根据新模型视图对象中的模型数据和页面地址,生成异常页面视图对象;将异常页面视图对象返回至客户端,以使客户端根据异常页面视图对象渲染显示包括与异常类型编码对应的异常信息的页面。
具体地,前端控制器调用视图解析对象,请求视图解析对象对新模型视图对象进行解析,视图解析对象解析后得到页面地址,该页面地址中的页面是用于显示与该异常类型编码对应的错误信息,前端控制器可以根据返回的页面地址和新模型视图对象中的模型数据,生成异常页面对象,这样,客户端就可以根据异常页面对象渲染显示包括与出现的异常类型编码对应的异常信息的页面,用户可以根据异常信息明确异常原因。
上述基于Spring MVC的异常处理方法,在通过前端控制器找到目标处理器对象处理客户端发送的资源请求得到模型视图对象后,在对模型视图对象进行解析之前,通过前端控制器调用拦截器接口类的回调函数对得到的模型视图对象进行验证,当模型视图对象存在异常时不会通过验证,回调函数会返回与异常对应的异常类型编码,不同的异常会返回不同的异常类型编码,实现对不同异常的统一处理,再进一步调用异常处理对象对返回的异常类型编码进行处理得到新模型视图对象,而新的模型视图对象可以用于生成异常页面视图对象,当客户端接收到前端控制器返回的新模型视图对象时,可以根据新模型视图对象渲染并显示包括异常信息的页面,该异常信息与该异常类型编码对应,实现了对各种异常信息的统一处理。
如图3所示,为一个具体的实施例中基于Spring MVC的异常处理方法的框架示意图。参照图3,该方法具体包括以下步骤:
1、通过前端控制器(WebSupportDispatcherServlet)接收资源请求,并根据该资源请求中的资源标识符查找与该资源请求对应的处理器映射器(WebSupportHandler Mapping);
2、若未查找到处理器映射器,则根据资源标识符获取相应的静态资源,若找不到相应的静态资源,则报404错误;
3、若查找到处理器映射器,则映射处理器根据自己的配置或注解(WebSupportWeb2AppBeanPostProcessor)把请求映射为执行链对象(HandlerExecutionChain),并将执行链对象返回给前端控制器,执行链对象包括一个处理器对象(Handler)和多个拦截器对象(HandlerInterceotor);
4、前端控制器遍历配置的所有适配器,查找与处理器对象对应的处理器适配器HandlerAdapter;
5、调用拦截器对象的预处理(preHandle)方法,该方法将在用户的资源请求被处理之前被调用,当该方法被调用后并返回true时,才会执行步骤6;
6、处理器适配器调用与处理器对象适配的具体的目标处理器,通过目标处理器处理资源请求,目标处理器处理完毕后返回模型视图对象(ModelAndView);
7、在处理资源请求之后,调用拦截器对象的回调函数(postHandler),对得到的模型视图对象进行操作;
8、若存在异常,并返回了异常类型编码,则调用继承自异常处理接口(HandlerExceptionResolver)的异常处理类(WebMappingExceptionResolver)对异常类型编码进行处理,返回发生新模型视图对象给前端控制器;
9、前端控制器将新模型视图对象传递给视图解析器ViewResolver,视图解析器根据配置将新模型视图对象中的逻辑视图名解析为具体的视图对象(View),并返回给前端控制器;前端控制器根据视图对象对传进来的模型数据进行渲染得到响应数据。
应该理解的是,虽然图2、图3的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,图2、图3中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些子步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。
在其中一个实施例中,如图4所示,提供了一种基于Spring MVC的异常处理装置400,包括:资源请求获取模块402、目标处理器对象获取模块404、模型视图对象获取模块406、回调处理模块408和异常处理模块410,其中:
资源请求获取模块402,用于通过前端控制器获取客户端发送的资源请求;
模型视图对象获取模块404,用于根据资源请求中的资源标识符确定对应的目标处理器对象,并通过目标处理器对象处理资源请求,得到模型视图对象;
回调处理模块406,用于调用拦截器接口类的回调函数对模型视图对象进行验证;
异常处理模块408,用于当回调函数返回异常类型编码时,则调用异常处理对象对异常类型编码进行处理得到新模型视图对象;通过前端控制器根据新模型视图对象生成异常页面视图对象;异常页面视图对象用于令客户端显示包括与异常类型编码对应的异常信息的页面。
在其中一个实施例中,模型视图对象获取模块404还用于从资源请求中提取资源标识符;通过前端控制器根据资源标识符调用相应的映射器对象;通过映射器对象获取与资源请求对应的处理器对象;通过前端控制器查找与处理器对象对应的处理器适配器;通过处理器适配器从处理器对象中确定目标处理器对象。
在其中一个实施例中,目标处理器对象继承自同一处理器接口类;模型视图对象获取模块404还用于获取处理器接口类定义的参数处理函数;将资源请求中的请求参数作为函数参数传递给参数处理函数,获取参数处理函数返回的与资源请求对应的模型视图对象。
在其中一个实施例中,异常处理对象继承自同一异常处理接口类;异常处理模块408还用于获取异常处理接口类定义的异常处理函数;将异常类型编码作为函数参数传递给异常处理函数,获取异常处理函数返回的新模型视图对象。
在其中一个实施例中,异常处理模块408还用于通过前端控制器调用视图解析对象;通过视图解析对象对新模型视图对象中的逻辑视图名进行解析,得到页面地址;根据新模型视图对象中的模型数据和页面地址,生成异常页面视图对象;将异常页面视图对象返回至客户端,以使客户端根据异常页面视图对象渲染显示包括与异常类型编码对应的异常信息的页面。
在其中一个实施例中,模型视图对象包括逻辑视图名和模型数据,装置还包括视图解析模块,视图解析模块用于当回调函数未返回异常类型编码时,则通过前端控制器获取视图解析对象;通过视图解析对象对逻辑视图名进行解析,得到视图对象;通过视图对象渲染模型数据,得到响应数据;通过前端控制器将响应数据返回至客户端。
在其中一个实施例中,装置还包括异常信息编码模块,异常信息编码模块用于获取异常信息,对各异常信息进行分类;按照各异常信息的类型进行编码,得到异常类型编码。
上述基于Spring MVC的异常处理装置,在通过前端控制器找到目标处理器对象处理客户端发送的资源请求得到模型视图对象后,在对模型视图对象进行解析之前,通过前端 控制器调用拦截器接口类的回调函数对得到的模型视图对象进行验证,当模型视图对象存在异常时不会通过验证,回调函数会返回与异常对应的异常类型编码,不同的异常会返回不同的异常类型编码,实现对不同异常的统一处理,再进一步调用异常处理对象对返回的异常类型编码进行处理得到新模型视图对象,而新的模型视图对象可以用于生成异常页面视图对象,当客户端接收到前端控制器返回的新模型视图对象时,可以根据新模型视图对象渲染并显示包括异常信息的页面,该异常信息与该异常类型编码对应,实现了对各种异常信息的统一处理。
关于基于Spring MVC的异常处理装置的具体限定可以参见上文中对于基于Spring MVC的异常处理方法的限定,在此不再赘述。上述基于Spring MVC的异常处理装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。
在其中一个实施例中,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图可以如图5所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口和数据库。该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统、计算机可读指令和数据库。该内存储器为非易失性存储介质中的操作系统和计算机可读指令的运行提供环境。该计算机设备的数据库用于存储网页资源数据。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机可读指令被处理器执行时以实现一种基于Spring MVC的异常处理方法。
本领域技术人员可以理解,图5中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
在其中一个实施例中,本申请提供的基于Spring MVC的异常处理装置可以实现为一种计算机可读指令的形式,计算机可读指令可在如图5所示的计算机设备上运行。计算机设备的存储器中可存储组成该基于Spring MVC的异常处理装置的各个程序模块,比如, 图4所示的资源请求获取模块402、模型视图对象获取模块404、回调处理模块406和异常处理模块408。各个程序模块构成的计算机可读指令使得处理器执行本说明书中描述的本申请各个实施例的基于Spring MVC的异常处理方法中的步骤。
例如,图5所示的计算机设备可以通过如图Z所示的基于Spring MVC的异常处理装置中的资源请求获取模块402执行步骤S202。计算机设备可通过模型视图对象获取模块404执行步骤S204。计算机设备可通过回调处理模块406执行步骤S208。计算机设备可通过异常处理模块408执行步骤S210。
一种计算机设备,包括存储器和一个或多个处理器,存储器中储存有计算机可读指令,计算机可读指令被处理器执行时,使得一个或多个处理器执行本申请各个实施例的基于Spring MVC的异常处理方法中的步骤。
一个或多个存储有计算机可读指令的非易失性计算机可读存储介质,计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行本申请各个实施例的基于Spring MVC的异常处理方法中的步骤。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机可读指令来指令相关的硬件来完成,所述的计算机可读指令可存储于一非易失性计算机可读取存储介质中,该计算机可读指令在执行时,可包括如上述各方法的实施例的流程。本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。
以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。
以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。
Claims (20)
- 一种基于Spring MVC的异常处理方法,包括:通过前端控制器获取客户端发送的资源请求;根据所述资源请求中的资源标识符确定对应的目标处理器对象,并通过所述目标处理器对象处理所述资源请求,得到模型视图对象;调用拦截器接口类的回调函数对所述模型视图对象进行验证;当所述回调函数返回异常类型编码时,则调用异常处理对象对所述异常类型编码进行处理得到新模型视图对象;及通过所述前端控制器根据所述新模型视图对象生成异常页面视图对象;所述异常页面视图对象用于令所述客户端显示包括与所述异常类型编码对应的异常信息的页面。
- 根据权利要求1所述的方法,其特征在于,所述根据所述资源请求中的资源标识符确定对应的目标处理器对象,包括:从所述资源请求中提取资源标识符;通过所述前端控制器根据所述资源标识符调用相应的映射器对象;通过所述映射器对象获取与所述资源请求对应的处理器对象;通过所述前端控制器查找与所述处理器对象对应的处理器适配器;及通过所述处理器适配器从所述处理器对象中确定目标处理器对象。
- 根据权利要求1所述的方法,其特征在于,所述目标处理器对象继承自同一处理器接口类;所述通过所述目标处理器对象处理所述资源请求,得到模型视图对象,包括:获取所述处理器接口类定义的参数处理函数;及将所述资源请求中的请求参数作为函数参数传递给所述参数处理函数,获取所述参数处理函数返回的与所述资源请求对应的模型视图对象。
- 根据权利要求1所述的方法,其特征在于,所述异常处理对象继承自同一异常处理接口类;所述调用异常处理对象对所述异常类型编码进行处理得到新模型视图对象,包括:获取所述异常处理接口类定义的异常处理函数;及将所述异常类型编码作为函数参数传递给所述异常处理函数,获取所述异常处理函数 返回的新模型视图对象。
- 根据权利要求1所述的方法,其特征在于,所述通过所述前端控制器根据所述新模型视图对象生成异常页面视图对象,包括:通过所述前端控制器调用视图解析对象;通过所述视图解析对象对所述新模型视图对象中的逻辑视图名进行解析,得到页面地址;根据所述新模型视图对象中的模型数据和所述页面地址,生成异常页面视图对象;及将所述异常页面视图对象返回至所述客户端,令所述客户端根据所述异常页面视图对象渲染显示包括与所述异常类型编码对应的异常信息的页面。
- 根据权利要求1至5所述的方法,其特征在于,所述模型视图对象包括逻辑视图名和模型数据,所述方法还包括:当所述回调函数未返回异常类型编码时,则通过所述前端控制器获取视图解析对象;通过所述视图解析对象对所述逻辑视图名进行解析,得到视图对象;通过所述视图对象渲染所述模型数据,得到响应数据;及通过所述前端控制器将所述响应数据返回至客户端。
- 根据权利要求1至5中任一项所述的方法,其特征在于,所述方法还包括:获取异常信息,对各所述异常信息进行分类;及按照各所述异常信息的类型进行编码,得到异常类型编码。
- 一种基于Spring MVC的异常处理装置,包括:资源请求获取模块,用于通过前端控制器获取客户端发送的资源请求;模型视图对象获取模块,用于根据所述资源请求中的资源标识符确定对应的目标处理器对象;并通过所述目标处理器对象处理所述资源请求,得到模型视图对象;回调处理模块,用于调用拦截器接口类的回调函数对所述模型视图对象进行验证;及异常处理模块,用于当所述回调函数返回异常类型编码时,则调用异常处理对象对所述异常类型编码进行处理得到新模型视图对象;通过所述前端控制器根据所述新模型视图 对象生成异常页面视图对象;所述异常页面视图对象用于令所述客户端显示包括与所述异常类型编码对应的异常信息的页面。
- 根据权利要求8所述的装置,其特征在于,所述模型视图对象获取模块,还用于从所述资源请求中提取资源标识符;通过所述前端控制器根据所述资源标识符调用相应的映射器对象;通过所述映射器对象获取与所述资源请求对应的处理器对象;通过所述前端控制器查找与所述处理器对象对应的处理器适配器;及通过所述处理器适配器从所述处理器对象中确定目标处理器对象。
- 根据权利要求8所述的装置,其特征在于,所述目标处理器对象继承自同一处理器接口类;所述模型视图对象获取模块,还用于获取所述处理器接口类定义的参数处理函数;及将所述资源请求中的请求参数作为函数参数传递给所述参数处理函数,获取所述参数处理函数返回的与所述资源请求对应的模型视图对象。
- 根据权利要求8所述的装置,其特征在于,所述异常处理对象继承自同一异常处理接口类;所述异常处理模块,还用于获取所述异常处理接口类定义的异常处理函数;及将所述异常类型编码作为函数参数传递给所述异常处理函数,获取所述异常处理函数返回的新模型视图对象。
- 根据权利要求8所述的装置,其特征在于,所述异常处理模块,还用于通过所述前端控制器调用视图解析对象;通过所述视图解析对象对所述新模型视图对象中的逻辑视图名进行解析,得到页面地址;根据所述新模型视图对象中的模型数据和所述页面地址,生成异常页面视图对象;及将所述异常页面视图对象返回至所述客户端,令所述客户端根据所述异常页面视图对象渲染显示包括与所述异常类型编码对应的异常信息的页面。
- 根据权利要求8至11任一项所述的装置,其特征在于,所述模型视图对象包括逻辑视图名和模型数据,所述装置还包括视图解析模块,所述视图解析模块用于当所述回调函数未返回异常类型编码时,则通过所述前端控制器获取视图解析对象;通过所述视图解析对象对所述逻辑视图名进行解析,得到视图对象;通过所述视图对象渲染所述模型数据,得到响应数据;及通过所述前端控制器将所述响应数据返回至客户端。
- 根据权利要求8至11任一项所述的装置,其特征在于,所述装置还包括异常信息编码模块,所述异常信息编码模块用于获取异常信息,对各所述异常信息进行分类;及 按照各所述异常信息的类型进行编码,得到异常类型编码。
- 一种计算机设备,包括存储器及一个或多个处理器,所述存储器中储存有计算机可读指令,所述计算机可读指令被所述一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤:通过前端控制器获取客户端发送的资源请求;根据所述资源请求中的资源标识符确定对应的目标处理器对象,并通过所述目标处理器对象处理所述资源请求,得到模型视图对象;调用拦截器接口类的回调函数对所述模型视图对象进行验证;当所述回调函数返回异常类型编码时,则调用异常处理对象对所述异常类型编码进行处理得到新模型视图对象;及通过所述前端控制器根据所述新模型视图对象生成异常页面视图对象;所述异常页面视图对象用于令所述客户端显示包括与所述异常类型编码对应的异常信息的页面。
- 根据权利要求15所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令时还执行以下步骤:从所述资源请求中提取资源标识符;通过所述前端控制器根据所述资源标识符调用相应的映射器对象;通过所述映射器对象获取与所述资源请求对应的处理器对象;通过所述前端控制器查找与所述处理器对象对应的处理器适配器;及通过所述处理器适配器从所述处理器对象中确定目标处理器对象。
- 根据权利要求15所述的计算机设备,其特征在于,所述目标处理器对象继承自同一处理器接口类;所述处理器执行所述计算机可读指令时还执行以下步骤:获取所述处理器接口类定义的参数处理函数;及将所述资源请求中的请求参数作为函数参数传递给所述参数处理函数,获取所述参数处理函数返回的与所述资源请求对应的模型视图对象。
- 一个或多个存储有计算机可读指令的非易失性计算机可读存储介质,所述计算 机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤:通过前端控制器获取客户端发送的资源请求;根据所述资源请求中的资源标识符确定对应的目标处理器对象,并通过所述目标处理器对象处理所述资源请求,得到模型视图对象;调用拦截器接口类的回调函数对所述模型视图对象进行验证;当所述回调函数返回异常类型编码时,则调用异常处理对象对所述异常类型编码进行处理得到新模型视图对象;及通过所述前端控制器根据所述新模型视图对象生成异常页面视图对象;所述异常页面视图对象用于令所述客户端显示包括与所述异常类型编码对应的异常信息的页面。
- 根据权利要求18所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行时还执行以下步骤:从所述资源请求中提取资源标识符;通过所述前端控制器根据所述资源标识符调用相应的映射器对象;通过所述映射器对象获取与所述资源请求对应的处理器对象;通过所述前端控制器查找与所述处理器对象对应的处理器适配器;及通过所述处理器适配器从所述处理器对象中确定目标处理器对象。
- 根据权利要求18所述的存储介质,其特征在于,所述目标处理器对象继承自同一处理器接口类;所述计算机可读指令被所述处理器执行时还执行以下步骤:获取所述处理器接口类定义的参数处理函数;及将所述资源请求中的请求参数作为函数参数传递给所述参数处理函数,获取所述参数处理函数返回的与所述资源请求对应的模型视图对象。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910243158.4A CN110069297B (zh) | 2019-03-28 | 2019-03-28 | 基于Spring MVC的异常处理方法、装置、计算机设备和存储介质 |
| CN201910243158.4 | 2019-03-28 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2020192134A1 true WO2020192134A1 (zh) | 2020-10-01 |
Family
ID=67366911
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2019/117506 Ceased WO2020192134A1 (zh) | 2019-03-28 | 2019-11-12 | 基于Spring MVC的异常处理方法、装置、计算机设备和存储介质 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN110069297B (zh) |
| WO (1) | WO2020192134A1 (zh) |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114579194A (zh) * | 2022-03-08 | 2022-06-03 | 杭州每刻科技有限公司 | 一种基于Spring远程调用的异常处理方法和系统 |
| CN115563606A (zh) * | 2021-12-22 | 2023-01-03 | 上海分蛋信息科技有限公司 | 一种限定重复请求的方法 |
| CN120805164A (zh) * | 2025-09-12 | 2025-10-17 | 浙江智慧信息产业有限公司 | 基于ai模型的能源业务处理方法和国产化前台业务办理终端 |
Families Citing this family (14)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110069297B (zh) * | 2019-03-28 | 2024-06-28 | 平安科技(深圳)有限公司 | 基于Spring MVC的异常处理方法、装置、计算机设备和存储介质 |
| CN110727537B (zh) * | 2019-10-21 | 2023-12-26 | 深圳前海环融联易信息科技服务有限公司 | 统一处理响应报文的方法、装置、计算机设备及存储介质 |
| CN111427701A (zh) * | 2020-03-09 | 2020-07-17 | 中国建设银行股份有限公司 | 一种工作流引擎系统和业务处理方法 |
| CN111722881B (zh) * | 2020-05-22 | 2023-08-08 | 广东浪潮大数据研究有限公司 | 一种容器云平台的资源扩展方法、系统及装置 |
| CN113778726A (zh) * | 2020-06-09 | 2021-12-10 | 武汉斗鱼网络科技有限公司 | 一种错误信息处理方法、装置、服务器和存储介质 |
| CN112083952A (zh) * | 2020-08-26 | 2020-12-15 | 武汉普利商用机器有限公司 | 一种基于spring架构的异常处理方法及系统 |
| CN112363720B (zh) * | 2020-11-30 | 2024-02-23 | 中国银行股份有限公司 | 基于Spring Restful框架实现公共控制逻辑的方法及装置 |
| CN112766769B (zh) * | 2021-01-26 | 2023-11-21 | 南京利特嘉软件科技有限公司 | 一种基于大数据的客户评估方法及系统 |
| CN113742179A (zh) * | 2021-07-22 | 2021-12-03 | 上海闻泰电子科技有限公司 | 异常信息的显示方法、装置、电子设备和介质 |
| CN113741870B (zh) * | 2021-08-20 | 2023-07-14 | 苏州浪潮智能科技有限公司 | 一种获取Spring框架中数据的方法、系统、设备和存储介质 |
| CN113946460B (zh) * | 2021-09-14 | 2025-06-27 | 杭州群核信息技术有限公司 | 处理系统 |
| CN114327425B (zh) * | 2021-12-23 | 2025-09-19 | 中国农业银行股份有限公司 | 视图生成方法、装置、电子设备和存储介质 |
| CN115309447A (zh) * | 2022-08-15 | 2022-11-08 | 中国银行股份有限公司 | 基于Spring和Maven的接口文档自动生成方法和装置 |
| CN116566810A (zh) * | 2023-05-10 | 2023-08-08 | 上海中通吉网络技术有限公司 | 一种基于Spring MVC框架的系统异常处理方法、装置和设备 |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20130007325A1 (en) * | 2011-07-01 | 2013-01-03 | Sahita Ravi L | Secure handling of interrupted events |
| CN103955510A (zh) * | 2014-04-30 | 2014-07-30 | 广西电网公司电力科学研究院 | 基于etl云平台上传的海量电力营销数据整合方法 |
| CN104317591A (zh) * | 2014-10-23 | 2015-01-28 | 西安未来国际信息股份有限公司 | 一种基于OSGi的web界面框架系统及web业务处理方法 |
| CN106484509A (zh) * | 2016-09-27 | 2017-03-08 | 腾讯科技(深圳)有限公司 | 一种弹窗的输出方法、装置及终端 |
| CN110069297A (zh) * | 2019-03-28 | 2019-07-30 | 平安科技(深圳)有限公司 | 基于Spring MVC的异常处理方法、装置、计算机设备和存储介质 |
Family Cites Families (8)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104267944A (zh) * | 2014-09-22 | 2015-01-07 | 浪潮软件集团有限公司 | 一种基于Spring的MVC模式优化系统 |
| CN105843609A (zh) * | 2016-03-18 | 2016-08-10 | 浪潮软件集团有限公司 | 一种基于Spring和MyBatis的MVC框架 |
| CN105867948A (zh) * | 2016-04-26 | 2016-08-17 | 江苏物联网研究发展中心 | 基于AJAX和SpringMVC的WEB开发方法 |
| CN106446023A (zh) * | 2016-08-29 | 2017-02-22 | 江苏数加数据科技有限责任公司 | 基于AngularJS和Bootstrap实现的双公示生产数据前端展示系统及方法 |
| CN107172122A (zh) * | 2017-03-31 | 2017-09-15 | 北京奇艺世纪科技有限公司 | 一种异常处理方法及装置 |
| CN107590202A (zh) * | 2017-08-21 | 2018-01-16 | 深圳市华宇兄弟科技股份公司 | 一种企业平台快速应用的方法及系统 |
| CN107705079A (zh) * | 2017-11-08 | 2018-02-16 | 厦门旺集信息科技有限公司 | 物流仓储管理系统处理方法以及跨境电商交易方法 |
| CN108762966A (zh) * | 2018-06-05 | 2018-11-06 | 中国平安人寿保险股份有限公司 | 系统异常拦截方法、装置、计算机设备及存储介质 |
-
2019
- 2019-03-28 CN CN201910243158.4A patent/CN110069297B/zh active Active
- 2019-11-12 WO PCT/CN2019/117506 patent/WO2020192134A1/zh not_active Ceased
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20130007325A1 (en) * | 2011-07-01 | 2013-01-03 | Sahita Ravi L | Secure handling of interrupted events |
| CN103955510A (zh) * | 2014-04-30 | 2014-07-30 | 广西电网公司电力科学研究院 | 基于etl云平台上传的海量电力营销数据整合方法 |
| CN104317591A (zh) * | 2014-10-23 | 2015-01-28 | 西安未来国际信息股份有限公司 | 一种基于OSGi的web界面框架系统及web业务处理方法 |
| CN106484509A (zh) * | 2016-09-27 | 2017-03-08 | 腾讯科技(深圳)有限公司 | 一种弹窗的输出方法、装置及终端 |
| CN110069297A (zh) * | 2019-03-28 | 2019-07-30 | 平安科技(深圳)有限公司 | 基于Spring MVC的异常处理方法、装置、计算机设备和存储介质 |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115563606A (zh) * | 2021-12-22 | 2023-01-03 | 上海分蛋信息科技有限公司 | 一种限定重复请求的方法 |
| CN114579194A (zh) * | 2022-03-08 | 2022-06-03 | 杭州每刻科技有限公司 | 一种基于Spring远程调用的异常处理方法和系统 |
| CN114579194B (zh) * | 2022-03-08 | 2024-04-05 | 杭州每刻科技有限公司 | 一种基于Spring远程调用的异常处理方法和系统 |
| CN120805164A (zh) * | 2025-09-12 | 2025-10-17 | 浙江智慧信息产业有限公司 | 基于ai模型的能源业务处理方法和国产化前台业务办理终端 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN110069297B (zh) | 2024-06-28 |
| CN110069297A (zh) | 2019-07-30 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2020192134A1 (zh) | 基于Spring MVC的异常处理方法、装置、计算机设备和存储介质 | |
| CN112910945B (zh) | 请求链路跟踪方法和业务请求处理方法 | |
| CN111324905B (zh) | 影像数据标注方法、装置、计算机设备和存储介质 | |
| CN110209652B (zh) | 数据表迁移方法、装置、计算机设备和存储介质 | |
| WO2020151333A1 (zh) | 页面加载方法、装置、计算机设备和存储介质 | |
| CN109582303B (zh) | 通用组件调用方法、装置、计算机设备及存储介质 | |
| CN110109656B (zh) | 接口模拟方法、装置、计算机设备和存储介质 | |
| CN109460527B (zh) | 产品数据配置方法、装置、计算机设备和存储介质 | |
| WO2020253061A1 (zh) | 页面生成方法、装置、计算机设备和存储介质 | |
| WO2020186786A1 (zh) | 文件处理方法、装置、计算机设备和存储介质 | |
| WO2020181839A1 (zh) | 页面数据测试方法、装置、计算机设备和存储介质 | |
| CN111859224A (zh) | 基于节点服务器的服务端渲染方法、装置和计算机设备 | |
| WO2021217846A1 (zh) | 接口数据处理方法、装置、计算机设备和存储介质 | |
| CN110908778B (zh) | 任务部署方法、系统和存储介质 | |
| WO2018184535A1 (zh) | 保险业务处理方法、装置、服务器和存储介质 | |
| US10382313B2 (en) | Test building for testing server operation | |
| WO2020199594A1 (zh) | 业务组件加载方法、装置、计算机设备和存储介质 | |
| WO2021120628A1 (zh) | 基于区块链的敏感词检测方法、装置、计算机设备和计算机可读存储介质 | |
| CN113377376A (zh) | 数据包生成方法、数据包生成装置、电子设备及存储介质 | |
| US20130167124A1 (en) | Detection of custom parameters in a request url | |
| CN112579705A (zh) | 元数据采集方法、装置、计算机设备和存储介质 | |
| CN111901383B (zh) | 数据请求处理方法、装置、计算机设备和存储介质 | |
| CN115130002A (zh) | 推荐请求处理方法、装置、计算机设备、存储介质 | |
| CN114721929B (zh) | 测试方法、装置、存储介质及设备 | |
| CN114296793A (zh) | 混淆代码的反混淆方法、装置、可读介质及电子设备 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 19921552 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 19921552 Country of ref document: EP Kind code of ref document: A1 |