SSH框架分模块开发

------------------siwuxie095

  

  

  

  

  

  

  

  

SSH 框架分模块开发

  

  

1、在Spring 核心配置文件中配置多个内容,容易造成

配置混乱,不利于维护

  

分模块开发主要针对Spring 核心配置文件

  

  

  

2、把Spring 核心配置文件中的一部分配置放到单独

配置文件中,再在Spring 核心配置文件中引入单独的配

置文件即可

  

  

  

3、一般情况下,建议把Action 对象的配置放到单独的

配置文件中

  

「因为其它的配置基本不变,只有Action 对象的配置在

不断重复」

  

如:

  

user.xml:

  

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd">

 

  

<!--配置 Action对象 -->

<beanid="userAction"class="com.siwuxie095.action.UserAction" scope="prototype">

<propertyname="userService"ref="userService"></property>

</bean>

 

<!--配置 Service对象 -->

<beanid="userService"class="com.siwuxie095.service.UserService">

<propertyname="userDao"ref="userDaoImpl"></property>

</bean>

 

<!--配置 Dao实现类对象 -->

<beanid="userDaoImpl"class="com.siwuxie095.dao.impl.UserDaoImpl">

<propertyname="hibernateTemplate"ref="hibernateTemplate"></property>

</bean>

 

<!--配置 HibernateTemplate对象 -->

<beanid="hibernateTemplate"class="org.springframework.orm.hibernate5.HibernateTemplate">

<!--注入 SessionFactory对象 -->

<propertyname="sessionFactory"ref="sessionFactory"></property>

</bean>

 

<!--

关于 HibernateTemplate对象的配置,其实也可以放在核心配置文件中,

因为它也是基本不变的

 

其实关于分模块开发,把任何一部分拿出去放到单独的配置文件中都可以,

只是建议把 Action 对象的配置放到单独的配置文件中,因为只有 Action

对象的配置是不断重复的,而其它的配置却是基本不变的

-->

 

 

</beans>

  

  

  

applicationContext.xml 中引入 user.xml:

  

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd">

 

 

<!-- (1) -->

<!--配置 C3P0连接池 -->

<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">

<propertyname="driverClass"value="com.mysql.jdbc.Driver"/>

<!--

jdbc:mysql:///test_db jdbc:mysql://localhost:3306/test_db的简写

-->

<propertyname="jdbcUrl"value="jdbc:mysql:///test_db"/>

<propertyname="user"value="root"/>

<propertyname="password"value="8888"/>

</bean>

 

 

<!-- SessionFactory对象的创建交给 Spring进行管理 -->

<beanid="sessionFactory"

class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">

<!--

数据库配置原本是在 Hibernate 核心配置文件中配置的,

现在 Hibernate核心配置文件不存在了,所以在这里注

dataSource

 

LocalSessionFactoryBean中有相关属性,所以可以

注入

-->

<propertyname="dataSource"ref="dataSource"></property>

<!--配置 Hibernate基本信息 -->

<propertyname="hibernateProperties">

<props>

<propkey="hibernate.show_sql">true</prop>

<propkey="hibernate.format_sql">true</prop>

<propkey="hibernate.hbm2ddl.auto">update</prop>

<propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

<!--

原来的配置:

<prop key="hibernate.current_session_context_class">thread</prop>

 

SSH框架整合中会报错,要么将这个配置删了,要么改成如下配置

 

参考链接:http://blog.csdn.net/maoyuanming0806/article/details/61417995

-->

<propkey="hibernate.current_session_context_class">

org.springframework.orm.hibernate5.SpringSessionContext

</prop>

</props>

</property>

<!--引入映射配置文件 -->

<propertyname="mappingResources">

<list>

<value>com/siwuxie095/entity/User.hbm.xml</value>

<!-- <value>....</value> -->

</list>

</property>

</bean>

 

 

 

<!-- (2) -->

<!--

引入 src下的 user.xml配置文件

 

其实 classpath可以省略不写,即:

<import resource="user.xml"/>

 

建议写上

-->

<importresource="classpath:user.xml"/>

 

 

 

<!-- (3) -->

<!--配置事务管理器 HibernateTransactionManager -->

<beanid="transactionManager"

class="org.springframework.orm.hibernate5.HibernateTransactionManager">

<!--注入 SessionFactory 对象 -->

<propertyname="sessionFactory"ref="sessionFactory"></property>

</bean>

 

<!--开启事务注解 -->

<tx:annotation-driventransaction-manager="transactionManager"/>

 

 

</beans>

  

  

  

引入部分如下:

  

  

  

  

  

  

  

  

  

  

  

【made by siwuxie095】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SSH框架是指Struts+Spring+Hibernate的集成框架,主要用于快速搭建Web应用程序。它将应用程序为表示层、业务逻辑层、数据持久层和域模块层,以实现结构清晰、可复用、易于维护的Web应用程序。其中,Struts负责MVC离,控制业务跳转;Hibernate提供持久层支持;Spring作为管理框架,管理Struts和Hibernate之间的关系。 而SSM框架指的是Spring+SpringMVC+MyBatis的集成框架。它是由Spring和MyBatis两个开源框架整合而成,通常用于数据源较简单的Web项目。在SSM框架中,SpringMVC是Spring的一部,负责处理MVC的离,而MyBatis则是用于提供持久层支持的框架。 另外还有Struts框架,它与SSH框架类似也是一种开源框架。它使用Servlet和JSP实现,并且基于MVC模型。Struts框架的核心组件包括Action、ActionServlet以及视图部由多个相互关联的JSP文件组成。它可以有效地减少基于MVC模型的Web应用系统的开发时间,从而控制系统开发成本。 所以,SSH框架和SSM框架都是用于快速开发Web应用程序的集成框架,而SSH框架使用的是Struts+Spring+Hibernate,而SSM框架使用的是Spring+SpringMVC+MyBatis。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [简述SSM框架SSH框架](https://blog.csdn.net/m0_37876935/article/details/93891639)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值