您的当前位置:首页正文

ssh框架1(翻译完毕)

2021-03-07 来源:步旅网
SSH framework

SSH is an integrated framework of struts + spring + hibernate, is currently the more popular a kind of open source Web application framework.

System of integrated SSH framework from the responsibility is divided into four layers: the presentation layer, business logic layer and data persistence layer and domain module layer, to help developers to build in the short term clear structure, good reusability, convenient maintenance of Web application. Using Struts as a system of the whole infrastructure, responsible for the separation of MVC, in the model part of the Struts framework, jump control business, using Hibernate framework to support the persistence layer, Spring to do management, management of Struts and Hibernate. Particular way is: use the object-oriented analysis method according to the demand for some models, these models as the basic Java Objects, and then write basic DAO (Data Access Objects) interface, and give the Hibernate DAO implementation, using Hibernate architecture implementation of DAO class to implement the conversion between Java classes and database and Access and finally by the Spring to do management, management of struts and Hibernate. The business process

Basic business processes of the system is: in the presentation layer, the first by the JSP page implementation interface, is responsible for receiving a Request (Request) and the transmission Response (Response), and then the Struts, according to the configuration file (Struts - config. XML) delegate the ActionServlet receives the Request to the appropriate Action. Service component in the business layer, the management of the Spring IoC container is responsible for providing business Model (Model) to the Action component and the component of collaborating objects data processing (DAO) complete business logic component, and provide the transaction, such as buffer pool container components to improve system performance and ensure the integrity of the data. While in the persistence layer, relies on the objectification of Hibernate mapping and database interaction, dealing with the DAO components request data, and returns the result of a decision making process.

Adopt the development model, not only to achieve the complete separation of view, controller and model, but also realizes the separation of business logic layer and persistence layer. So no matter how changes in the front, the model layer is little changes, and database changes will not affect on the front end, greatly improving the reusability of the system. And due to the coupling between different layers is small, is conducive to team members work in parallel, greatly improve the efficiency of development. Frame structure Struts1

Struts on the Model, View and Controller provides the corresponding component.

The ActionServlet, this class is the core of the struts 2 controllers, is responsible for the intercept from the user's request.

Action, this class is usually provided by the user, the controller is responsible for receiving a request from the ActionServlet, call the business logic of the model method according to the request processing requests, and the results returned to the JSP page displays.

The Model part:

Composed of actionforms and JavaBean, including actionforms are used to the user's request parameters are encapsulated into actionforms object, the object is the ActionServlet is forwarded to the Action, the Action according to the inside of the actionforms request parameters for handling the user's request. JavaBean encapsulates the underlying business logic, including database access and so on.

The View part:

This part adopts JSP (or HTML, PHP,...) The implementation.

The Struts tag library provides a rich, through the use of tag libraries can reduce script, the custom tag library can realize the effective interaction with the Model, and strengthen the function of the reality. Corresponding JSP part of the above.

The Controller module:

Controller component is composed of two parts - the system core Controller, business logic Controller.

System, the core controller corresponding to the above the ActionServlet. The controller inherits the HttpServlet class, so can be configured to the Servlet. The controller is responsible for stopping all HTTP requests, and then according to user's request to decide whether or not to to business logic controller.

Business logic controller, responsible for handling user requests, itself does not have the ability to handle and instead call the Model to complete the processing. The corresponding Action.

Spring

Spring is an open source framework, it founded by Rod Johnson. It is in order to solve the complexity of enterprise application development and creation. Spring use basic JavaBean to complete before things can only be performed by the EJB. However, the purpose of the Spring is not only confined to the server-side development. From simplicity, testability, and the Angle of loose coupling, any Java application can benefit from the Spring.

Objective: to solve the complexity of enterprise application development

Function: use the basic JavaBean instead of EJB, and provides more enterprise applications Scope: any Java application

In simple terms, the Spring is a lightweight inversion of control (IoC) and the aspect oriented (AOP) container framework.

Lightweight - -from two aspects of size and overhead Spring is a lightweight. Complete the Spring framework can be in a JAR file size is more than 1 MB in the release. And Spring the required processing overhead is negligible. In addition, the Spring is a non-invasive: typically, the Spring does not depend on the Spring of a particular class of objects in the application.

Inversion of control -- Spring through a known as inversion of control (IoC) technology promotes loose coupling. When the application of the IoC, of an object depend on other objects will be passed through a passive way, rather than the object or create your own lookup dependent objects. You can think of the IoC in contrast to the JNDI - not object from the container to find rely on, but the container in the object initialization time and tide wait for no object request would rely on active passed to it.

Aspect oriented - Spring provides extensive support aspect oriented programming, allowed by separating the business logic of the application and system level services (such as audit (auditing) and transaction (transaction) management) for the development of internal cohesion.

Application objects only realize they should do, complete business logic, that's all. They are not responsible for (even) consciousness of other system level concerns, such as logging or transaction support.

Container -- Spring contains and manages the configuration of the application object and life cycle, in this sense it is a container, you can configure how your each bean is created based on a configurable prototype (prototype), your bean can create a separate instance or every time you need to generate a new instance - and how they are interrelated.

Framework - Spring can be a simple component configuration, combination become complex applications. In Spring, the application object is declarative combination, typically in an XML file. Spring also provides many basis functions (transaction management, persistence framework integration, etc.), the development of the application logic for you.

All these features enable you to write the Spring cleaner, more manageable, and easier to test the code. They also provide the basis for the various modules in the Spring support.

Hibernate

Hibernate is an open source object-relational mapping framework, it is very lightweight for JDBC object encapsulation, make the use of Java programmers can follow one's inclinations to manipulate the database object programming thinking. Hibernate can be used in any situation, using the JDBC can be used in Java client program, can also be used in the Servlet/JSP Web application, the most revolutionary significance is that Hibernate can replace the CMP in EJB of J2EE application architecture, to complete the important task of data persistence. Hibernate advantages:

1, encapsulate JDBC, simplifies a lot of repetitive code.

2, simplifies the DAO layer coding, make development more objectivity.

3, good portability, support a variety of databases, if change the database configuration is ok as long as in the configuration file transformation, without changing the hibernate code.

4, support transparent persistence because hibernate operation is pure Java classes (pojo), don't implement any interface, no invasive. So it is a lightweight framework. Hibernate delay loading:

Get not to support lazy loading, load support lazy loading. 1, hibernate2 of entity object and collection for lazy loading 2, hibernate3 lazy-loading function of provides properties

Hibernate is lazy loading when using session. The load (User. The class 1) or session. The createQuery () query objects or attributes of the object or attribute is not in memory, only when the program operation data, may only exist in memory, thus realize the lazy loading, saving memory overhead, thus improve the performance of the server.

ssh框架

SSH 为 struts+spring+hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架。

集成SSH框架的系统从职责上分为四层:表示层、业务逻辑层、数据持久层和域模块层,以帮助开发人员在短期内搭建结构清晰、可复用性好、维护方便的Web应用程序。其中使用Struts作为系统的整体基础架构,负责MVC的分离,在Struts框架的模型部分,控制业务跳转,利用Hibernate框架对持久层提供支持,Spring做管理,管理struts和hibernate。具体做法是:用面向对象的分析方法根据需求提出一些模型,将这些模型实现为基本的Java对象,然后编写基本的DAO(Data Access Objects)接口,并给出Hibernate的DAO实现,采用Hibernate架构实现的DAO类来实现Java类与数据库之间的转换和访问,最后由Spring做管理,管理struts和hibernate。

业务流程

系统的基本业务流程是: 在表示层中,首先通过JSP页面实现交互界面,负责接收请求(Request)和传送响应(Response),然后Struts根据配置文件(struts-config.xml)将ActionServlet接收到的Request委派给相应的Action处理。在业务层中,管理服务组件的Spring IoC容器负责向Action提供业务模型(Model)组件和该组件的协作对象数据处理(DAO)组件完成业务逻辑,并提供事务处理、缓冲池等容器组件以提升系统性能和保证数据的完整性。而在持久层中,则依赖于Hibernate的对象化映射和数据库交互,处理DAO组件请求的数据,并返回处理结果。

采用上述开发模型,不仅实现了视图、控制器与模型的彻底分离,而且还实现了业务逻辑层与持久层的分离。这样无论前端如何变化,模型层只需很少的改动,并且数据库的变化也不会对前端有所影响,大大提高了系统的可复用性。而且由于不同层之间耦合度小,有利于团队成员并行工作,大大提高了开发效率。

框架结构 Struts1

Struts对Model,View和Controller都提供了对应的组件。

ActionServlet,这个类是Struts1的核心控制器,负责拦截来自用户的请求。

Action,这个类通常由用户提供,该控制器负责接收来自ActionServlet的请求,并根据该请求调用模型的业务逻辑方法处理请求,并将处理结果返回给JSP页面显示。

Model部分:

由ActionForm和JavaBean组成,其中ActionForm用于将用户的请求参数封装成ActionForm对象,该对象被ActionServlet转发给Action,Action根据ActionForm里面的请求参数处理用户的请求。JavaBean则封装了底层的业务逻辑,包括数据库访问等。

View部分:

该部分采用JSP(或HTML、PHP……)实现。

Struts提供了丰富的标签库,通过标签库可以减少脚本的使用,自定义的标签库可以实现与Model的有效交互,并增加了现实功能。对应上图的JSP部分。

Controller组件:

Controller组件有两个部分组成——系统核心控制器,业务逻辑控制器。

系统核心控制器,对应上边的ActionServlet。该控制器继承了HttpServlet类,因此

可以配置成标注的Servlet。该控制器负责拦截所有的HTTP请求,然后根据用户请求决定是否要转给业务逻辑控制器。

业务逻辑控制器,负责处理用户请求,本身不具备处理能力,而是调用Model来完成处理。对应Action部分。 Spring

Spring是一个开源框架,它由Rod Johnson创建。它是为了解决企业应用开发的复杂性而创建的。Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情。然而,Spring的用途不仅限于服务器端的开发。从简单性、可测试性和松耦合的角度而言,任何Java应用都可以从Spring中受益。

目的:解决企业应用开发的复杂性

功能:使用基本的JavaBean代替EJB,并提供了更多的企业应用功能 范围:任何Java应用

简单来说,Spring是一个轻量级的控制反转 (IoC)和面向切面(AOP)的容器框架。 轻量——从大小与开销两方面而言Spring都是轻量的。完整的Spring框架可以在一个大小只有1MB多的JAR文件里发布。并且Spring所需的处理开销也是微不足道的。此外,Spring是非侵入式的:典型地,Spring应用中的对象不依赖于Spring的特定类。

控制反转——Spring通过一种称作控制反转(IoC)的技术促进了松耦合。当应用了IoC,一个对象依赖的其它对象会通过被动的方式传递进来,而不是这个对象自己创建或者查找依赖对象。你可以认为IoC与JNDI相反——不是对象从容器中查找依赖,而是容器在对象初始化时不等对象请求就主动将依赖传递给它。

面向切面——Spring提供了面向切面编程的丰富支持,允许通过分离应用的业务逻辑与系统级服务(例如审计(auditing)和事务(transaction)管理)进行内聚性的开发。应用对象只实现它们应该做的——完成业务逻辑——仅此而已。它们并不负责(甚至是意识)其它的系统级关注点,例如日志或事务支持。

容器——Spring包含并管理应用对象的配置和生命周期,在这个意义上它是一种容器,你可以配置你的每个bean如何被创建——基于一个可配置原型(prototype),你的bean可以创建一个单独的实例或者每次需要时都生成一个新的实例——以及它们是如何相互关联的。然而,Spring不应该被混同于传统的重量级的EJB容器,它们经常是庞大与笨重的,难以使用。

框架——Spring可以将简单的组件配置、组合成为复杂的应用。在Spring中,应用对象被声明式地组合,典型地是在一个XML文件里。Spring也提供了很多基础功能(事务管理、持久化框架集成等等),将应用逻辑的开发留给了你。

所有Spring的这些特征使你能够编写更干净、更可管理、并且更易于测试的代码。它们也为Spring中的各种模块提供了基础支持。

Hibernate

Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库。 Hibernate可以应用在任何使用JDBC的场合,既可以在Java的客户端程序使用,也可以在Servlet/JSP的Web应用中使用,最具革命意义的是,Hibernate可以在应用EJB的J2EE架构中取代CMP,完成数据持久化的重任。 hibernate优点:

1、封装了jdbc,简化了很多重复性代码。

2、简化了DAO层编码工作,使开发更对象化了。

3、移植性好,支持各种数据库,如果换个数据库只要在配置文件中变换配置就可以了,不

用改变hibernate代码。

4、支持透明持久化,因为hibernate操作的是纯粹的(pojo)java类,没有实现任何接口,没有侵入性。所以说它是一个轻量级框架。 hibernate延迟加载:

get不支持延迟加载,load支持延迟加载。

1、hibernate2对 实体对象和集合 实现了延迟加载 2、hibernate3对 提供了属性的延迟加载功能

hibernate延迟加载就是当使用session.load(User.class,1)或者session.createQuery()查询对象或者属性的时候

这个对象或者属性并没有在内存中,只有当程序操作数据的时候,才会存在内存中,这样就实现延迟加载,节省了内存的开销,从而提高了服务器的性能。

因篇幅问题不能全部显示,请点此查看更多更全内容