SPRINGMVC Study Notes

Source: Internet
Author: User

1, strictly realize the framework of MVC design idea, strictly stratification, reduce coupling;

2. Components (red required)
2.1 Dispatcherservlet Front Controller
2.2 Controller Business Controllers
2.3 Handler Mapping Request match: Request forwarded to specific controller
2.4 Viewresolver: Control controller return response to jump to a different view of the components presented
View: For different view technologies (JSP, PDF, Excel ... ) Take a different processing component
Each of the Viewresolver must specify a view
2.5 Interceptors: Interceptor, face-cutting technology
2.6 Localresolver: Localization processing component
2.7 Validate: Verifying components

3, Controller implementation method (original 3 before the configuration method has been eliminated recommended use of annotations)
3.1 Implementing controller interfaces or inheriting Abstractcontroller abstract classes (incoming request and response objects)
3.2 Modelandview
3.2 Parameterizableviewcontroller, Urlfilenameviewcontroller (URL name and view name match) for direct jump page
3.3 controllers that automatically encapsulate form parameters (Common): Commandcontroller overrides the handle method, which injects the form parameter through the property editor into the entity class, and some types, such as dates, need to provide an overridden property editor to correctly convert ; Formcontroller rewrite onsubmit method;
Use annotations are not recommended after Spring3;
3.4 Multiactioncontroller Red parameter required
Method: Public (modelandview| map| string|void) actionname (httpservletrequest request,httpservletresponse response,httpsession session,Object anyobj);

4, Handlermapping
4.1 Default Controllerclassnamehandlermapping
4.2 Common Simpleurlhandlermapping
4.3 beannameurlhandlermapping
4.4 Recommended use of defaultannotationhandlermapping based on annotations controller

5. Annotation-based SPRINGMVC configuration
5.1 Using annotations then spring-mvc.xml need to add the context and MVC two namespaces
5.2 Note Configure the scan first, then add the configuration jump processing Internalresourceviewresolver, and then add the annotations;
5.3 RESTful style request: Define the URL request template first, and then use the @pathvariable to specify the processing method to receive the parameters passed in the URL of the variable;
For special format parameters, the property editor must be converted; Data binding: You can use the entity object directly as the entry parameter, there is the possibility of the data format conversion exception;
5.4 Requests for different request methods, such as Get post, can be handled via @method
Other Notes: @CookieValue @RequestHeader
5.5 If the return value is void and the method does not use Pringwriter, then the view that is configured with the same name in requestmapping is automatically matched

6. Forwarding and redirection
return "forward:index.jsp"; Forward
return "FORWARD:USER.DO?METHOD=REG5"; Forward
return "REDIRECT:USER.DO?METHOD=REG5"; redirect
return "redirect:http://www.baidu.com"; redirect


7, Xmlviewresovler:
View:jstlview, Excelview, and custom view (jsperreport| Pdf| Excel)
View Chain

8, the Interceptor chain (generally all MVC will implement interceptors):
Implement the Handlerinterceptor interface, overriding three methods: Prehandler:controller before execution, posthandler:controller after view generation,
Aftercompletion Releasing Resources

9. View Internationalization:
9.1 page introduced spring tag: <% taglib uri= "http://www.springframework.org/tags" prefix= "Spring"%>, using Tags: <spring: Message code= The key value of the "Xxxkey"/> Code counterpart resource file (*.properties);
9.2 Creating and writing a resource file: mess.properties,mess_zh_cn.properties,mess_en_us.properties
9.3 Configuration support: <bean:id= "Messagesource" class= "Org.springframework.context.support.ResourceBunldleMessageSource" >
<property name= "basename" value= "mess"/>
</bean>
Note that ID can only call this messagesource.


10. Injection verification: JSR303 Validate Bean
@Valid: Validation: Provides validation interfaces for entity object JDK general other frameworks like hibernate provide validation implementations

Add: The controller in SPRINGMVC is a singleton how to become a multi-case? Add annotations to the controller @scope ("prototype")

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.