The basic concept of SpringMVC

About three-tier architecture and MVC 1.1

1.1.1 three-tier architecture

Our development architecture are generally based on two forms, one is C / S structure, that is, client / server, and the other is B / S architecture, it
is a browser server. In JavaEE development, almost all developing B / S architecture. Then the B / S architecture, the system's standard three-tier architecture
include: presentation layer, business layer, persistence layer. In our three-tier architecture used in the actual development of very large, three-tier architecture, each layer of their duties, then we talk about what each layer is responsible for:
the presentation layer:
that is, we often say that the web Floor. It is responsible for receiving client requests, the response result to the client, the client usually using http protocol request
web tier, web http request needs to receive, complete http response.
Presentation layer comprising a display and control layers: the control layer is responsible for receiving the request, the results show demonstrate responsible layer.
Presentation layer dependent on the service layer, the received client request layer will generally call the business service processing, and the processing result in response to the client.
Design the presentation layer generally use MVC model. (MVC design model is the presentation layer, and other layers does not matter)
business layer:
that is, we often say that the service layer. It is responsible for business logic processing, and the needs of our development projects are closely related. layer web service layer dependent, but not dependent business layer web layer. Business layer in the business process may depend on the persistence layer, if you want to ensure data persistence required transactional consistency. (That is, we say, the transaction should be placed in the service layer to control)
the persistence layer:
that is, we often say dao layer. Responsible for data persistence, including data layer, namely the database and the data access layer, the database is the data persistence carriers, data access layer is the interface service layer and persistence layer interaction, business layer needs through the data access layer will persist data to database. Popular speaking, persistence layer is to interact with the database, the database tables once excision investigation.

1.1.2 MVC model

MVC full name is the Model View Controller, is a model (model) - view (view) - abbreviation controller (controller), is a model for design to create a Web application presentation layer. MVC in each part of their duties:
Model (model): Usually refers to our data model. Encapsulating the data for the action generally.
View (View): Usually refers to our jsp or html. The role of the general is to display the data. Usually view is created based on the model data.

The Controller (Controller): user interaction is part of the application process. Effect is generally handler logic. It is relative to the first two is not well understood, here for example:
For example: we want to save information about a user, the user includes the name, gender, age, etc. information. This time forms the input requirements of age must be an integer between 1 and 100. Name and sex can not be empty. And padding into the model. At this time, in addition to checking js, the server should check the accuracy of the data, then check the controller is done. When the check fails, the controller is responsible for the error page is displayed to the user.
If the check is successful, the controller is also responsible for filling data into the model, and call the business layer to achieve a complete business needs.

1.2 SpringMVC Overview

What 1.2.1 SpringMVC that?

SpringMVC is a type of drive based on the request of the realization of Java MVC design model of a lightweight Web framework, belong Spring FrameWork successor, it has been integrated in the Spring Web Flow inside. Spring provides a framework for building Web applications full-featured MVC module. Spring can be inserted using the MVC architecture, so that when using Spring WEB development, can choose to use the Spring Framework Spring MVC, or MVC other integrated development framework, such as Struts1 (now generally do not), the Struts2 like.
SpringMVC has become one of the most mainstream of the current MVC framework, and as Spring3.0 release, beyond Struts2, as
is the best MVC framework.
It is through a set of annotations to make a simple Java classes to become controller processes the request, without having to implement any interface. It also supports
RESTful programming style requests.

1.2.2 SpringMVC position in the three-tier architecture

1.2.3 SpringMVC advantage

1, a clear separation of roles:
front-end controller (the DispatcherServlet)
request to the handler mapping (the HandlerMapping)
Processor Adapter (HandlerAdapter is)
view resolver (ViewResolver)
processor or a page controller (Controller)
validator (the Validator)
command object ( command request parameters bound to an object is called command object)
form object (form Object to the object and submit the form to display the form object is called).
2, clear division of labor, and extension points is quite flexible and can be easily extended, although almost do not need.
3, because the command object is a POJO, the framework do not need to inherit a particular API, you can use the command object directly as a business object.
4, and other frameworks Spring seamless integration, other Web frameworks do not have.
5, can be adapted by HandlerAdapter may support any class as the processor.
6, customization, HandlerMapping, ViewResolver, etc. can be very easy to customize.
7, powerful data validation, formatting, binding mechanism.
8, using the Spring Mock objects can provide a very simple means of testing for Web layer.
9, localization, supporting analytical themes, making it easier to switch internationalization and themes.
10, a powerful JSP tag library to make it easier to write JSP.
.................. For example, there is support for RESTful style, simple file upload, agreed greater than the configured contract programming support, with zero-based annotation
Home support and so on.

Guess you like

Origin www.cnblogs.com/heliusKing/p/11318199.html