---
title: "SSH架构简单总结"
author: "java虫"
date: "2007-03-23T17:01:56Z"
tags: ["DAO", "Hibernate", "SSH", "Spring", "Struts"]
slug: "ssh"
draft: false
lastmod: "2007-03-23T17:01:56Z"
id: 65007
url: "https://ltc603.iteye.com/blog/65007"
---

Struts、spring、Hibernate在各层的作用
<span style="color:red">1）struts 负责 web层. </span>
   ActionFormBean 接收网页中表单提交的数据，然后通过Action 进行处理，再Forward到对应的网页。 在struts-config.xml中定义<action-mapping>, ActionServlet会加载。

<span style="color:red">2）spring 负责业务层管理，即Service（或Manager).  </span>
1． service为action提供统计的调用接口，封装持久层的DAO，。
2．可以写一些自己的业务方法。
3．统一的javabean管理方法
4．声明式事务管理
5.集成Hiberante

<span style="color:red">3）Hiberante，负责持久化层，完成数据库的crud操作</span>
hibernate 为持久层，提供 OR/Mapping。 
它有一组 .hbm.xml文件和 POJO,是跟数据库中的表相对应的。然后定义DAO，这些是跟数据库打交道的类，它们会使用PO。

在struts+spring+hibernate的系统中，
对象的调用流程是：jsp-> Action－> Service ->DAO ->Hibernate。
数据的流向是 ActionFormBean接受用户的数据，Action 将数据从 ActionFromBean 中取出，封装成VO或PO, 再调用业务层的Bean类，完成各种业务处理后再forward。而业务层Bean收到这个PO对象之后，会调用DAO接口方法，进行持久化操作。