?? addcustomeraction.java
字號:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import struts.form.AddCustomerForm;
import po.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import business.IOperator;
/**
* 功能:增加客戶
* 作者:趙昌峻
* Creation date: 11-02-2006
*
* XDoclet definition:
* @struts.action path="/addCustomer" name="addCustomerForm" input="/web/newCustomer1.jsp" scope="request" validate="true"
* @struts.action-forward name="success" path="/web/newUser.jsp"
*/
public class AddCustomerAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
AddCustomerForm addCustomerForm = (AddCustomerForm) form;// TODO Auto-generated method stub
HttpSession session=request.getSession();
//通過收集從頁面傳過來的form表單構造客戶對象
Tcustomer customer=new Tcustomer();
customer.setCustomerAddress(addCustomerForm.getCustomerAddress());
customer.setCustomerBirtyday(addCustomerForm.getCustomerBirtyday());
customer.setCustomerName(addCustomerForm.getCustomerName());
customer.setCustomerSex(addCustomerForm.getCustomerSex());
customer.setIdNumber(addCustomerForm.getIdNumber());
customer.setIdType(addCustomerForm.getIdType());
/*這個地方是用spring的關鍵所在
* 通過FileSystemXmlApplicationContext類得到spring配置文件
* 通過ApplicationContext得到應用程序上下文context.
* 用getBean(類對象名)方法即可得到"具體干活的類"
* 直接用接口類就可以調用相關方法.
*/
ApplicationContext context=new FileSystemXmlApplicationContext("C:\\eclipse\\workspace\\chinamobile\\src\\applicationContext.xml");
IOperator dooperator=(IOperator)context.getBean("operatorservice");
// 調用業務層方法判斷客戶是否存在
Tcustomer mycustomer=dooperator.isCustomerExist(customer);
if(mycustomer==null){
//如果客戶不存在,調用業務層方法增加客戶.
mycustomer = dooperator.addCustomer(customer);//直接調用實現了Tcustomer類的子類的方法處理業務(增加客戶)
if(mycustomer!=null){
//將客戶信息寫入session
session.setAttribute("customer", mycustomer);
return mapping.findForward("success");
}else{
request.setAttribute("message", "操作失敗!請重試!");
return mapping.findForward("false");
}
}else{
// 將客戶信息寫入session
session.setAttribute("customer", mycustomer);
return mapping.findForward("success");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -