Springmvc Framework Learning Notes (i)

Source: Internet
Author: User
Tags lenovo

In the study of the academic, to review the Java SPRINGMVC Framework, there are no projects recently, so there is a period of time without looking at this framework, are a little strange, and now every day in the reading paper, research programs, do experiments, In the paper can not see the time to learn about Springmvc is also a good choice, HAHAHA!!!!!!

1. SPRINGMVC Frame 1.1 What is SPRINGMVC

SPRINGMVC is a module of the spring Framework, and SPRINGMVC and spring do not need to be consolidated through an intermediate integration layer. SPRINGMVC is an MVC-based web framework.

Application of 1.2 MVC in B/s system

MVC is a design pattern, the application of MVC in B/s system:

1.3 Springmvc Frame

Steps:

First step: Initiating a request to the front-end controller (dispatcherservlet)

Step Two: Front controller request handlermapping find Handler

Can be found based on XML configuration, annotations

Step Three: Processor mapper handlermapping back to the front-end controller Handler

Fourth step: The front controller calls the processor adapter to execute the handler

Fifth Step: Processor adapter to perform handler

Sixth step: Handler execution completes to the adapter return Modelandview

Seventh Step: The processor adapter returns Modelandview to the front-end controller

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

Eighth step: The front controller requests the view parser to carry on the visual diagram analysis

Resolves to a real view (JSP) based on the logical view name

Nineth Step: View Resolver to Front controller return view

Tenth step: Front controller for view rendering

View rendering fills the model data (in the Modelandview object) into the request field

11th Step: Front controller responds to user results

Component:

1. Front Controller dispatcherservlet (no programmer development required)

function receive request, response result, equivalent to transponder, CPU.

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

2, Processor mapper handlermapping (no programmer development required)

Function: Find handler based on the URL requested

3. Processor Adapter Handleradapter

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

4. Processor handler (programmer development Required)

Note: When writing handler, follow Handleradapter's instructions so that the adapter can go to the correct execution handler

5. View Resolver views Resolver (no programmer development required)

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

6. Views view (requires programmer to develop JSP)

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

2. Starter Program 2.1 Requirements

Driven by a case.

Springmvc and Mybaits use a case (commodity order management).

Functional Requirements: Product List Query

2.2 Environment Preparation

Database environment: mysql5.7

Java environment:

jdk1.8.0

apache-tomcat-8.0.51

Eclipse Neon

SPRINGMVC version: spring3.2

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

2.3 Configuring the front-end controller

Configure the front-end controller in Web. Xml.

2.4 Configuring the Processor adapter

Configuring the processor adapter in the Springmvc.xml under Classpath

By viewing the source code:

This adapter can perform the handler of the Controller interface.

2.5 Development Handler

The Controller interface needs to be implemented to 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 setattribute, 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 Authoring

2.7 Configuring Handler

The handler will be written to load in the spring container.

2.8 Configuring the Processor Mapper

Configuring the Processor mapper in the Springmvc.xml under Classpath

2.9 Configuring the View resolver

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

2.1 Deployment of Commissioning

Access Address: http://localhost:8080/springmvc/queryItems.action

The processor mapper cannot find the handler based on the URL, reporting the error below. Description URL error.

Processor mapper based on the URL found handler, forwarded JSP page found, reported the error below, indicating that the JSP page address is wrong.

At first, I encountered an error, prompting

Java.lang.ClassNotFoundException:org.springframework.web.servlet.Dispatcher

After you enter the correct address, and do not have access to the expected effect, after viewing the code, you find the path in the configuration file:

<servlet-class>org.springframework.web.servlet.dispatcherservlet </servlet-class

There is a problem, click to see if you can go in, found not to go, so that this path I guide the wrong, so that can not find this class, re-import source files, copy the correct full path after the correct access, problem solving.

The correct effect is expected:

To be continued ... ..... ........

Springmvc Framework Learning Notes (i)

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.