ssh框架整合

Ssh 框架的整合

1、导入 ssh的 jar

2、Spring整合 hibernate

3、对应数据库表的java bean po 和 映射文件

4、配置hibernate和兴配置信息 hibernate.cfg.xml

5、使用spring 加载hibernate 配置信息

6、加载hibernate核心配置文件,直接配置hibernate的配置信息

7、把得到的sessionfactory 注入到 Dao,把 dao 注入 service

8、Spring 封装 hibernate 

1)加载配置信息

2)封装了一个 hibernateTemplatedao

9、在 web.xml 中配置 struts2 核心控制器。

10、Action

11、Struts.xml 配置文件

12、Struts action 交给 spring 来管理。 Action标签中所需要的action直接向 spring

13、Web.xml 加载spring核心配置文件。配置spring监听器。

 

练习配置

 

第一种配置方式:

要求:

1、导入jar包。【用于整合的】

2、创建UserPo对象【UserPo.java

3、创建对应的映射文件【UserPo.hbm.xml

4、创建hibernate文件。【hibernate.cfg.xml

5、

练习ssh的整合:

——整合 hibernate 部分。

1、导入jar

2、创建 UserPo.java 以及对应的 UserPo.hbm.xml

3、创建beans.xml  里面需要一个 数据源 datasource 以及对应的 sessionfactory 这里面主要是 一些关于hibernate的一些属性。

4、创建框架中的应有内容 包括 service serviceimpl dao daoimpl

5、创建test 部分 利用 applicationContext 来并得到对应属性。

6、在beans.xml 里面 创建 applicationContext 中需要 生成的 userService 和 userDao

 

——整合 struts 部分

1web.xml的配置

1) 创建自启 文件,这样就不用 书写 applicationContext

2) 创建监听器

3) 核心配置文件

 

2、创建界面  login.jsp

 

3、写对应的 action 

 

4、配置 beans.xml文件

 

5、配置 struts.xml 文件

5、

 

  <!-- 对于这个 web.xml 需要配置三个 内容, 

  

  1、服务器启动时候的加载

  2、spring的监听

  3、核心控制器 -->

  

  <!-- 原来是 通过 硬编码的方式在 test里面采用ApplicationContext applicationContext= new ClassPathXmlApplicationContext("beans.xml");配置的。

   现在一旦启动了tomcat服务器就会在 程序中对这样一个 beans.xml文件进行解读。

   -->

  <context-param>

   <param-name>contextConfigLocation</param-name>

   <!-- 下面这个,经华哥讲解,终于理解了,当我们发布到tomcat服务器以后,这个东西会经过编译,不再存在src目录了。都会转到WEB-INF这个目录下面。

   所以,每次 我们每个人独立编译以后,总会有文件跟服务器端里面存在的 svn的版本不一致,这就是这个原因了。然而当我们查找相关文件的时候,也是要到这个里面寻找。

    -->

   <param-value>/WEB-INF/classes/beans.xml</param-value>

  </context-param>

  <!-- spring的监听器,如果有一个请求【关于action的】 spring的ioc容器 就会为我们找到一个 对应的action对象 -->

  <listener>

   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

  </listener>

  

  

  <!-- 配置核心控制器 -->

  <filter>

   <filter-name>struts2</filter-name>

   <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

  </filter>

  <filter-mapping>

   <filter-name>struts2</filter-name>

   <url-pattern>/*</url-pattern>

  </filter-mapping>

  

 

 

原文地址:https://www.cnblogs.com/letben/p/5185923.html