zoukankan      html  css  js  c++  java
  • SSH

    http://www.cnblogs.com/hoobey/p/5512924.html

    struts   ---  控制器

    hibernate   操作数据库

    spring        解耦

    Struts 、 spring 、 Hibernate 在各层的作用

    1 ) struts 负责 web 层 .

    ActionFormBean 接收网页中表单提交的数据,然后通过 Action 进行处理,再 Forward 到对应的网页。

    在 struts-config.xml(struts1的配置文件,Struts.xml 是Struts2的) 中定义 <action-mapping>, ActionServlet 会加载。

    2 ) spring 负责业务层管理,即 Service (或 Manager).

    1 . service 为 action 提供统计的调用接口,封装持久层的 DAO.

    2 .可以写一些自己的业务方法。

    3 .统一的 javabean 管理方法

    4 .声明式事务管理

    5. 集成 Hiberante

    3 ) Hiberante ,负责持久化层,完成数据库的 crud(增删改查) 操作

    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 接口方法,进行持久化操作。

       --

    spring:Aop管理事务控制,IoC管理各个组件的耦合,DaoTemplate作为常规持久层的快速开发模板! 

    struts:控制层Action,页面标签和Model数据,调用业务层 

    Hibernate:负责数据库和对象的映射,负责DAO层(Data Access Object:数据访问) 

    spring整合hibernate和struts,只要在配好了applicationContext.xml,在struts的action中直接调用就可以了。hibernate访问数据库的操作都在spring中实现了,spring的调用又在stuts的action中实现了。这个ssh框架就连到了一起……

    一个简单的SSH例子

    配置文件

    /SSHLoginDemo/WebRoot/WEB-INF/struts.xml

    代码

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

    <struts-config>
    <data-sources />
    <form-beans>
    <form-bean name="loginForm"
    type="com.qdu.sun.struts.form.LoginForm" />

    </form-beans>

    <global-exceptions />
    <global-forwards />
    <action-mappings>
    <action attribute="loginForm" input="/login.jsp"
    name="loginForm" path="/login" scope="request"
    type="org.springframework.web.struts.DelegatingActionProxy">
    <forward name="success" path="/success.jsp" />
    <forward name="fail" path="/fail.jsp" />
    </action>

    </action-mappings>

    <message-resources
    parameter="com.qdu.sun.struts.ApplicationResources" />
    <plug-in
    className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation"
    value="/WEB-INF/classes/applicationContext.xml" />
    </plug-in>

    </struts-config>

  • 相关阅读:
    vue 项目中assets文件夹与static文件夹引用的区别
    v-on绑定特性命名带小横杠 ‘-’与props属性中变量怎么对应
    解决 The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
    解决win10无法完成更新 正在撤销更改
    Felix HttpServer call iPojo Demo
    Felix Http server Demo
    osgi学习
    windows一个目录下最大文件数目
    oracle默认配置ora文件位置
    iptables配置(/etc/sysconfig/iptables)
  • 原文地址:https://www.cnblogs.com/iOS-mt/p/6023135.html
Copyright © 2011-2022 走看看