How the SPRINGMVC works

Source: Internet
Author: User

First, Spring introductionSpringmvcis aSpringa module of the framework,Springmvcand theSpringno need to develop through an intermediate integration layer. Springmvcis a based onMVCof theWebFramework.   Spring Web MVCand theStruts2is the framework of the presentation layer.,It isSpringpart of the framework,we can get fromSpring's overall structure:Second, the application of MVC in B/s system1.User initiatedRequestRequest to Controller(Controller)control the data received from user requests and delegate to the model for processing2.controller through Model(Model)process data and get processing resultsthe model usually refers to the business logic3.model processing results returned to the controller4.the controller will model data in the view(View)Show in  Webthe model cannot display data directly on the view and needs to be done through the controller. If theC/Sin-app models are the data that can be displayed in a view. 5.controller will viewResponseResponding to users      show the data to the user or process the results through a view. Three, spring working principle

(1).initiating a request to the front-end controller(Dispatcherservlet);(2).front-end controller requesthandlermappingFindHandler, can be based onXMLconfiguration, annotation to find;(3).Processor Mapperhandlermappingback to Front controllerHandler;(4).The front controller invokes the processor adapter to performHandler;(5).Processor adapter to performHandler;(6). Handlerexecution finishes to adapter returnModelandview;(7).the processor adapter returns to the front-end controllerModelandview (is aSpringmvcone of the underlying objects of the framework, includingModeland theView);(8).The Front controller requests the view resolver to parse the view, resolving the real view based on the logical view name(JSP ...);(9).The view resolver returns to the front-end controllerView;(Ten).front-end controller for view rendering, view rendering is the model data(in theModelandviewobject in)Fill toRequestthe domain. (one).the front controller responds to the user's results. Iv. Introduction of Components 1 , front-end controller Dispatcherservlet (No siege lion development required), provided by the frameworkfunction: Receive request, response result, equivalent to transponder, CPU. With theDispatcherservletthe coupling between the other components is reduced.        a user request arrives at the front controller, which is equivalent toMVCin the patternC,Dispatcherservletis the center of the entire process control, which calls other components to process the user's request,Dispatcherservletthe presence of a component reduces the coupling between components. 2 , processor mapper handlermapping ( no need for siege lion development ), provided by the frameworkfunction: According to the requestedURLFindHandler    handlermappingresponsible for the user request to findHandlerthat is, the processor,SpringmvcDifferent Mapper is provided to implement different mapping methods, such as: Configuration file mode, interface mode, annotation method and so on. 3 , processor Adapter Handleradapterrole: According to specific rules (Handleradapterrequired rules) to executeHandler       throughHandleradapterexecution of the processor, which is an application of the adapter pattern, can be performed on more types of processors through the extension adapter. 4 , Processor Handler ( need to develop siege Lions )  Note: Write Handler When you follow Handleradapter required to do so the adapter can go to the correct execution HandlerHandleris the followingDispatcherservletthe back-end controller of the front -end controllerDispatcherservletunder the controlHandlerprocessing of specific user requests.      becauseHandlerrelated to specific user business requests, so the general situation requires the siege lion to develop according to business requirementsHandler. 5 , view resolver View Resolver ( no need for siege lion development ), provided by the frameworkfunction: Perform a view resolution that resolves to a real view based on the logical view name (View)  View Resolverresponsible for generating the processing resultsViewView,View ResolverFirst, the logical view name is parsed into the physical view name that is the specific page address, and then the generatedViewView object, and finally theViewrendering renders the processing results to the user through the page. SpringmvcThe framework provides a lot ofViewview types, including:Jstlview,Freemarkerview,Pdfviewand so on. In General, the model data needs to be presented to the user through page labels or page template technology, and the specific page needs to be developed by the siege Lion according to the business requirements. 6 , Views View ( need to develop siege Lions jsp ... )  Viewis an interface that implements classes that support differentViewType (JSP,Freemarker,PDF ...)

VC in B/s system should be two, MVC in the B/S system Application

How the SPRINGMVC works

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.