The role of Java Dao layer
The role of Java Dao layer
The Dao layer is called the data access layer. It is a relatively low-level and basic operation. It can be specific to For the addition, deletion, modification and query of a certain table or an entity, the function of the Dao layer is to encapsulate the access to the database, so that it does not involve business and achieves decoupling.
Calling process
JSP page——Action——Service——DAO——(Hibernate framework)——Database
Extended information
MVC pattern
MVC pattern is a software framework pattern that is widely used in JavaEE The project is under development. The MVC pattern is easy to understand, but it is also very important. We cannot do without it in future web application development.
Before, we have studied Servlet and JSP. It seems that they can complete many functions independently, but each has its own characteristics. MVC provides a way to maximize strengths and avoid weaknesses, and combine both swords.
1. What is MVC
MVC is Model, View, and Controller.
Model
The model is the part used to process data logic.
The so-called data logic refers to the mapping of data and the addition, deletion, modification and query of data. Beans, DAO (data access object, data access object), etc. all belong to the model part.
View (View)
The view is responsible for the display of data and other information, which is the page that the user sees.
html, jsp and other pages can be used as views.
Controller (controller)
The controller is the bridge between the model and the view, controlling the interaction between data and users.
The controller is usually responsible for reading data from the view, processing user input, and sending data to the model. It can also read data from the model and then send it to the view for display by the view.
The Servlet learned earlier can be used as a controller.
2. Why use MVC
I believe that the MVC model has the following three major benefits.
Looks comfortable
When we studied Servlet and JSP earlier, we found that these two things are a mixture of functions and displays, and their readability is very poor. With MVC, Servlet has It is logic code, and JSP is display code, which is clear at a glance.
It’s easy to write
The MVC model is conducive to the division of labor and cooperation among personnel. Different developers can exert their respective expertise and develop different parts at the same time.
Easy to change
MVC can focus on one aspect at a time, making application testing and iteration more convenient. Therefore, most complex applications will choose to use the MVC pattern.
The above benefits, in a jargon, are called "high cohesion and low coupling".
3. Design Pattern and Framework Pattern
When collecting information, I found that MVC is called a "design pattern" in many places. At first, I thought there was nothing wrong with it, literally. It makes sense, but if you think about it carefully, the word "design pattern" is a term that refers to things like factory pattern and singleton pattern, and it cannot be used indiscriminately. MVC should be called the "framework pattern".
So what is the difference between the two?
Design patterns are for "code", just like the stacking of bricks and tiles when building a house, they are the cornerstone of software development.
Frame pattern is for "framework" and is a reusable solution for certain application scenarios, such as the layout of buildings with different functions such as hospitals and shopping malls. It is a more macro concept than design pattern.
In future articles, I will learn from you the current mainstream frameworks.
4.MVC practice
In JavaEE, the most classic MVC pattern is
Bean(Model) JSP(View) Servlet(Controller)
If there is a requirement: to edit the information on the web page and synchronize it with the database
In terms of implementation, it can be divided into the following steps:
Use Bean to map the data table and write a DAO
Use the Servlet responsible for querying to call DAO to query the content that needs to be edited and send it to the jsp page for editing
Submit the modified value of the editing page to the Servlet responsible for updating and call DAO Update the database
Use another Servlet responsible for querying and send the updated content queried to the JSP responsible for display
Recommended tutorial: "Java Tutorial"
The above is the detailed content of The role of Java Dao layer. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.
