Home > Java > javaTutorial > What are the three major frameworks of java

What are the three major frameworks of java

(*-*)浩
Release: 2020-09-16 17:50:56
Original
38742 people have browsed it

Struts, Hibernate and Spring are commonly used keys in our Java development. They provide the most appropriate solutions for different application scenarios. But do you know how these well-known frameworks originally came about?

Recommended course: Java Tutorial.

What are the three major frameworks of java

We know that traditional Java Web applications are implemented using JSP Servlet Javabeans. This model implements the most basic MVC layering, making the program structure divided into There are several layers, including JSP responsible for front-end display, Servlet responsible for process logic control, and Javabean responsible for data encapsulation. However, there are still problems with this structure: for example, JSP pages need to use symbols to embed a lot of Java code, resulting in a confusing page structure. Servlets and Javabeans are responsible for a lot of jumps and calculations, tight coupling, low program reusability, etc.

The three major frameworks of java are:

1. Struts

In order to solve these problems, the Struts framework appeared, which It is a perfect MVC implementation. It has a central control class (a Servlet). For different businesses, we need an Action class to be responsible for page jumps and background logic operations, and one or several JSP pages to be responsible for data input and output display. , there is also a Form class responsible for passing data between Action and JSP. A set of tags provided by the Struts framework can be used in JSP, which is as simple as using HTML tags, but can complete very complex logic. From now on, there is no need to have a line of surrounding Java code in the JSP page.

However, placing all the operation logic in the Action of Struts will make the Action class less reusable and the logic confusing. Therefore, people usually divide the entire Web application into three layers. Struts is responsible for the display layer. The business layer is called to complete the operation logic, and the business layer then calls the persistence layer to complete the reading and writing of the database.

Use JDBC connection to read and write the database. The most common thing we do is to open the database connection, use complex SQL statements to read and write, and close the connection. The obtained data needs to be converted or encapsulated and then transmitted to the outside. This is a Very cumbersome process.

2. Hibernate

The Hibernate framework appears at this time, which requires you to create a series of persistence classes. The attributes of each class can be simply viewed as It has a one-to-one correspondence with the attributes of a database table. Of course, it can also be associated with various table files in a relational database. When we need related operations, we no longer need to pay attention to the database table. We no longer need to query the database line by line. We only need the persistence class to complete the functions of addition, deletion, modification and query. Make our software development truly object-oriented rather than messy code-oriented. My feeling is that using Hibernate reduces the amount of programming by 80% compared to JDBC.

Now we have three layers, but what are the calls between each layer? For example, if Struts in the display layer needs to call a business class, it needs to create a new business class and then use it; if the business layer needs to call the persistence layer class, it also needs to create a new persistence layer class. Calling each other through this new method is the embodiment of the worst design in software development. To put it simply, the caller depends on the callee, and a strong coupling is formed between them. If I want to reuse a class elsewhere, other classes that this class depends on also need to be included. The program becomes very confusing, each class depends on each other and calls each other, and the degree of reusability is extremely low. If a class is modified, many classes that depend on it will be affected. For this purpose, the Spring framework appears.

3. Spring

The function of Spring is to completely decouple the dependencies between classes. If a class depends on something, it is an interface. As for how to implement this interface, it doesn't matter. As long as you get a class that implements this interface, you can easily inject the implementation class into the class that calls the interface through the xml configuration file. This dependency between all classes is completely replaced by configuration files. So the core of the Spring framework is the so-called dependency injection and control inversion.

The current structure is that Struts is responsible for the display layer, Hibernate is responsible for the persistence layer, and Spring is responsible for the middle business layer. This structure is currently the most popular Java Web application architecture in China. In addition, because Spring uses dependency injection and AOP (aspect-oriented programming), its internal model is so excellent that Spring itself has also implemented an MVC framework that uses dependency injection, called Spring MVC. At the same time, for good To handle things, Spring integrates Hibernate, which elevates transaction management from Hibernate's persistence layer to the business layer, making it more convenient and powerful to use.

The Struts framework started in 2000, and the technology is quite mature. Currently, the Struts framework is the undisputed king of display layer technology in global Java development. It has a large user base and a good development team. This is also the basic requirement for new employees by most domestic Java software companies.

other

The term Java seems destined to be closely associated with open source. In the Java world, a large number of open source technologies appear every day. Since it is open source, the problems and shortcomings in the technology will soon be discovered. , open source software providers will quickly modify or expand these technologies, so the version is updated quickly, and a new version will be released in a few weeks or days.

When we choose Java in the technical line, we also choose that you must continue to learn, always pay attention to the latest technologies, understand them, see if they suit your needs, and then learn to use them.

The combination of Java's SSM is also very good, and everyone can learn about it.

The above is the detailed content of What are the three major frameworks of java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template