What is the difference between SPRNG and struts?

  • 2020-04-01 03:57:21
  • OfStack

Spring:

1) open source framework

2)IoC (inversion of control), which writes the creation and dependencies of classes in the configuration file and is injected by the configuration file, achieves loose coupling

3)AOP extracts the relatively independent functions of security, transaction and program logic, and inserts these functions in the configuration file of spring to realize programming according to aspects and improve reusability

Differences between struts and spring

Structs: like ww2, etc., structs are typical MVC structural framework). Structs focus on the presentation layer, and it ACTS as a controller, which can well separate the presentation layer from the business layer. Spring: to put it bluntly, it's a hodgepodge of popular frameworks that offer integration with hibernate, the classic, mail,axis... All kinds. In addition, it is more classic is IOC and AOP functionality. In addition, it provides Spring MVC, which is based on webflow. Spring is a collection of web framework technologies that are characterized by lightweight, non-invasive, decoupled design, and more. The most commonly used is its IoC/DI, or inversion of control/dependency injection, such as declaring beans in XML, and runtime injection.

I can't understand it well because I don't understand it very well.

Simply say struts spring hibernate this 3 mainstream open source, the industry in fact the standard framework!

Not struts in the early, we transfer data Taiwan before and after, are in the scope of the object (page, request, session, application), contains a lot of the getParameter and getAttribute, as well as the data type conversion. A lot of time was wasted. Moreover, there are many developments that do not use the MVC pattern, which increases the difficulty of later maintenance and secondary development.

In this case, struts came into being. It provides three components for us to use. The front-end and back-end database transfer is delivered by actionform, which is directly encapsulated into objects. Easy to operate. Moreover, as a typical implementation of MVC, the separation of view and control layer makes the code clearer and easier to maintain.

In the early days of doing JDBC, I'm sure you all had the experience of writing your own database action classes, passing database action statements, executeUpdate and executeQuery and then again looping through the result set and closing the link. And the database is a relational database, and the Java development, is the object model, the relational-object transformation, is also a headache. In enterprise development, the most headache is to change the database, if the early requirements analysis is not in place, it means that the project will start over the embarrassment.

The hibernate framework provides a built-in method, a simple save merge delete find method, to achieve the functionality that previously required a lot of coding, and to automatically encapsulate values into javabeans, easy to use. And we don't have to worry about when to open the database link and when to close the database link. And hibernate also provides the function of database switching, simple configuration can be very convenient. You don't have to write fancy SQL statements.

As for spring, it really is the spring for Java developers. Rod Johnson in 2002 by the Expert to one to one J2EE design and development ", the Java EE framework of orthodox overstaffed, inefficient and question the reality of the status quo, in the book, the author according to his many years of rich experience in practice, on the EJB bulky bloated structure individually analyzed and negation, and replaced in the form of concise and practical. My Java teacher and I had a class: at the time, the industry kept Shouting, "no ejbs is j2ee development. And ejb development is too complicated for most people to understand."

In short, Spring is a lightweight inversion of control (IoC) and aspect-oriented (AOP) container framework. Ioc can also be understood as dependency injection. This means that dependencies between programs are managed by spring, reducing the degree of coupling between programs. In the program, we simply inject an object as a property into the object, and leave the instantiation to spring to manage without an instance. As for the implementation of the object, it can be configured in the configuration file. Of course, these objects must all conform to a specification (Interface). Aop is oriented to aspect programming, and spring's declarative transactions use aop to implement the wok. If we want to add transactions to methods in hibernate, we need to care about whom and where we add them, and with declarative transactions, we don't need to care about these details. Spring takes care of everything.

What all three frameworks have in common is that they are lightweight and flexible to use.

I'm just saying a few things here. There are a lot of things worth studying, not just one or two sentences.

It should also be noted that spring is not responsible for the business layer, but collects the scattered "facets" in the system together for centralized management, so that we programmers can have more energy to focus on the development of the business layer and speed up the development progress of the software.

The above is the entire content of this article, there is a need for the companion can refer to the next.


Related articles: