Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Struts + Hibernate + Spring WEB framework

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Struts: responsible for the display layer, is a perfect MVC implementation, it calls the business layer to complete the operation logic, the business layer and then calls the persistence layer to complete the database reading and writing.

Hibernate: Create a series of persistent classes, mapping the attributes of each class to the attributes of the database table.

Spring: Dependency injection and control inversion. Once you get a class that implements this interface, you can easily inject the implementation class into the class that calls the interface via an xml configuration file. This dependency between all classes is completely replaced by configuration files.

Java Web application architecture: Struts for the display layer, Hibernate for the persistence layer, Spring for the middle business layer.

In addition, because Spring uses dependency injection and AOP(aspect-oriented programming), so its internal pattern is very good, so that Spring itself also implements a dependency injection MVC framework, called Spring MVC, and in order to deal with things well, Spring integrates Hibernate, making things management from Hibernate's persistence layer to the business layer, more convenient and powerful to use.

The so-called three-tier development is to divide the whole business application of the system into "presentation layer-business logic layer-data access layer"

1、Struts

Struts control files struts-config.xml, Action and Action Servlet implement the controller of MVC, JavaBean or EJB completes the model part of MVC, JSP pages undertake the view component of MV, and all control logic is completed by struts-config.xml configuration file.

Struts2 provides a rich interceptor implementation

2、Hibernate

Hibernate is a lightweight framework for the data persistence layer, which encapsulates JDBC in a very lightweight object that Java programmers can use at will.

Object programming thinking to manipulate databases. It provides a method to query and obtain data, and operates database with object-oriented idea to save the time of developing and processing data.

On top of the physical database, some configuration files such as hibernate.cfg.xml, Action and Action files, XML Mapping(mapping files), etc. are used to provide the application system

Provide data persistence services, while achieving the purpose of isolating the persistence layer of the application system from different physical database systems.

Hibernate workflow:

reading and parsing configuration files;

Configuration is responsible for reading and creating mapping information, creating session factory

SessionFactory is responsible for creating sessions;

Transaction is responsible for opening Transaction;

Query is responsible for performing persistence operations;

Transaction is responsible for submitting transactions;

close session and session factory;

Hibernate provides two levels of Cache, the first level cache is the Session level cache, which belongs to the transaction scope cache. Managed by Hibernate, usually without intervention. The second level cache is the Session Factory level cache, which is process-wide or cluster-wide. It can be configured and changed, and can be dynamically loaded and unloaded.

3、Spring

Spring: Core containers provide the basic functionality of the Spring Framework. The main component of the core container is Bean Factory, which is an implementation of the factory pattern. Bean Factory uses the Inversion of Control (IOC) pattern to separate an application's configuration and dependency specifications from the actual application code. Inversion of control or dependency injection is at the heart of Spring. Certain dependencies between objects are injected by the container into the caller during runtime, and the implementation of relationships between control programs is left to external containers.

Dependency injection exists in 2 implementations:

1. Set injection

2. Structural injection

Summary:

Struts is used for presentation layer, directly facing users, responding to user requests, providing a model and a controller for display, and delegating functions such as calling business logic and other upper processing.

Spring's unique capabilities in transaction management and dependency injection, implementation of business logic and business validation for handling applications, and providing interfaces to interact with other layers.

Hibernate is an implementation of ORM (Object Relational Mapping), which is used to build persistent objects of Java object model, and then to conveniently operate relational database in an object-oriented way.

Struts, Spring, and Hibernate can encapsulate programs at all levels, such as dealing with the foreground presentation layer without mixing transaction logic and persistence logic, thus maximizing the goal of high cohesion and low coupling at all levels.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report