Article Source: http://www.zretc.com/technologyDetail/476.html
Spring as one of the three big frames, has been puzzled what is her use? Why use Spring? (most of them are from the Internet, citing too many sources, not to be identified.) )。
SSH represents 3 frameworks in the Java EE Project, Spring + Struts +hibernate. Struts provides the corresponding components for both Model,view and controller. Spring is a lightweight control inversion (IoC) and facet-oriented (AOP) container framework that is created by Rod Johnson. It is created to address the complexities of enterprise application development. Spring uses basic JavaBean to accomplish things that were previously only possible by EJBS. Hibernate is an open source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that can be used in any JDBC application, in servlet/jsp Web applications, or in the Java EE architecture of the EJB application to replace the CMP To complete the task of data persistence.
The STRUTS2 principle is to use interceptors so that requests sent by your clients are intercepted and processed. The interceptor is in the reflection mechanism. The main function of STRUTS2 is control forwarding, which is the handling of the action, and the Struts.xml configuration.
Spring actually contains a lot of knowledge, with IOC,AOP and so on, is actually a management framework of the container, you do not have to consider your new object, it will help you do, reduce the layer and layer coupling degree. Spring has a lot of ideas, the IOC is control inversion, injected. AOP is facet-oriented and a bit like an interceptor.
Hibernate is a persistent layer framework, we usually use the JDBC database to write SQL statements, and sometimes a lot of fields will be very troublesome, so with hibernate is very convenient, you just master the mapping inside the relationship, you do not have to write SQL statements, it will help you write, API call is very convenient.
Struts
1.Struts Frame Structure
Struts provides the corresponding components for both Model,view and controller.
In the image on the right, Actionservlet, the class is the core controller of struts and is responsible for intercepting requests from users.
Action, which is typically provided by the user, is responsible for receiving a request from Actionservlet and invoking the model's business logic method to process the request based on the request, and returns the processing result to the JSP page display.
2.Model part
Consists of Actionform and JavaBean, where actionform is used to encapsulate the user's request parameters, encapsulated as a Actionform object, which is forwarded to the action by Actionservlet, The action processes the user's request based on the request parameters inside the Actionform.
The JavaBean encapsulates the underlying business logic, including database access.
3.View part
This part is implemented by JSP.
Struts provides a rich library of tags that can reduce the use of scripts through a tag library, and a custom tag library enables effective interaction with the model and adds real-world functionality. The corresponding JSP part.
4.Controller components
The controller component consists of two parts-the system core controller, the business logic controller.
System core Controller, corresponding to the Actionservlet. The controller is provided by the struts framework and inherits the HttpServlet class, so it can be configured as a callout servlet. The controller is responsible for intercepting all HTTP requests and then deciding whether to transfer to the business logic controller based on user requests.
The business logic controller, which is responsible for processing user requests, does not have the processing power, but calls model to complete processing. Corresponds to the action section.
Spring
1. Introduction
Objective: To solve the complexity of enterprise application development
Function: Use basic JavaBean instead of EJB, and provide more enterprise application function
Scope: Any Java application
In short, spring is a lightweight control inversion (IoC) and aspect-oriented (AOP) container framework.
2. Light weight
Spring is lightweight both in terms of size and overhead. The full spring framework can be published in a jar file with a size of more than 1MB. and the processing overhead required by spring is negligible.
In addition, spring is non-intrusive: Typically, objects in spring applications do not depend on a particular class of spring.
3. Control reversal
Spring facilitates loose coupling through a technique called inversion of Control (IoC). When an IOC is applied, other objects that an object relies on are passed in passively, rather than the object itself creating or locating dependent objects. You can think of the IOC as opposed to Jndi--not the object looking for dependencies from the container, but the container actively passing the dependency to it when the object is initialized without waiting for the object to be requested.
4. Face Tangent
Spring provides rich support for aspect-oriented programming, allowing for the development of cohesion through the separation of application business logic with system-level services such as auditing (auditing) and transaction (transaction) management.
The Application object only implements what they should do-complete the business logic-that's all.
They are not responsible (or even conscious) for other system-level concerns, such as log or transaction support.
5. Containers
Spring contains and manages the configuration and lifecycle of the Application object, in this sense it is a container where you can configure how each of your beans is created-based on a configurable prototype (prototype), Your bean can create a separate instance or generate a new instance each time it is needed-and how they relate to each other.
However, spring should not be confused with traditional heavyweight ejb containers, which are often bulky and cumbersome and difficult to use.
6. Framework
Spring can configure and combine simple components into complex applications. In spring, application objects are combined declaratively, typically in an XML file. Spring also provides a number of basic functions (transaction management, persistence framework integration, etc.), leaving the development of application logic to you.
All of these features of spring enable you to write cleaner, more manageable, and easier-to-test code. They also provide basic support for the various modules in spring.
Hibernate
1. Introduction
Hibernate is an open-source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that allows Java programmers to manipulate databases at will using object programming thinking. Hibernate can be applied to any JDBC application, both in Java client applications and in servlet/jsp Web applications, and most revolutionary of all, hibernate can replace CMP in the EE architecture of the EJB application. The task of achieving data persistence.
Hibernate has a total of 5 core interfaces: Session, sessionfactory, Transaction, query, and configuration. These 5 core interfaces will be used in any development. Through these interfaces, you can not only access persistent objects, but also enable transaction control. These five core interfaces are described separately below.
2.Session interface
The session interface is responsible for performing crud operations on persisted objects (the task of crud is to complete the communication with the database, including many common SQL statements. )。 However, it is important to note that the session object is non-thread-safe. At the same time, Hibernate's session differs from the HttpSession in JSP applications. When the term "session" is used, it is actually referring to the session in Hibernate, and later the Httpsesion object is called the user session.
3.SessionFactory interface
The Sessionfactory interface is responsible for initializing hibernate. It acts as a proxy for the data storage source and is responsible for creating session objects. The factory model is used here. It is important to note that Sessionfactory is not lightweight, because in general, a project typically requires only one sessionfactory, and when you need to manipulate multiple databases, you can specify a sessionfactory for each database.
4.Configuration interface
The configuration interface is responsible for configuring and starting hibernate to create the Sessionfactory object. During Hibernate startup, the instance of the configuration class first locates the map document location, reads the configuration, and then creates the Sessionfactory object.
5.Transaction interface
The transaction interface is responsible for transaction-related operations. It is optional, and developers can also design their own underlying transaction-processing code.
6.Query and Criteria Interface
The query and criteria interfaces are responsible for executing various database queries. It can be expressed in either the HQL language or the SQL statement.
Weibo_ Jing Guangming Admiral _0
Links: http://www.imooc.com/article/7283
Source: MU-Class Network
Learn more about getting started with Java programmers Welcome to the technical knowledge base of soft international education Group!
Java Programmer Training: Why use Spring with three big framework profiles