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

📄 customersaveaction.java

📁 由于跟踪客户的购物意向
💻 JAVA
字号:
package com.relationinfo.customertrace.struts.actions;

import org.apache.struts.*;
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.*;
import java.math.*;
import com.relationinfo.customertrace.dao.*;
import com.relationinfo.customertrace.dto.*;
import com.relationinfo.customertrace.factory.*;
import com.relationinfo.customertrace.struts.forms.*;

public class CustomerSaveAction extends Action
{
	/**
	 * Method 'execute'
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @throws Exception
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		try {
			// cast the form to the appropriate type
			CustomerForm customerForm = (CustomerForm) form;
		
			//创建Dao类
			CustomerDao dao = CustomerDaoFactory.create();
		
			Customer dto = new Customer();
			dto.setCustomercode( customerForm.getCustomercode());
			dto.setCustomertypecode( customerForm.getCustomertypecode());
			dto.setCustomername( customerForm.getCustomername());
			dto.setAddress( customerForm.getAddress());
			dto.setPhone( customerForm.getPhone());
			dto.setMobile( customerForm.getMobile());
			dto.setEmail( customerForm.getEmail());
			dto.setBirthday( customerForm.getBirthday() == null ? null : DateFormat.getDateInstance().parse( customerForm.getBirthday()));
			dto.setHobby( customerForm.getHobby());
			dto.setNote( customerForm.getNote());
		
			if (customerForm.getCrudMethod().equalsIgnoreCase("insert")) {
				dao.insert( dto );
			} else if (customerForm.getCrudMethod().equalsIgnoreCase("update")) {
				dao.update( dto.createPk(), dto );
			} else if (customerForm.getCrudMethod().equalsIgnoreCase("delete")) {
				dao.delete( dto.createPk() );
			}
		
			return mapping.findForward( "success" );
		}
		catch (Exception e) {
			ActionErrors _errors = new ActionErrors();
			_errors.add( ActionErrors.GLOBAL_MESSAGE, new ActionMessage("internal.error", e.getClass().getName() + ": " + e.getMessage() ) );
			saveErrors( request, _errors );
			return mapping.findForward( "failure" );
		}
		
	}

}

⌨️ 快捷键说明

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