On MVC and three-tier architecture

introduction:

You will find that when using the Eclipse development tool to write Java Web project, a medium-sized or large-scale projects with the increase in code, you will find: The code can be written in the src directory, you can also write in the WebContent directory. Src can be built under a lot of packages, a lot can be built under the WebContent folder.

So the question arises: in the end to write a new class which file in which directory to the folder?

At this solution is: the need to regulate a pattern, which in the end the class where to write.

                                                                         

 MVC design pattern:

View View

Responsible for page display; interaction with the user. It contains a variety of forms. Techniques are used to achieve view html / css / jsp / js other front-end technology.

User interaction: the user click on a page; page in a variety of forms to fill in and so on ........

Model Model

Model responsible for implementing each function (such as login, add, delete function). JavaBean model implemented.

JavaBeans :

① Java is in a special class (in other words: JavaBean is a Java class).

A Java class that meets the following requirements, can be called a JavaBean

  a. public class modified, that provides a public constructor with no arguments

  b. All properties are private

  c. Provide getter and setter methods

 

② from the use of perspective, JavaBean divided into two categories:

 a business logic package the JavaBean. (EG: LoginDao.java encapsulates the login logic)

  b JavaBean encapsulated data. (entity classes: eg:. Student.java Vedio.java often corresponds to a table in the database, i.e. the database table has a Student, there projects a Student.java class)

   

 

③JavaBean is a reusable component to achieve some common functions by writing a component, "write once, execute anywhere, anywhere reuse."

Controller Controller

控制器负责将视图与模型一一对应起来。相当于一个模型分发器。所谓分发就是:①接收请求,并将该请求跳转(转发,重定向)到模型进行处理。②模型处理完毕后,再通过控制器,返回给视图中的请求处。建议使用Servlet实现控制器。

 

 三层架构:

首先来说,三层架构与MVC的目标一致:都是为了解耦和、提高代码复用。MVC是一种设计模式,而三层架构是一种软件架构。

三层架构分为:表现层(UI)、业务逻辑层(BLL)、数据访问层(DAL)再加上实体类库(Model)

1.实体类库(Model),在Java中,往往将其称为Entity实体类。数据库中用于存放数据,而我们通常选择会用一个专门的类来抽象出数据表的结构,类的属性就一对一的对应这表的属性。

·一般来说,Model实体类库层需要被DAL层,BIL层和UI层引用。

2.数据访问层(DAL),主要是存放对数据类的访问,即对数据库的添加、删除、修改、更新等基本操作

 ·DAL就是根据业务需求,构造SQL语句,构造参数,调用帮助类,获取结果,DAL层被BIL层调用

3.业务逻辑层(BLL)

·BLL层好比是桥梁,将UI表示层与DAL数据访问层之间联系起来。所要负责的,就是处理涉及业务逻辑相关的问题,比如在调用访问数据库之前,先处理数据、判断数据。

BLL层只被UIL层引用

  1. 用户表现层(UIL),就是用户看到的主界面。

                        各层引用关系如下图所示:

 

 

MVC与三层架构的对应关系,图示如下:

 

Guess you like

Origin blog.csdn.net/weixin_42153410/article/details/90753696