短學期SSH項目雜談
ssh工程下的子文件:
其中,application類中的代碼如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!--數據庫-配置數據連接池 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306ssh">
</property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
<property name="maxActive" value="100"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<!--sessionFactory配置與管理 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/crm/bean/Cust.hbm.xml<alue>
<st>
</property>
</bean>
<!--配置DAO -->
<bean id="custDao" class="com.crm.impl.CustDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 配置service -->
<bean id="custService" class="com.crm.service.impl.CustServiceImpl">
<property name="custDao" ref="custDao"></property>
</bean>
<!-- 配置SaveAction -->
<bean id="custSaveAction" class="com.crm.action.CustSaveAction">
<property name="service">
<ref bean="custService"/>
</property>
</bean>
<!--配置-查詢listAction -->
<bean id="listCustAction" class="com.crm.action.CustListAction">
<property name="service" ref="custService"></property>
</bean>
<!--配置-刪除deleteAction -->
<bean id="custRemoveAction" class="com.crm.action.CustRemoveAction">
<property name="service" ref="custService"></property>
</bean>
<!--配置-條件查詢findCdtAction -->
<bean id="findCustByCdtAction" class="com.crm.action.FindCustByCdtAction">
<property name="findCdtService" ref="custService"></property>
</bean>
<!--配置-修改updateCustAction -->
<bean id="updateCustAction" class="com.crm.action.UpdateCustAction">
<property name="updateCustService" ref="custService"></property>
</bean>
<!--配置-修改預覽updatePreviewCustAction -->
<bean id="updatePreviewCustAction" class="com.crm.action.UpdatePreviewCustAction">
<property name="updatePreviewCustService" ref="custService"></property>
</bean>
</beans>
用於配置各種action類,實現操作
struts類代碼如下:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd ">
<struts>
<package name="customer" extends="struts-default">
<!-- 保存 -->
<action name="saveCust" class="custSaveAction">
<result name="success" type="redirect">/jsp/custInfo.jsp</result>
</action>
<!-- 查詢 -->
<action name="listCust" class="listCustAction">
<result>/jsp/custInfo.jsp</result>
</action>
<!-- 刪除 -->
<action name="delectCust" class="custRemoveAction">
<result>/jsp/custInfo.jsp</result>
</action>
<!-- 條件查詢 -->
<action name="findCust" class="findCustByCdtAction">
<result>/jsp/custInfo.jsp</result>
</action>
<!-- 修改預覽 -->
<action name="updatePreviewCust" class="updatePreviewCustAction">
<result name="success">/jsp/updateCust.jsp</result>
</action>
<!-- 修改 -->
<action name="updateCust" class="updateCustAction">
<result name="success" type="redirect">listCustomer.action</result>
<result name="input">/jsp/updateCust.jsp</result>
</action>
</package>
</struts> 用於連接前端和後端
短學期SSH項目雜談