如何搭建SSH框架,myeclipse搭建SSH框架详解

1、先新建个Web项目

2 、添加struts2依赖包和配置文件

右击工程,选择“myeclipse”在二级菜单中找到“Add Struts Capabiliies” 点击进入

 

 

 

3、添加spring框架依赖包和配置文件

右击工程,选择“myeclipse”在二级菜单中找到“Add Spring Capabiliies” 点击进入

 

 

 

 

 

4、 新建“mysql-test”数据库连接

首先,打开“MyEclipse  Database  Explorer”视图,步骤:工具栏“Widow” ——》“Open  Perspective”——》“Other”——》“MyEclipse  Database  Explorer” ——“OK”

 

 

 

 

接着,在Myeclipse右上角找到切换视图的图标,切换到“MyEclipse  Database  Explorer”视图,在该视图上我们可以新建数据库连接,如下图

5、添加Hibernate框架依赖包和配置文件

右击工程,选择“myeclipse”在二级菜单中找到“Add Hibernate Capabiliies” 点击进入

 

 

 

 

 

数据源选择步骤4新建的数据库连接“mysql-test”

 

 

 

6、通过“mysql-test”数据库连接,我们可以生成hibernate实体类和映射文件,以users表为例,如下图

 

 

 

 

 

 

效果如下图:

 

 

 

7、添加Spring事务管理

首先,修改applicationContext.xml文件,修改<beans>标签,将标签的属性修改成:

[plain]  view plain  copy
  1. <beans xmlns="http://www.springframework.org/schema/beans"  
  2.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns:aop="http://www.springframework.org/schema/aop"  
  4.     xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans   
  6.     http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
  7.     http://www.springframework.org/schema/tx  
  8.     http://www.springframework.org/schema/tx/spring-tx-2.0.xsd  
  9.     http://www.springframework.org/schema/aop  
  10.     http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">  


接着,再添加以下内容:

 

[plain]  view plain  copy
  1.        <!--声明一个事务管理器  -->   
  2. <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  3.     <property name="sessionFactory">  
  4.         <ref local="sessionFactory" />  
  5.     </property>  
  6. </bean>  
  7.   
  8. <!-- 声明一个事务通知 -->  
  9. <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  10.     <tx:attributes>  
  11.        <tx:method name="*" propagation="REQUIRED"/>  
  12.     </tx:attributes>  
  13. </tx:advice>  
  14.   
  15. <!-- 声明一个AOP切入点 -->  
  16. <aop:config>  
  17.    <aop:pointcut id="daoMethods" expression="execution(* edu.dao.impl.*.*(..))" />  
  18.    <aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods"/>  
  19. </aop:config>  

转自:https://blog.csdn.net/yh_zeng2/article/details/72927049

猜你喜欢

转载自blog.csdn.net/qq_39657909/article/details/80738229