Spring Official document Translation--15.1 Introduction to Spring WEB MVC framework

Source: Internet
Author: User
Tags tld

Part V. The Web

This section of the documentation describes the spring framework's support for the presentation layer (especially the Web-based presentation layer)

Spring has its own web framework--spring Web MVC, which is described in the first two chapters. The rest of the chapters are used to introduce the integration of spring and other web technologies, such as struts and JSF (only two are mentioned here).

This section ends with an introduction to the Spring MVC portlet framework.

15th Chapter--web MVC Framework (WEB MVC framework)

The 16th Chapter-View Technology (technologie)

17th chapter-Integration with other web frameworks (integrating Withother Web frameworks)

18th Chapter--portlet MVC Framework (Portlet MVC framework)

15.WebMVC Frame
15.1 Introduction to the Spring WEB MVC framework

The Spring WEB MVC Framework is designed around a dispatcher (Dispatcherservlet) to distribute requests (request) to the corresponding processor (handler). This also relies on configurable processor mappings (handlermappings), visual analysis (view resolution), localization and topic resolution (local andtheme resolution), and upload file support.

The default handler relies on @controller and @requestmapping annotations to provide a flexible approach. In Spring3.0, the @Controller mechanism also allows you to create restful websites and apps with @pathvariable annotations and other features.

"Open for Extension"

In spring Web MVC and Spring, a key design guideline is the "open extensions, close changes" principle.

Some methods in the Spring WEB MVC core class are marked as final. As a developer, you can't rewrite these methods to meet your needs. This is not an arbitrary and must be defined criteria.

For an explanation of this principle, you can look at the expert Spring Web MVC and Web Flow written by Seth Ladd, especially the "a look Atdesign" chapter, on page 117 of the first edition. Or you can watch it.

1. Bob Martin, the open-closed Principle (PDF)

You cannot add advice to the final method when using spring MVC. For example, you cannot add advice for abstractcontroller.setsynchronizeonsession (). You can refer to the section "UNDERSTANDINGAOP proxies" For more information about AOP proxies and why you cannot add advice to the final method.

In spring Web MVC, you can use any object to act as a Command object or Form object. So you don't need to implement a framework-related interface or base class. Spring's data binding is highly flexible. For example, it considers a type mismatch as a checksum error (validationerrors), which can be handled by the application rather than a direct system error. So you don't have to copy the properties of the business object as strings to handle invalid commits, or to convert those string attributes. It's usually better to bind parameters directly to your business object.

Spring's view resolution is also extremely flexible. Controller implementations can even write data directly to the response stream. Typically a Modelandview object contains a view name and a model map. The model map contains Beannames and its corresponding objects, such as command objects or form objects.

View name resolution can be configured through the bean names,properties file or your own Viewresolver implementation.

The model is based on the map interface, which allows for full abstraction of the view technology. You can integrate jsp,velocity or other page rendering techniques directly. Because model map can easily be converted to the appropriate format, such as a JSP requestattributes or velocity template model.

features of Spring MVC


Spring Web Process

The goal of Spring Web flow (SWF) is to be the best solution for Web Application page Flow management.

SWF can be integrated into existing frameworks, such as spring mvc,struts and JSF, both in servlet and protlet environments. If you have a business process that benefits from session mode rather than a simple request pattern, SWF can be a solution.

SWF allows you to capture a logical page stream as a "self-contained" module. Can be reused in different scenarios, which facilitates the creation of a modular Web application that can guide users through constrained navigation to drive business processes.

If you need more information about SWF, go to spring Web Flow website to see it.

Spring's web modules include many features that are only supported by the Web:

clear separation of roles . Each role--the controller, the Validator (validator), the Command object (commandobject), the Form objects (Form object), the Model object (Modelobject), Distributors (Dispatcherservlet), processor mappings (handler mapping), page parsers (viewresolver), and so on-can all be implemented by specific objects.

powerful and concise configuration . Powerfuland straightforward configuration of both framework and application classes Asjavabeans. This configuration capability includes easy referencing acrosscontexts, such as from web controllers to business objects a nd validators. This translation is not good ~ ~

adaptability, non-invasive and flexible . Based on the given scenario, use some parameter annotations (such as @requestparam, @RequestHeader, @PathVariable, etc.) to define the controller method you need.

reuse business code, without duplication . Instead of having them inherit a specific framework base class, use existing business objects directly to act as command objects or form objects.

Customizable bindings and checksums . Types do not match as an application-level checksum error, which enables the binding of localized dates, numbers, and other values, not just string-based form objects. The latter also requires a manual type conversion to be converted into a business object.

Customizable processor mapping and view resolution. Processor Mapping and view resolution strategies from simple URL-based configuration to complex, specific-purpose parsing strategies. Spring is more flexible than web MVC frameworks that host technology.

Flexible model Conversions . Models can be converted to one Key/value map to support integration with any attempt to technology

definable localization and topic resolution . Supports JSPs with or without the Spring tag library, supports JSTL, supports velocity and does not require additional bridging.

The Spring Tag Library is a simple yet powerful JSP tag library that provides support for data binding and themes . In the area of tag code, the custom label allows for maximum flexibility. To find out more about the tag library descriptor, you can see the Appendix F,spring.tld

in Spring2.0, there is a JSP form tag library that makes it easier to make a form in a JSP . To find out more about the tag library descriptor, you can see the Appendix G,spring-form.tld

the beans life cycle range is the current HTTP request or HttpSession. This is the feature of the Webapplicationcontext container, not the Spring MVC feature. Just SPRINGMVC used the webapplicationcontext. The scope of these beans is described in the chapter "Request,session,andglobal Session Scopes".

The pluggable nature of other MVC implementations

The implementation of Spring MVC may not be the most appropriate for some projects. Many teams are looking to leverage existing investments to improve technology and tools. For example, the Struts framework contains a large amount of knowledge and experience in use. If you can tolerate the flaws of the struts architecture, it can be another option for your Web tier. The same is true for other MVC frameworks.

If you don't want to use spring's web MVC, but you want to use the other solutions provided by spring, you can integrate the Web MVC framework of your choice into spring, which can be very easy. You only need to start a spring root application context through Contextloaderlistener, and then access it (or spring's own Help method) from the control of the integrated struts or webwork with the ServletContext property. No "Plug-ins" is involved, so no dedicated integration is necessary. From the Web layer perspective, you are simply using spring as a library and the root application context object as a pointcut.

Even if you don't use spring's Web MVC, your registered beans and spring services will be at your fingertips. Spring does not compete with struts or webwork, it simply provides features not provided by the simple Web MVC framework, such as bean configuration, data access, and transactional processing. So you can use the spring middle tier and/or data access layer to enrich your app, even if you just want to combine JDBC or hibernate to use abstract transaction management.

Spring Official document Translation--15.1 Introduction to Spring WEB MVC framework

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.