基于MVC模式的电子商务网站(BC)的分析与设计.doc
文本预览下载声明
Based on MVC Pattern Analysis and design of e-commerce (B2C)sites
Before we start our journey into the internals of Spring MVC, we first need to understand the different layers of a web application. And we’ll begin that discussion with a brief introduction of the MVC pattern in general, including what it is and why should we use it. After reviewing the MVC Pattern, we will go through the different layers in a web application and see what role each layer plays in the application.
The Model View Controller pattern (MVC pattern) was first described by Trygve Reenskaug when he was working on Smalltalk at Xerox. At that time, the pattern was aimed at desktop applications. This pattern divides the presentation layer into different kinds of components. Each component has its own responsibilities. The view uses the model to render itself. Based on a user action, the view triggers the controller, which in turn updates the model. The model then notifies the view to (re)render itself.
The MVC pattern is all about separation of concerns. As we mentioned previously, each component has its own role (see Table 3-1).
Separation of concerns is important in the presentation layer because it helps us keep the different components clean. This way, we don’t burden the actual view with business logic, navigation logic, and model data. Following this approach keeps everything nicely separated, which makes it easier to maintain and test our application.
What Is MVC:
MVC is a design pattern that breaks an application into three parts: the data (Model),
the presentation layer (View), and the user interaction layer (Controller). In other
words, the event flow goes like this:
1. The user interacts with the application.
2. The controller’s event handlers trigger.
3. The controller requests data from the model, giving it to the view.
4. The view presents the data to the user.
Or, to give a real example, Figure 1-1 shows how sending a new chat message would
work with Holla.
Figure 1-1. Sending
显示全部