Understanding of the SPRINGMVC framework

Source: Internet
Author: User

SPRINGMVC Concept:
He is a lightweight open source framework that is applied to the presentation layer, based on the MVC design pattern.
SPRINGMVC features: 1. He is a singleton and can be set into multiple cases. 2. His thread is secure 3. He is based on method-level interception 4. The way to accept the request parameter is parameter binding 5. Carrying parameters to the page is through the request domain object.SPRINGMVC Process (focus) 1. The user sends a request to the server and is captured by the SPRINGMVC front-end controller Dispatchservlet.
2.DispatcherServlet receives the request and calls the Handlermapping processor mapper.
3. The processor mapper finds the specific processor (XML configuration or annotations, requesrtmapper), generates the Processor object, and the processor interceptor is returned to Dispatcherservlet
4.Dispatcherservlet Call Handleradapter Processor Adapter
5.HandlerAdapter through the adapter calls the specific processor (Controller)
6.Controller returns Modelandview after execution completes
7.HandlerAdapter Returns the controller execution result Modelandview to Dispatcherservlet
8.DispatcherServlet passing Modelandview to Viewreslover view parser
9.ViewReslover parse to return to specific view
10.DispatcherServlet render view based on view
11.DispatcherServlet finally responds to the user by rendering the finished view interface.
Several component descriptions in the SpringmvcDispatcherservlet: Front controller, control the whole process, he's Springmvc's entrance.
Handlermapper: Processor Mapper
Handleradapter: Processor Adapter
viewresolver: View resolver, can parse jsp,freemarker,pdf, etc.
Springmvc's Big Three: (interview may be asked)Handlermapper\handleradapter\viewresolver
MVC design Pattern ConceptsM-model (model, complete business logic: mainly JavaBean composition, service+dao+entity)
V-view (view layer, mainly to do the display of the page, jsp,html ...)
C-controller (Controller, call model layer after accepting request (M) return page based on result)
Springmvc frequently used annotations[email protected]: Tagged on the class, he will indicate that the class is a SPRINGMVC controller object. The processor will scan the method of the annotated class and detect if the method uses the @requestmapping annotation [email Protected] just defines the class controller class, and the annotation that really handles the request is @requestmapping.
Most frames are used when the integration is so marked on a class @controller is not really a SPRINGMVC controller, this time spring does not recognize this annotation, you need to give the Controller class to spring to manage, and then two ways: 1. Write the full path of this class directly<bean class= "com.xxx.xxx. Current Class"/>2. The path is written to the previous layer of the current controller annotation class
<context:component-scan base-package = "com.xxx"/> Note the current configuration @controller This class don't write it up.
controllers do not rely on HttpServlet objects such as HttpServletRequest and HttpServletResponse, which can be obtained directly from the controller's method parameters. Small Demo
@Controllerpublic class Savecontroller () {@RequestMapping ("/save") public String Save () {System.out.println        ("Save Saved");    Return "Success"; }}[email protected]
requestmapping is the annotation used to process the request URL
Six properties in requestmapping:
2.1--value: The actual address of the request
2.2--method: The type of the request. Get,post,put,delete, etc.
@RequestMapping (value= "", method= "Requestmethod.get")
2.3--consumes: Specifies the type of submitted content requested (Content-type), such as text/html2.4--produces: Specifies the type of content returned2.5--params: Specifies that some parameter values must be included in the request for this method to be processed2.6--headers: Specifies that certain header values must be included in the request for the method to process requests
[email protected]
This annotation is used to convert the controller's method return object through Htpmessageconverter to a specified time to write to the body data of the response object,usage Scenario: When the returned data is not an HTML tag, other data formats such as Json,xml are used.
[email protected]
used to map the template variables in the request URL to the parameters of the function processing method, and remove the variables in the URL template as parameters
[email protected]
used to map the request parameter area data to the parameters of a functional processing method.
[email protected]
parameter: Value parameter nameRequired: Whether you must
DefaultValue: Default value
[email protected] and @autowired
They are all used as bean injections, @Resource not spring annotations his gem Javax.annotation.Resource needs a guide package, but spring supports the injection of the annotation
common denominator: Both can unload fields and setter methods, and if both are written on the field there is no need to write setter methods
different points:
The @Autowired is that spring provides annotations that require a leader, by Bytype injection, by default he requires that the dependent object must exist, and if the null value is allowed, set his required property to false.
@Resource is automatically injected by ByName by default, he has two important properties, name and type,spring resolve the Name property of the annotation to the bean's name, the type attribute resolves to the bean, and if you want to use the Name property, Automatic injection of byname is required, and using the type attribute requires a Bytype auto-injection policy. If any attribute is not established, she will use the ByName auto-injection strategy through reflection.

Understanding of the SPRINGMVC Framework (RPM)

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.