"SPRINGMVC" Study notes

Source: Internet
Author: User
Tags lenovo

Application of 1.SpringMVC frame 1.1 MVC in B/s system
    1. User sends request to controller
    2. Controller request model for processing
    3. Model returns the processing result to the controller
    4. Controller accepts processing results from model send
    5. Render the view, populate the model data in the request domain (view)
    6. Responding to a user's request

1.2 Springmvc Frame
    1. Initiating a request to a front-end controller (dispatcherservlet)
    2. Front Controller request Handlermapping Find handler

(Can be found based on XML configuration, annotations)

    1. Processor Mapper Handlermapping back to the front-end controller Handler
    2. The front controller invokes the processor adapter (Handleradapter) to perform the handler
    3. Processor Adapter Execution Handler
    4. Handler execution completes to adapter return Modelandview
    5. Processor Adapter returns Modelandview to the front-end controller

Modelandview is an underlying object of the SPRINGMVC framework, including model and view

    1. The front controller requests the view resolver to parse the view and parse it into a real view (JSP) based on the logical view name.
    2. View Resolver returns to Front controller view
    3. Front controller for view rendering, view rendering populates model data (in the Modelandview object) into the request domain
    4. Front-end controller responds to user results

1.3 Components
    1. Front Controller Dispatcherservlet (no program Ape development required)

function accept request, response result, equivalent to transponder, CPU

With the Dispatcherservlet, the coupling of other components is reduced.

    1. Processor Mapper handlermapping (no program Ape development required)

Function: Find handler based on the URL requested

    1. Processor Adapter Handleradapter (no program Ape development required)

Function: Execute handler According to the specific rules (Handleradapter requirements)

    1. Processor handler (requires program Ape development)

Function: Write handler in accordance with handleradapter requirements to do, so that the adapter can go to the correct execution handler

    1. View Resolver views Resolve (no program ape development required)

Function: Perform a view resolution, resolve to a real view based on the logical View name (view)

    1. Views view (Requires program Ape development)

View is an interface that implements classes that support different view types (JSP, Freemarker, pdf)

2. Development Step 2.1 Requirements 2.2 environment preparation

Need to spring3.2 all jars (must include Spring-webmvc-3.2.0.release.jar)

2.3 Configuring the front-end controller

Configuring the front-end controller in Web. xml

<servlet><Servlet-name>Springmvc</Servlet-name><Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class><Init-param><Param-name>Contextconfiglocation</Param-name><Param-value>Classpath:springmvc.xml</Param-value></Init-param><Load-on-startup>1</Load-on-startup></servlet><servlet-mapping><Servlet-name>Springmvc</Servlet-name><Url-pattern>*.action</Url-pattern></servlet-mapping>
2.4 Configuring the Processor adapter

Configuring the processor adapter in the Springmvc.xml under Classpath

<!---<class= " Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter "/>

2.5 Development Handler

The Controller interface needs to be implemented,

Can be performed by the Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter adapter

 Public classItemsController1ImplementsController {@Override PublicModelandview HandleRequest (httpservletrequest request, httpservletresponse response)throwsException {//Call Service Lookup database, query commodity list, use static data simulation hereList<items> itemslist =NewArraylist<items>(); //populating the list with static dataItems items_1=NewItems (); Items_1.setname ("Lenovo Notebook");        Items_1.setprice (6000F); Items_1.setdetail ("ThinkPad T430 Lenovo notebook computer! "); Items items_2=NewItems (); Items_2.setname ("Apple Phone");        Items_2.setprice (5000F); Items_2.setdetail ("Iphone6 Apple phone!" ");        Itemslist.add (Items_1);        Itemslist.add (items_2); //back to ModelandviewModelandview Modelandview =NewModelandview (); //equivalent to the request of Setattribut, in the JSP page through itemslist fetching dataModelandview.addobject ("Itemslist", itemslist); //Specify a ViewModelandview.setviewname ("/web-inf/jsp/items/itemslist.jsp"); returnModelandview; }}
2.6 View Writing 2.7 configuration Handler

Will write handler loaded in the Spring container springmvc.xml

<!---<name= "/items1.action"  ID = "ItemList1" class = "Cn.itcast.springmvc.controller." ItemsController1"/>

Name= "/items1.action": The processor mapper configured in front of Beannameurlhandlermapping will successfully map to the ITEMLIST1 controller if the requested URL is "context/items1.action".

2.8 Configuring the Processor Mapper

Configuring the Processor mapper in the Spring.xml under Classpath

<!---<!---<class  = "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
2.9 Configuring the View resolver

You need to configure the view parser to parse the JSP.

"SPRINGMVC" Study notes

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.