The article directories

A, JavaBean

A JavaBean is a common Java class. To standardize development, a JavaBean is required to have the following specifications:

① There is a common, parameterless constructor;

(2) Properties of a class are private, and public setter and getter methods must be provided for assigning and obtaining property values externally;

In short: JavaBean = property private + public setter/getter methods + empty parameter constructor

Relational Mapping object Relational Mapping

① A data table corresponds to a JavaBean

② A record in a table corresponds to an object in a JavaBean

③ A field in the table corresponds to an attribute of the JavaBean

(When designing entity classes and database tables, try to achieve ORM, that is, attribute names correspond to field names, table names correspond to entity class names, which can facilitate the operation of database tables)

Entity Class: a mapping formed by the ORM concept in Java. It maps a table in a database to a corresponding Java Class (JavaBean), which is responsible for storing and managing information inside the system.

Pojos (Plain Ordinary Java Objects) : Plain Javabeans, created to avoid confusion with EJBs.

Persistent classes: Classes whose instances need to be persisted to a database. The persistent class conforms to the Javabeans specification and contains private properties and their corresponding getter() and getter() methods.

Persistence: The saving of data (such as an in-memory object) to a permanent storage device. (such as disk, database)

The main application of persistence is to store objects in memory in databases, disk files, XML files, and so on.

In practice, there is no essential difference between Javabeans, entity classes, POJos, and persistence classes, but all must meet the Javabeans specification. In relation to Spring’s management of beans, it is called a JavaBean; In the Spring JDBC Template, you need to operate on the database, called an Entity Class; In persistence frameworks such as MyBatis, relationships between multiple objects are involved, called POJOs or persistence classes.

Has a different name, because need to deal with the logic of the situation is different, like parents, call your nickname in the home, in school, call your full name, my teachers and classmates in the bank for the business staff call you madam/Sir, but you are still you, has the properties such as name, gender, id number, this is you must meet the specification.

Second, Java three-tier system

The Dao layer operates the Entity Class to operate the tables in the database and complete CRUD operations on the corresponding data.

1. The Dao layer

Dao (Data Access Object) is mainly responsible for accessing the database, CRUD the Data, and return the result set to the Service without involving transactions.

2. The Service layer

The Service layer is mainly responsible for the implementation of business logic, which is actually the further encapsulation of the add, delete, change and check operations of the Dao layer, involving the operation of transactions.

Such as: get database connection, close database connection, transaction rollback or some complex logical business processing

3. The Controller layer

The Controller layer is mainly used to control the business logic, control user input, receive requests from the front end, hand over the operations to be performed to the Service layer for processing, and then return the processed results to the front end.

The relationship between the three

Almost all the business logic is actually the operation of the database table. The Dao level implements transactions and business logic to the tables in the database and Service. The Controller layer controls the received requests and then calls the Service layer to implement the business logic. The Service layer gives the operations needed for database tables in logical processing to the Dao layer for data operation, and finally returns the processing results to the front end layer by layer, so that users can see the final processing results.

MVC design pattern

MVC is a software design pattern that divides software programs into three core modules: Model, View and Controller.

Model: Management database, used for data encapsulation and transmission, to achieve specific business functions (transaction processing, algorithms, etc.).

View: Is responsible for interacting with users, obtaining data from the model and presenting it to users through web pages, and transmitting user requests to the controller for processing.

3. The controller

Controller: Receives user requests, processes and forwards them for business process control, and sends data to the model.

The relationship between the three

The user operates the software through View, and the View transfers the request to the Controller. Model is responsible for data management, View is responsible for interaction with the user, and Controller is responsible for responding to the user’s request. At the same time, when the data is updated, it will be transmitted to View and then update the page.

The relationship between three-tier architecture and MVC

There is no contradiction between three-tier system and MVC. Three-tier system is a programming idea, which aims to reduce the coupling between modules and better deal with business logic. MVC is a software design pattern. It divides software into modules according to functions to better realize software development. The relationship between the two is as follows:

The MVC design pattern is explained in detail in the Spring MVC framework, which will be covered after Spring.