SSH框架的整合

1、Struts+spring的整合
 ·web.xml中
  ·加载的spring配置文件
   ·<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/applicationContext*.xml /  classpath*:applicationContext*.xml
    </param-value>
    </context-param>
  ·容器启动时加载
   ·<listener>
    <listener-class>
     org.springframework.web.context.ContextLoaderListener
    </listener-class>
    </listener>
 ·struts-config.xml
    ·<action path="/test/ssh" type="org.springframework.web.struts.DelegatingActionProxy" parameter="command" ../>
   ·parameter="command" 是因为使用了DispatchAction
 ·contextApplication.xml
  ·<bean name="/test/ssh" class="org.kker.drp.sysmgr.struts.items.ItemAction" >
   <property name="itemManager">
    <ref bean="itemManager"/>
   </property>
    </bean>
*************************************************************************************************************
2、Hibernate+Spring的整合
 ·web.xml中
  ·加载spring配置文件 (如上)
  ·创建过滤器:
   ·<filter>
    <filter-name>hibernateFilter</filter-name>
     <filter-class>
      org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
     </filter-class>
   </filter>

 ·contextApplication.xml(事务)
  ·引入spring-tx-2.0.xsd、spring-aop-2.0.xsd
  *DI
  *声明事务
  ·<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="configLocation">
    <value>classpath:hibernate.cfg.xml</value>
   </property>
   </bean>
  *事务管理器
  ·<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref bean="sessionFactory"/>
   </property>
    </bean>
  *配置事务的传播特性
  ·<tx:advice id="txAdvice" transaction-manager="transactionManager">
   <tx:attributes>
    <tx:method name="add*" propagation="REQUIRED"/>
    <tx:method name="*" read-only="true"/>
   </tx:attributes>
    </tx:advice>
  *配置AOP
  ·<aop:config>
   <aop:pointcut id="managerMethod" expression="execution(* org.kker.drp.basedate.hibernate.*.*(..))"/>
   <aop:advisor advice-ref="txAdvice" pointcut-ref="managerMethod"/>
    </aop:config>

  *添加业务逻辑操作
  ·<bean id="userManagerDao" class="org.kker.user.UserManager">
   <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
  ■:public class UserManager extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
  ·具体使用:
   ·this.getHibernateTemplate().save(user);
   ·特定sql语句
    @List list = this.getHibernateTemplate().executeFind()(new HibernateCallback(){
    public Object doInHibernate(Session session)throw HibernateException,SQLException{
     return (session.createQuery("from User u order by u.id").list());
    }
       });

·Other
 ·spring 的过滤器
  ·<filter>
   <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
   <filter-name>Spring Character Encoding</filter-name>
   <init-param>
    <param-name>encoding</param-name>
    <param-value>gb18030</param-value>
   </init-param>
    </filter>
  ·<filter-mapping>
   <filter-name>Spring Character Encoding</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值