📄 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 + -