ssh 标准整合(除去jpa注解)

  1准备好包

        这里面有准备好的包:  http://download.csdn.net/detail/heavenandhell/8657403 ssh版本:struts2 hibernate4 spring4

  2配置web文件

   <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>
  
  <!-- 配置web服务监听类 -->
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <!-- 配置Spring核心配置文件路径-->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>
  		/WEB-INF/applicationContext.xml 
  	 </param-value>
  </context-param>

  3配置applicationContext.xml 文件

         里面需要spring 的bengs,context,tx,aop
 <context:annotation-config />
    <context:component-scan base-package="*" />
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
       <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
       <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
       <property name="username" value="scott"></property>
       <property name="password" value="123456"></property>
       <property name="maxActive" value="80"></property>  
       <property name="maxIdle" value="20"></property>  
       <property name="maxWait" value="3000"></property>
	</bean>
	
	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
	<property name="dataSource" ref="dataSource"/>
	<property name="hibernateProperties">
		<props>
			<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
			<prop key="hibernate.hbm2ddl.auto">update</prop>
			<prop key="hibernate.show_sql">true</prop>
		</props>
	</property>
	<property name="mappingResources">
		<list>
			<value>Entity/Thenten.hbm.xml</value>
		</list>
	</property>
	</bean>
	<bean id="txManager"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"/>
	</bean>
	<tx:advice id="txAdvice" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="*" read-only="false" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<aop:pointcut id="txService" expression="execution(* com.ssh.service..*.*(..))" />
		<aop:advisor pointcut-ref="txService" advice-ref="txAdvice" />
	</aop:config>

   4 写好:业务层 控制层 数据層 实体类 


   5各层需要的注解

           控制层: HibernateUtil类:在类名上注解为: @Component  在 private SessionFactory sessionFactory 上注解为:@Resource
                           Dao接口 不用写注解 只需要这个接口
                            DaoImp  Dao的实现类:需要的注解 有 在类名头上注解@Repository("dao") 
                             DaoImp 实现类 不仅实现了Dao接口也继承了 HibernateUtil 类 提供getSession();
                      
                          
             
          业务层:Servelt 接口 不用写注解 只需写这个接口 
                            ServeltImp Servelt 的实现类 :需要在类名上标注为@Service("ser")   定义Dao接口  private Dao dao; 注解为: @Resource(name="dao");
                           
                           Action类为struts的Action 需要标注的是类这个Action类:@Controller("Action")   @Scope("prototype")   定义Servelt接口:标注为@Resource(name="ser")
            
         
              实体类就是配置 hibernate 配置文件    Entity/Thenten.hbm.xml 这个文件  一般这个文件不容易出错 
               
             ssh 基本配置已经完成
          
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值