Action / Service / DAO a Profile

Reprinted: https://www.cnblogs.com/wym789/p/6393857.html

SSH basic architecture of a hierarchical manner:

modle layer: is the entity class database tables corresponding to the real object coming into classes. Store your entity class

Dao layer: Hibernate is the use of a database connection, a database operation (CRUD), and the model layer.

Service layer: a reference database operations corresponding Dao, where you can write code (such as a simple determination) you need.

Action layers: a reference layer corresponding Service, herein incorporated Struts configuration file, jumping to a specific page, of course, can accept the requested page of data transfer, the calculation processing can be done.

 

action is part of the business layer, is a manager (main switch) (action is taken reverses) (extracted data reception interface, calls the service method, or an action is forwarded to the next page) 

Model layer model: entity objects is generally (the real thing into java objects in) the role of temporarily storing data to facilitate a persistent (or write to a file stored in the database) Second class encapsulates some data to a different and all the layers use java object.
dao data access layer is used to access the database for persistence of data (the data in memory permanently saved to your hard disk
Service is to manage specific functions.
Action is only responsible for the management, and Service is responsible for implementing.
DAO only completed CRUD , although 1-n, nn 1-1 association, blur, dynamic, sub-queries can be. but no matter how complex the query, dao package just CRUD. As for additions and deletions to change search how to implement a function, dao are no . the
summary of these three, be explained by an example:
Action like a waiter, customers what to order, to number a few dishes on the table, are the responsibility of ta;
Service is the chef, dishes on the menu are all action sent ta do;
Dao is the kitchen unskilled laborer, things and materials dealing with all ta tube

Now the most basic hierarchical manner, combined with SSH architecture. Model layer entity class database table that corresponds. Dao layer is formed using a hibernate database connection, a database operation (CRUD). Service layer: a reference database operations corresponding Dao. Action layers: a reference layer corresponding Service, herein incorporated Struts configuration file, jumping to a specific page, of course, can accept the requested page of data transfer, the calculation processing can be done.
More than Hibernate, Struts, needs to be injected into the spring configuration files, Spring these linked as a whole.
Three framework Struts / Hibernate / Spring
Briefly:
Struts-- of control;
; Hibernate-- database operation
Spring-- decoupling used.
In detail say:
the Struts acts as the SSH control frame, which is a core Controller, ActionServlet i.e., the core is treated ActionServlet Struts-config.xml, the primary control logic.
Hibernate data persistence layer, it is a new object-relational mapping tool that provides mapping from Java classes to tables of data, but also provides data query and recovery mechanisms, greatly reduce the complexity of data access. The direct operation of the database, converted into operations on persistent objects.
Spring is a lightweight inversion of control (IoC) and the facing section (AOP) of the container frame. Interface-oriented programming, the container dependencies between process control, rather than the traditional implementation, directly controlled by the program code. This is called "inversion of control" concept where :( dependent) control by the application code to an external container, control of the transfer, the so-called inversion. Dependency injection, that is, dependencies between components at runtime is determined by the container, figuratively speaking, that is dynamically inject the dependencies into some kind of container components, the main role is played by decoupling.

Struts, Spring, Hibernate role layers:
(. 1) is responsible for the Struts Web Layer: receiving data ActionFormBean form submission page, and then treated by the Action, Forward and then to the corresponding page. It is defined in the Struts-config.xml, ActionServlet loads.
(2) Spring is responsible for managing the business layer, namely Service (or Manager).
Service provided statistics for the action call interface, encapsulation DAO persistence layer;
you can write some of their own business methods;
unified Javabean management;
declarative transaction management;
integrated Hibernate.
(3) Hibernate, responsible for the persistence layer, to complete the operation of the database crud. Providing OR / Mapping. It consists of a set of .hbm.xml files and POJO, it is corresponding with the database appearances. Then define the DAO, which is dealing with the database class, they will use the PO.
Analysis frame business logic:
In Struts + Spring + Hibernate system,
call flow objects is: JSP-Action-Service-DAO -Hibernate.

Is the flow of data: user data receiving ActionFormBean, Action ActionFormBean removed from the data, encapsulated into VO or PO, and then call the business layer Bean class, and then perform various service processing Forward. While the business layer Bean received the PO after the object will call DAO interface method, persistence operations.
SSH framework advantage: The biggest advantage is that Hibernate database tables, generating a reverse entity
class, and also the relationship between the inside, there is the operating data it is also very convenient, Spring omitted inside the new class object process, this relationship is called the call directly to the display configuration file,
any operation becomes simple.
Illustrates a simple process: build a good framework, and the introduction of various jar After coating, business logic analysis starts - assuming a basic registration function: page has two text boxes, a username (username) and a password (password). QQ registration page in order to illustrate, here nickname and password as a representative example.
The first is the action layer: it is, as well as the role between the page and the program is responsible for transferring data to make the jump page. Page filled out by the user form data, click on the submit button, the form data pages automatically encapsulated by the Hibernate to this page form corresponding ActionFrom (ActionFrom with the entity class is not a thing, ActionFrom is page what value class to write what attributes, form is used to encapsulate data; and entity class field of the database is in full accordance with the generated class can be used as the entity ActionFrom used, but not as an absolute ActionFrom entity class used), so as to form data of the object in the Action ActionFrom click "submit button" that method of execution in existence. This time need to do is to form data stored in the database. At this time, Action features come to an end, then the data is passed BIZ layer. BIZE layer (the business logic): responsible for the processing of the data. If there is no data processing tasks, then this layer only simple data transfer effect, and then to the DAO layer.
DAO layer (layer database operations): responsible for the data CRUD operations to the database, is used to access the database for persistence of data (the data in memory permanently saved to your hard drive) in the framework of the registration, if. Spring's, the data transfer between each layer needs a new instance of the class layer data call. The use of Spring, then, need to do is put the DAO layer and each class BIZ layer write an interface class, interface class to write a method implementation class, when the call is not new objects directly with the object point (.) the method can, do not forget to add each object set / get methods.

 

Guess you like

Origin www.cnblogs.com/wsnan/p/11613734.html