java three-tier architecture: understanding the persistence layer, business layer, presentation layer

SH:

The Struts (Presentation Layer) + Spring (business layer) + Hibernate (persistence)

Struts:

Struts framework is represented by a layer, the main role is to show the interface, receiving a request, distribution request.

 

In the MVC framework, Struts belongs to the VC level, responsible for the performance of the interface, responsible for the distribution MVC relations.

(View:沿用JSP,HTTP,Form,Tag,Resourse ;

Controller:ActionServlet,struts-config.xml,Action)

Hibernate: Hibernate is a persistence framework, it is responsible for the operation and the relational database.

Spring: Spring is a business layer framework, is an integrated framework can be a good bonding presentation layer and persistence layer.

 

We know that traditional Java Web applications are written using JSP + Servlet +, this model Javabean implemented to achieve the most basic MVC layered, so that the program structure is divided into several layers, foreground there is JSP responsible for the show, is responsible for the process and logic control Javabean Servlet responsible for data encapsulation. However, this structure is still a problem: as JSP pages need to use a lot of symbols embedded Java code, confusion page structure, Servlet and Javabean responsible for a lot of jump and operational work, tightly coupled, low program reusability and so on.

 

Struts

To solve these problems, there has been Struts framework, it is a perfect MVC implementation, it has a central control class (a Servlet), for different business, we need an Action class is responsible for the page jump back and logical operations, or a JSP pages several input and output for data display, there is a Form class is responsible for transmitting the intermediate data Action and JSP. You can use JSP Struts framework provides a set of labels, just as simple as using HTML tags, but can do very complex logic. From this line of Java code does not need to appear surrounded by a JSP page. But all logic operations are placed in the Struts Action Class Action will make a low degree of multiplexing and logical confusion, so people usually put the entire Web application is divided into three layers, Struts responsible for the display layer, it invokes the business logic layer to complete the operation , business layer and then call the persistence layer to read and write to the database. Read and write using JDBC connection to the database, the most common is we open the database connection, use complex SQL statements to read and write, close the connection, the data obtained and the need to convert or after packaging to rumor, this is a very cumbersome process.

 

Hibernate

Then there was the Hibernate framework, it requires you to create a series of persistent classes, each class attributes and properties can simply be seen as a one to one database table, of course, you can achieve a variety of relational database tables associated with the corresponding member. When we need the relevant operation is no longer concerned about the database table. We did not have to query the database rows, just persistent class can be completed CRUD functionality. So that we truly object-oriented software development instead of facing messy code. My feeling is that the use of Hibernate 80% less than the amount JDBC programming mode. 

 

Now we have three layers, but calls between each layer what is it like Struts presentation layer of the need to call a business class, you need a new business class out, and then use;? Need to call the business layer class persistence layer, also it requires a new class out with persistence layer. In this new way of calling each other is reflected in the development of software designed for the worst. Simply put, that is, the caller is dependent on the caller, the formation of a strong coupling between them, if I want to reuse in other parts of a class, the class dependent on other classes also need to be included. Program becomes very confusing, each class rely on each other to call each other, reusability is very low. If a class has been modified, it is dependent on a lot of class will be implicated. 

 

To this end, Spring Framework appear.

Spring Spring is the role of the dependencies between completely decoupled class, a class if you want to rely on anything, it is an interface. As for how to implement this interface, it is not important. Just got a implements this interface, you can easily through xml configuration file to implement class injected into the call interface in that class. This dependency between all classes by completely replaces the profile manner. So the core Spring Framework dependency injection, and the so-called inversion of control. 

 

The structure is now, Struts responsible for the display layer, Hibernate persistence layer is responsible, Spring business layer is responsible for the middle of this structure is the most popular Java Web application architecture of.

Further, since the use Spring dependency injection and the AOP (aspect-oriented programming), so that its internal model is very good, so that he is achieved Spring dependency injection using a MVC framework, called the MVC Spring, while for good deal with things, Spring integrates Hibernate, the object management improvement from the Hibernate persistence layer to the business layer, easier to use and powerful. Struts framework was started in 2000, and has now developed into a five-year, technology is quite mature, the current global Java development framework Struts layer technology is worthy of the king in the display. It has a large user base and good development team. It is also the most basic requirements of Java software company for new employees. This term seems destined to other Java and open source closely together in the Java community, there are a large number of open source technologies emerge every day, because it is open source, technology problems and shortcomings will soon be found, open source software providers will soon amend or extend these techniques, so the updated version soon, a few weeks or a few days there is a new version comes out. When we chose Java technology in line, it chose you must continue to learn, always concerned about the latest technology, to understand them, to see if fits your needs, then learn to use them.

Released six original articles · won praise 3 · Views 800

Guess you like

Origin blog.csdn.net/SmileLucki/article/details/104813958