A basic understanding of the MVC pattern

The following reference to the "proficient Java Web Integrated Development (JSP + Ajax + Struts + Hibernate)" and the contents inside "MVC Web development framework based on write their own Struts-- building."


Outline


MVC model, i.e. the model - View - Controller (MVC, Model-View-Control) is a structural model of the organization of the interface.

Model (Model) , represents the business logic of the application, the application contains the core functionality that represents enterprise data and business rules. Model encapsulates the state of the application. In the MVC model, task model to deal with a lot in order to make a model to provide data to give multiple views, then let the model has nothing to do with the data format.

View (View) , view of the application layer, providing a model representation. It is the interface of the application, the user is able to see and interact with the interface. In the view layer, there is no real processing occurs. View layer is only one way to show data provided by the model, therefore, view the method can only read access model, and write methods can not access model. A view of the controller has no knowledge, when changing the model, the view should be notified.

Controller (Control) , which provides an application control process, the controller to react to user input, and it creates the model set. The controller is equivalent to a transfer station, and it itself does not output any data processing. The controller action is to accept requests from the client, and select corresponding service logic execution, and then decide which view to display the processed data returned by the model, so that the response is sent back to the client results.



MVC Pattern


Requests submitted by the user causes the controller to change or view the model or change the model or view simultaneously. Once the controller changes the model data, it notifies all dependent view are automatically updated; the other hand, as long as the controller selects a corresponding view, which will retrieve from the model to be refreshed.



MVC design pattern


MVC pattern design idea is this: the original developer for the input of a system, output, process flow programmatically change is in accordance with the model layer, view layer, control layer decomposition, so that the whole system accountability, clear interfaces to speed up Development Process.

1, the model layer

Business process model is to develop state of the processing and business rules. There are generally two types of model: model business logic and data model. Model view accepts the request, and returns the final result of the processing. Business process process is closed on the two additional layers (View and Control) is. In the MVC model, we want to apply the model according to certain rules extracted, the extraction level is the key, which is to determine whether the developer excellent basis. Data model mainly refers to the entity object data is stored, that is persistent. Data model to a model between the view and interact with support. Implement the "what to do (business process)" and "how to do (business entity)" separation, so that you can reuse business logic. MVC design business model is the most important part of the core.

2, the view layer

View is the customer interface and system interaction, as the view is concerned, it is just a way to show the data provided by the model. It can be an HTML page or in other ways, and so on.

In the MVC design pattern, the view is limited to handling data acquisition and processing on the view, and the user's request, the process does not include a view of the business process, and change processing to the state of the business process model layer processing.

3, the control layer

Control layer as a relay station, it accepts a user request, according to a user request and matching with model and view together to complete the user's request. Control layer without any data processing, it is a dispenser, and choose what kind of model view, to complete what the user request . To be able to control and coordinate the processing of each user across multiple requests, the control mechanism should be managed in a centralized manner. User submits a form, or click on a link control layer after receiving the request, which itself does not deal with business information, but according to the user's request type, the transfer of user information to the corresponding model, the model told what to do, such as model after processing, the data is then selected to meet the requirements of the process model view to the user. Thus, a model may correspond to a plurality of views, the view may correspond to a plurality of models. In this case, we may make some simple data conversion and other operations at the control level.

The relationship between the division of labor model, view and controller are as follows:

Diagram as follows:

Module Name

Division of work

cooperation

Model M

1, system application features abstract

2, the state of the packaging system

3, there is provided a method and system functions using path

4, storage and management of data consistency

5, notification related component when the data changes

1, when the notification view of the system state changes

2, in response to the status query view

3, to provide a way to operate the controller

V view

1, abstract data representation

2, data representation for the user

3, maintenance and model data consistency

1, the display data model

2, the received data update notification updates the model view

3, accepts user input data to the controller

Control C

1, user and system time abstract semantic mapping

2, the system is mapped to user input events

3, select the appropriate display based on user input data and a context where

1, receiving a user request

2, call a model of user requests

3, the results will give a view for display

 

MVC summary of the process is as follows:

First, the controller receives the user's request, and to decide which models should be called to process, and then model the business logic used to handle the user's request and returns the data, the controller finally formatted data corresponding to the model view and shows the view through to the layer user.



MVC-based Web framework


In general, to achieve a schematic diagram of MVC-based Web framework as follows:


Reproduced in: https: //my.oschina.net/guanzhenxing/blog/232856

Guess you like

Origin blog.csdn.net/weixin_34008784/article/details/92625367