ssh整合步骤之一 搭建环境

               

ssh整合主要可以分为3个步骤:搭建环境、设计架构、实现逻辑

以下是搭建环境的步骤

1、导入jar包

      导入ssh基本jar包

2、导入ssh配置文件。

      包括(struts.xml   hibernate.cfg.xml   `````.hbm.xml    applicationContext.xml   jdbc/properties)

3、整合strut与spring

     1)web.xml

      在web.xml中加上以下代码

    

<context-param>  <param-name>contextConfigLocation</param-name>  <param-value>classpath:applicationContext.xml</param-value></context-param><listener>  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>   <!-- 配置Spring的用于解决懒加载问题的过滤器 --> <filter>  <filter-name>OpenSessionInViewFilter</filter-name>  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping>  <filter-name>OpenSessionInViewFilter</filter-name>  <url-pattern>*.action</url-pattern> </filter-mapping>  

4、整合spring与hibernate

   1)在applicationContext.xml中加上以下代码:

   

<context:component-scan base-package="com.njupt"></context:component-scan>                <context:property-placeholder location="classpath:jdbc.properties" />                <bean id="sessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  <!-- 指定hibernate的配置文件位置 -->  <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>  <!-- 配置c3p0数据库连接池 -->  <property name="dataSource">   <bean class="com.mchange.v2.c3p0.ComboPooledDataSource">    <!-- 数据连接信息 -->    <property name="jdbcUrl" value="${jdbcUrl}"></property>    <property name="driverClass" value="${driverClass}"></property>    <property name="user" value="${user}"></property>    <property name="password" value="${password}"></property>    <!-- 其他配置 -->    <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->    <property name="initialPoolSize" value="3"></property>    <!--连接池中保留的最小连接数。Default: 3 -->    <property name="minPoolSize" value="3"></property>    <!--连接池中保留的最大连接数。Default: 15 -->    <property name="maxPoolSize" value="5"></property>    <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->    <property name="acquireIncrement" value="3"></property>    <!--     控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default:     0    -->    <property name="maxStatements" value="8"></property>    <!--     maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0    -->    <property name="maxStatementsPerConnection" value="5"></property>    <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->    <property name="maxIdleTime" value="1800"></property>   </bean>  </property> </bean>   <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="txManager"/>  

到这里ssh就整合完了,以下是一些方便使用的功能:

1)hibernate.cfg.xml中贴上

<property name="hbm2ddl.auto">update</property> 
以上代码完成自动建表功能

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/sfhinsc/article/details/86572051