1. 程式人生 > >客戶信息維護jsp

客戶信息維護jsp

delet doc exc clas drive throws inf tsa this

搭建好SSH環境後,實現對客戶信息的操作:

applicationContext.xml

<?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:3306/dbssh">
</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</value>
</list>
</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 ="custService"></property>
</bean>

<!-- 配置-查詢ListCustAction -->
<bean id="listCustAction" class="com.crm.action.ListCustAction">
<property name="custService" ref="custService"></property>
</bean>
<!--配置-刪除deleteAction -->
<bean id="removeCustAction" class="com.crm.action.RemoveCustAction">
<property name="service" ref="custService"></property>
</bean>
<!--配置-條件查詢findCdtAction -->
<bean id="findCdtAction" class="com.crm.action.FindCustByCdtAction">
<property name="findCdtService" ref="custService"></property>
</bean>
<!--配置-typeAction -->
<bean id="typeAction" class="com.crm.action.TypeAction">
</bean>
</beans>

struts.xml

<?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="input">/custAdd.jsp</result>
</action>
<!-- 查詢 -->
<action name="listCust" class="listCustAction">
<result>/jsp/custInfo.jsp</result>
</action>
<!-- 刪除 -->
<action name="delectCust" class="removeCustAction">
<result>/jsp/custInfo.jsp</result>
</action>
<!-- typeAction下拉列表 -->
<action name="typeAction" class="typeAction">
<result></result>
</action>
<!-- 條件查詢 -->
<action name="findCdtCustList" class="findCdtAction">
<result>/jsp/custInfo.jsp</result>
</action>
</package>
</struts>

信息存儲類CustSaveAction.java

package com.crm.action;
import com.crm.bean.Cust;
import com.crm.service.CustService;
import com.opensymphony.xwork2.ActionSupport;
public class CustSaveAction extends ActionSupport{
private CustService service;
private Cust cust;
public Cust getCust() {
return cust;
}

public void setCust(Cust cust) {
this.cust = cust;
}

public CustService getService() {
return service;
}

public void setService(CustService service) {
this.service = service;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
this.service.saveCustomer(cust);
return SUCCESS;
}
}

信息刪除類RemoveCustAction.java

package com.crm.action;
import java.util.Map;
import com.crm.service.CustService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class ListCustAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private CustService custService;
public CustService getCustService() {
return custService;
}

public void setCustService(CustService custService) {
this.custService = custService;
}
@SuppressWarnings("unchecked")
@Override
public String execute() throws Exception {
Map map = (Map)ActionContext.getContext().get("request");
map.put("list", this.custService.findAllCust());
return SUCCESS;
}

}

按條件查詢FindCustByCdtAction.java

package com.crm.action;
import java.util.Map;
import com.crm.bean.Cust;
import com.crm.service.CustService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class FindCustByCdtAction extends ActionSupport{
private Cust cust;
private CustService findCdtService;
public Cust getCust() {
return cust;
}
public void setCust(Cust cust) {
this.cust = cust;
}
public CustService getFindCdtService() {
return findCdtService;
}
public void setFindCdtService(CustService findCdtService) {
this.findCdtService = findCdtService;
}
@SuppressWarnings({ "unchecked", "unchecked" })
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
Map map = (Map)ActionContext.getContext().get("request");
map.put("list", this.findCdtService.findCustByCondition(cust));
return SUCCESS;
}
}

客戶信息維護jsp