如何搭建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>标签,将标签的属性修改成:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">


接着,再添加以下内容:

 

        <!--声明一个事务管理器  --> 
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
	    <property name="sessionFactory">
		    <ref local="sessionFactory" />
	    </property>
	</bean>
	
	<!-- 声明一个事务通知 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
	    <tx:attributes>
	       <tx:method name="*" propagation="REQUIRED"/>
	    </tx:attributes>
	</tx:advice>
	
	<!-- 声明一个AOP切入点 -->
	<aop:config>
	   <aop:pointcut id="daoMethods" expression="execution(* edu.dao.impl.*.*(..))" />
	   <aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods"/>
	</aop:config>


 

 

 

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值