常见的框架整合

一、spring+struts:

1、导入入struts+spring整合需要的jar文件(struts2-spring-plugin-2.3.1.2)

2、配置web.xml
<!-- 配置struts -->
  <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>


  <!-- 配置spring,如果在web-inf下可以只要listener-->
  <context-param>
<param-name>contextConfigLocation</param-name><!-- contextConfigLocation 名不能改变化 -->
  <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

3、配置struts文件
<action name="user_*" class="userAction" method="{1}"> //即为struts的action前加上注解


二、spring+struts+hibernate:

1.在web.xml中通过ContextLoaderListener来融入spring,并加载spring的相关配置文件  


2.配置sturts2的前端总控制器filterDispatcher来过滤相关的请求并且加载struts.xml  

  
3.action继承ActionSupport,然后通过引入struts-spring-plugin.jar包并且根据配置文件中service的id生成get,set方法来注入service层。
    
4.dao层继承于HibernateDaoSupport,并且在dao的配置文件中注入sessionFactory.也可直接使用HibernateTemplate


5.spring中的配置文件加载hibernate.cfg.xml文件从而融入hibernate.


<listener>  
    <description>Spring core configuration</description>  
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  </listener> 
  <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>



三、spring+spring mvc+mybatis:

1、导入框架所需的jar包


2、配置web.xml--->加入spring、spring mvc和解决乱 码的配置文件


3、配置spring-->applicationContext.xml
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage"> 
<value>com.hy.mapperdao</value>
</property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- spring配置事务 基于注解开发 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 纯注解方式,只需要所需类前加上 @Transactional -->
<tx:annotation-driven transaction-manager="transactionManager" />


4、开发entity-->dao接口-->mapper.xml(要求id的名和接口中的方法名一致),不需要开发实现接口

















































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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值