In Action java layer, Service layer and the functional layer distinguishing Dao (plain)

A, Action / Service / DAO Description:
Action is management business (Service) scheduling and management jump.
Service management is a specific function.
Action is only responsible for the management, and Service responsible for implementation.
DAO only completed CRUD, although 1-n, nn, 1-1 association, blur, dynamic, can subqueries. 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 is a matter of.
Summing up the three to explain by example:
Action like a waiter, customers what to order, the food to the table a few numbers, all ta duties;
Service is the chef, dishes on the menu are all action sent ta do ;
Dao is the kitchen laborer, things and materials dealing with all ta tube.
The relationship is, unskilled laborer (dao) job is to meet the requirements of the chef (service), and to meet the chef waiter (action) to convey the client (user page) requirements, the waiter is natural for customer service myself.
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.
Second, the three framework Struts / Hibernate / Spring
Simply put:
  Struts-- of control;
  Hibernate-- operation of the database;
  Spring-- decoupling used.
In detail, said:
  1.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.
  2.Spring is a lightweight inversion of control (IoC) and section (AOP) facing 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.
  3.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.
  Third, the business logic framework analysis:
  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 classes, 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 and do 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): is responsible for data CRUD operations to the database in the frame of the registration, if not used in the Spring, the data transfer between each layer of the layer requires a data call a new class. examples. 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 blog.csdn.net/h471507602/article/details/92396667