gogoWebsite

MVC and DAO modes

Updated to 21 days ago

Excerpted from:/s/blog_df1ba2640102wf55.html

MVC, namely Model-View-Controller (model-view-controller) is a software design model. MVC first appeared in the Smalltalk language and was later widely used in Java. It was recommended by Sun as the design model of the Java EE platform. Later, Sun proposed two Java Web development models based on the MVC model: JSP Model1 and JSP Model2.

DAO mode (Data Access Object, DAO) provides data abstraction layer interfaces to the business layer. The DAO model is an operation belonging to the Java EE data layer. Using the DAO model can simplify a large amount of code writing and increase the portability of programs. The DAO model achieves the following goals: 1. Separation of data storage logic 2. Separation of data access underlying implementation 3. Data abstraction

In this mode, Servlets are used to process requested transactions and act as the controller (Controller, i.e. "C"). The Servlet is responsible for responding to customer requests for business logic and deciding which JSP page to send to the customer based on the user's request behavior. The JSP page is in the presentation layer, that is, the role of the view (View is "V". JavaBean is responsible for data processing, that is, the role of model (Model, "M"), Servlet+JSP+JavaBean (MVC) mode is suitable for the development of complex web applications. In this mode, servlets are responsible for processing user requests, jsp is responsible for data display, and javabean is responsible for encapsulating data. The hierarchy between the Servlet+JSP and JavaBean mode programs is clear, and web development recommends using this mode. The MVC architecture Model-View-Controller architecture model was invented in the laboratories of Smalltalk-80 GUI, a classic object-oriented programming language, in the mid-1980s. According to the MVC model, a software should separate business logic (Model) and display (View). There are many benefits to separation, and the most important ones are two: 1. The same business logic layer (Model) may correspond to multiple display layers (Views). If the business logic layer and the display layer are put together, adding another display layer will greatly increase the complexity of the component. An example of business logic facing two display layers is: the business logic layer of a bank account corresponds to two display layers ATM and Internet. 2. Generally speaking, the business logic layer is not required to be modified every time the display layer is modified. ​

Don’t put all the eggs in one basket, isn’t the code? If you stack access to the database, operating the database and other business logic codes in one Servlet at the same time, the Servlet will undoubtedly be very bloated, and the maintenance workload is very large, and the risk of the program will also increase. Then the DAO model solves this problem. The DAO model places access, operations and calls to the database in different Java classes, reducing the coupling between business logic and the underlying database and making it easier to maintain. It can be said that the DAO model has become a design model that is widely used in Java Web development. ​