JavaEE (5): MVC pattern

1. Introduction

    MVC is an architectural design pattern and a design philosophy. It is to achieve the purpose of layered design, so as to decouple the code and facilitate maintenance and code reuse. MVC is the abbreviation of 3 words, the full name: Model-View-Controller (Model-View-Controller).


2. Structure

1、View

The view layer is the UI interface, which is used to interact with the user. Generally, all JSP, Html and other pages are the View layer.

2、Controller

The control layer, the function of the Controller layer is to associate the Model and View layers. For example, the View mainly displays data, but the data needs to be accessed by the Model. In this case, the View will tell the Controller first, and then the Controller will tell the Model. After the Model requests the data, it will tell the View. This allows the View to display the data.

3、Model

The model layer, which can be simply understood as the data layer, is used to provide data. In the project, (simple understanding) generally use the code of data access and operation, such as object-relational mapping, as the Model layer, that is, the code that operates on the database columns as the Model layer. For example, in the code, we will write DAO and DTO type code, then this DAO and DTO can be understood as the code belonging to the Model layer.

3. Expansion

In fact, in addition to the MVC architecture, there are MVP, MVVM and so on. In actual projects, a better implementation of MVC should have an additional service layer to handle business logic. as follows:

The extra Service layer is mainly used to deal with complex business logic, so that the structure level is more distinct and brief.

The main MVC frameworks are: SpringMVC and Struts

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324800973&siteId=291194637