Simple understanding of MVC three-tier architecture

Article Directory

MVC three-tier architecture:

1.Understand MVC:

Model view Controller model, view, controller

2.Previous architecture (only two layers):

Insert picture description here


In fact, JSP is essentially a servlet, but for better maintenance, there are respective areas of focus.

The user layer directly accesses the control layer to directly operate the database

servlet--CRUD-->数据库

Disadvantages: The program is very bloated, which is not conducive to maintenance

在以前的架构中servlet的代码需要:处理请求、响应、视图跳转、处理JDBC、处理业务代码、处理逻辑代码

Architectural thinking: There is nothing that can't be solved by adding another layer!
Classic example:

程序猿调用
↑
JDBC (实现该接口)
↑
Mysql Oracle SqlServer ....(不同厂商)

3 MVC three-tier architecture:

Insert picture description here


Model

  1. Business processing: business logic (Service)
  2. Data persistence layer: CRUD (Dao-data persistence object)
Insert picture description here

View

  1. Display data
  2. Provide a link to initiate a Servlet request (a, form, img...)
Insert picture description here

)

Controller (Servlet)

  1. Receive user requests: (req: request parameters, session information...)
  2. Hand it over to the business layer to process the corresponding code
  3. Jump
Insert picture description here


login of control view —> Receive user login request —> Process user request (get user login parameters, username, password) ----> hand it over to the business layer to handle the login business (judge whether the user name and password are correct: Transaction) —> Dao layer queries whether the user name and password are correct —> Query in the database The
final result is true (back to the business layer -----> user request -----> jump page) failed the same reason