SSH專案整合-簡單線上訂單系統
阿新 • • 發佈:2019-01-23
專案介紹
專案後臺開發基於struts2-2.5.12,spring-4.3.10,hibernate-4.3.11,頁面框架使用jQuery EasyUI 1.3.2,實現了一個簡單線上訂單系統,提供提交訂單,查詢訂單,新增訂單,修改訂單等功能。
專案截圖:
專案下載:
核心Spring配置檔案:
applicationContext.xml
<context:component-scan base-package="com.cheng"/>
<context:annotation-config/>
<context:property-placeholder location="classpath:mysqldb.properties"/>
<!--配置C3P0資料來源-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxPoolSize" value="20"/>
<property name="minPoolSize" value="5"/>
<property name="loginTimeout" value="120"/>
<property name="maxStatements" value="100"/>
<!--初始化時獲取幾個連線-->
<property name="acquireIncrement" value="1"/>
<!--隔一定時間間隔去自動校驗連線物件是否失效,失效銷燬-->
<property name="testConnectionOnCheckout" value="true"/>
<property name="idleConnectionTestPeriod" value="120"/>
</bean>
<!--配置sessionFactory-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
</props>
</property>
<!-- 適用於Hibernate4 -->
<property name="packagesToScan" value="com.cheng.pojo"/>
</bean>
<!--配置宣告事務管理-->
<!--註解採用@Transactional-->
<bean id="transactionManger" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManger"/>
Hibernate開啟事務:
//注入SessionFactory
@Resource
private SessionFactory sessionFactory;
//註解開啟事務
@Transactional
public int addGoods(Goods goods) {
Session session = sessionFactory.getCurrentSession();
Serializable save = session.save(goods);
return save != null ? (int) save : -1;
}
整合Struts:
匯入struts2-spring-plugin-2.5.12.jar
@Controller
//Struts2的Action是多例的
@Scope("prototype")
public class GoodsAction extends ActionSupport {
@Resource
private GoodsService goodsService;
}