(Spring document translation) Part V, the Web 17.1 Spring Web MVC Framework Introduction

Source: Internet
Author: User

This section of the guide document covers the support of the spring framework for the presentation layer (especially the Web-based presentation layer) and the WebSocket Messaging style Web application.

The spring framework has its own web framework, Spring Web MVC, which is included in the previous chapters. The following chapters are about the Spring framework's integration support for other web technologies, such as JSF.

Then there is the Spring Framework's MVC Porlet framework.

The Spring MVC framework revolves around the Dispatcherservlet design, Dispatcherservlet forwarding requests to handler with configurable handler mappings, view parsing, localization, and theme scenarios

and support file upload.

The default handler, based on @controller and @requestmapping annotations, provides a very resilient handling method, in Spring3.0 's introduction, @ The controller mechanism allows you to create restful Web sites and applications through @pathvaliable annotations and other features.

"Open for expansion ..." is a key design principle for SPRINGWEBMVC, in spring, the principle of "open to expansion, closed to modification".

Some of the core class methods in SPRINGWEBMVC are marked as final. As a developer, you cannot override these methods to provide your own behavior. This is not an absolute requirement, but the principle must be clarified in the mind.

For an explanation of this principle, you can refer to the Expert Spring Web MVC and Web flow of Seth Ladd, especially the "A Loot at Desing" section, on page 117 of the first edition.

When you use spring MVC, you cannot provide enhancements to the final method. For example, you cannot enhance the Abstractcontroller.setsynchronizeonsession () method. Refer to Section9.6.1 For more information on the AOP agent and why you cannot enhance the final method.

In spring Web MVC, you can make any object as a command or object that returns a form, and you don't need to implement an interface or base class for a particular framework. Spring's data binding is very resilient. For example, it treats a type-matching error as a validation error, so that it can be applied to a discovery rather than a system error. This way you don't have to copy the properties of your business object, like a simple, no-type string from a Form object, to handle an illegal commit, or it would be appropriate to convert it to a string. Spring can often be very good at binding directly to your business object.

Spring's view solution is extremely resilient. The controller is usually responsible for preparing a map model with data and selecting a view name, but it can also write directly to the response stream to end the request. The name of the view is also highly configurable and can be implemented through the file's extension or accept header,content type negotiation, through the bean name, a properties file, or even a traditional viewresolver. Model (m in MVC) is a map excuse that allows a complete abstraction of the view technique. You can directly use template-based rendering techniques, such as jsp,velocity,freemaker integration, or direct production of xml,json,atom, as well as other very hot content forms.

The map model can be easily converted to the appropriate format, like the request property of the JSP, the model of the velocity template.


English Original:

Introduction to Spring Web MVC framework

The Spring Web Model-view-controller (MVC) framework is designed around aDispatcherServletThat dispatches requests to handlers, with configurable handler mappings, view resolution, locale, time zone and theme res Olution as well as support for uploading files. The default handler is based on the@Controllerand@RequestMappingAnnotations, offering a wide range of flexible handling methods. With the introduction of Spring 3.0, the@ControllerMechanism also allows you to create RESTful Web sites and applications, through the@PathVariableAnnotation and other features.

"Open for extension ..." A key design principle in spring Web MVC and in spring in general are the "Open for extension, closed for modification< /c1> "principle.

Some methods in the core classes of Spring Web MVC is marked final . As a developer cannot override these methods to supply your own behavior. This have not been do arbitrarily, but the specifically with this principle on mind.

For a explanation of this principle, refer to Expert Spring Web MVC and Web Flowby Seth Ladd and others; specifically see the section ' A look at Design, ' on page 117 of the first edition. Alternatively, see

    • Bob Martin, the open-closed Principle (PDF)

you cannot add advice to final methods when you use Spring MVC. For example, you cannot add advice to The abstractcontroller.setsynchronizeonsession () method. Refer to section 9.6.1, "Understanding AOP Proxies"  for more information on AOP proxies and what you cannot Add advice to final methods.

In Spring Web MVC You can use any object as a command or Form-backing object; You don't need to implement a framework-specific interface or base class. Spring's data binding is highly flexible:for example, it treats type mismatches as validation errors so can be evaluate D by the application, not as system errors. Thus need not duplicate your Business objects ' properties as simple, untyped strings in your form objects simply to ha Ndle invalid submissions, or to convert the Strings properly. Instead, it's often preferable to bind directly to your business objects.

Spring ' s view resolution is extremely flexible. AControlleris typically responsible for preparing a modelMapWith data and selecting a view name is it can also write directly to the response stream and complete the request. View name resolution is highly configurable through file extension or Accept header content type negotiation, through bean Names, a properties file, or even a customViewResolverimplementation. The model (the M in MVC) is aMapinterface, which allows for the complete abstraction of the view technology. You can integrate directly with template based rendering technologies such as JSP, Velocity and Freemarker, or directly GE Nerate XML, JSON, Atom, and many other types of content. The modelMapis simply transformed to an appropriate format, such as JSP request attributes, a Velocity template model.


(Spring document translation) Part V, the Web 17.1 Spring Web MVC Framework Introduction

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.