ssh整合主要可以分為3個步驟:搭建環境、設計架構、實現邏輯
以下是搭建環境的步驟
1、導入jar包
ssh配置文件? 導入ssh基本jar包
2、導入ssh配置文件。
包括(struts.xml hibernate.cfg.xml `````.hbm.xml applicationContext.xml jdbc/properties)
3、整合strut與spring
什么是ssh? 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>
ssh linux?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架構。到這里ssh就整合完了,以下是一些方便使用的功能:
1)hibernate.cfg.xml中貼上
<property name="hbm2ddl.auto">update</property>
以上代碼完成自動建表功能
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态