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

📄 addmerchantaction.java

📁 这是本人曾经在公司里用的,内部开发框架,基于struts+hibernate今天分享给大家
💻 JAVA
字号:
/**
 * 
 */
package cn.bway.myoffice.merchant.action;

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

import org.apache.struts.action.*;

import cn.bway.common.BwayException;
import cn.bway.common.BwayHibernateException;
import cn.bway.common.Util;
import cn.bway.common.WebConstant;
import cn.bway.common.action.BaseAction;
import cn.bway.myoffice.merchant.form.MerchantForm;
import cn.bway.myoffice.merchant.impl.MerchantManagerFactory;
import cn.bway.myoffice.merchant.model.Merchant;

/**
 * @author Kson
 *
 */
public class AddMerchantAction extends BaseAction {
	
	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws BwayException 
	 * @throws Exception
	 */
	
	public ActionForward execute(ActionMapping mapping,
				ActionForm form,HttpServletRequest request,	HttpServletResponse response)
				throws BwayHibernateException, BwayException {
		
		MerchantForm pForm = (MerchantForm) form;
		ActionErrors errors = new ActionErrors();
		String returnStr = WebConstant.FORWARD_SUCCESS;
		
		//处理get请求����get����
		if(request.getMethod().equals("GET")){
			request.setAttribute(WebConstant.PAGE_Object, pForm);
			returnStr = WebConstant.FORWARD_INITPAGE;
			return mapping.findForward(returnStr);
		}
		
		try {
			saveObject(pForm);
			
			returnStr=WebConstant.FORWARD_SUCCESS;
			request.setAttribute(WebConstant.RETURN_Message,"添加成功!");
		} catch (BwayHibernateException e) {
			returnStr=WebConstant.FORWARD_FAIL;
			errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("edu.system.excption",e.getMessage()));
			this.saveErrors(request,errors);
			e.printStackTrace();
		}
		return mapping.findForward(returnStr);
	}

	/**
	 * 构建VO,保存对象�������
	 * @throws BwayHibernateException 
	 * @throws BwayException 
	 */
	private void saveObject(MerchantForm form) throws BwayHibernateException, BwayException{
		//得到父类型对象�õ������Ͷ���
		Merchant pvo=new Merchant();
		try{
			
			pvo.setStaffid(form.getStaffid());
			pvo.setStaffname(form.getStaffname());

			pvo.setMername(form.getMername());
			pvo.setMercode(form.getMercode());
			pvo.setSimplename(form.getSimplename());
			pvo.setTel(form.getTel());
			pvo.setFax(form.getFax());
			pvo.setWeburl(form.getWeburl());
			pvo.setEmail(form.getEmail());
			pvo.setArea(form.getArea());
			pvo.setPostcode(form.getPostcode());
			pvo.setAddr(form.getAddr());
			pvo.setRemark(form.getRemark());

			pvo.setAccount(form.getBankaccount());
			pvo.setBankaccount(form.getBankaccount());
			
			pvo.setAdddate(Util.fotmatDate3(new java.util.Date()));
			
			MerchantManagerFactory.getMerchantManager().addMerchant(pvo);
			
		}catch(Exception e){
			e.printStackTrace();
			throw new BwayException (e);
		}
	}
	
}

⌨️ 快捷键说明

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