⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customeraction.java

📁 基于SSH (struts+spring+hibernate)框架设计的 CRM客户关系管理系统
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.csu.crm.customer.action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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 com.csu.crm.common.dao.original.CrmCustomerDAO;
import com.csu.crm.common.vo.CrmCustomer;
import com.csu.crm.customer.form.CustomerForm;
import com.csu.crm.util.BeanUtil;

/**
 * 
 * @author 3eCRM小组:曾东
 * @since 2007-9-30 下午04:07:30
 * @version 1.0 创建时间:2007-9-30 下午04:07:30,初始版本
 */
public class CustomerAction extends Action {
	private static final Log log = LogFactory.getLog(CustomerAction.class);
	private CrmCustomerDAO crmCustomerDAO;
	private BeanUtil beanUtil;
	/*
	 * 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) {
		CustomerForm customerForm = (CustomerForm) form;
		log.warn("进入CustomerAction类的execute方法");
		log.warn("得到customerForm表单数据");
		log.warn(customerForm.toString());
		Object obj = request.getSession().getAttribute("selectedCustomer");
		CrmCustomer crmCustomer;
		//判断提交方法是 增加  还是 修改
		if(obj == null) {
			log.warn("增加" + obj);
			//增加
			crmCustomer = beanUtil.populate(new CrmCustomer(),customerForm);
			crmCustomerDAO.save(crmCustomer);
			
			
			log.warn("提交成功");
			request.setAttribute("isSubmited","true");
			try {
				request.getRequestDispatcher("add.do?target=CrmCustomer").forward(request, response);
			} catch (ServletException e) {			
				e.printStackTrace();
			} catch (IOException e) {			
				e.printStackTrace();
			}
		} else {
			log.warn("修改");
			//修改
			crmCustomer = (CrmCustomer)request.getSession().getAttribute("selectedCustomer");
			crmCustomer = beanUtil.populate(crmCustomer,customerForm);
			crmCustomerDAO.merge(crmCustomer);
			
			
			log.warn("提交成功");
			request.setAttribute("isSubmited","true");
			try {
				request.getRequestDispatcher("update.do?target=CrmCustomer&id=" + customerForm.getCustomerId()).forward(request, response);
			} catch (ServletException e) {			
				e.printStackTrace();
			} catch (IOException e) {			
				e.printStackTrace();
			}
		}
				
		
		
		return null;
	}

	public CrmCustomerDAO getCrmCustomerDAO() {
		return crmCustomerDAO;
	}

	public void setCrmCustomerDAO(CrmCustomerDAO crmCustomerDAO) {
		this.crmCustomerDAO = crmCustomerDAO;
	}

	public BeanUtil getBeanUtil() {
		return beanUtil;
	}

	public void setBeanUtil(BeanUtil beanUtil) {
		this.beanUtil = beanUtil;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -