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

📄 businessaddaction.java

📁 这个是完整的wap项目的源码 开发语言 Java 系统架构 Struts + hibernate + spring 数据库 Mysql5.0 应用服务器Tomcat5.0 开发工具 MyEc
💻 JAVA
字号:
package com.longtime.wap.module.business.web.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;
import org.springframework.web.struts.DispatchActionSupport;

import com.longtime.wap.common.WapConstant;
import com.longtime.wap.model.Business;
import com.longtime.wap.model.Cp;
import com.longtime.wap.module.business.service.BusinessService;
import com.longtime.wap.module.business.web.form.BusinessEditForm;

/**
 * 处理列表页请求
 * 
 * @author gengb
 * @date Nov 19, 2007
 */
public class BusinessAddAction extends DispatchActionSupport {
	private static final Log LOGGER = 
		LogFactory.getLog(BusinessAddAction.class);
	private BusinessService businessService = null;

	/**
	 * 注入服务对象
	 * 
	 * @param businessService
	 *            服务对象
	 */
	public void setBusinessService(BusinessService businessService) {
		this.businessService = businessService;
	}

	/**
	 * 获取单位信息
	 * 
	 * @param mapping
	 *            ActionMapping对象
	 * @param form
	 *            ActionForm对象
	 * @param request
	 *            HttpServletRequest对象
	 * @param response
	 *            HttpServletResponse对象
	 * @return ActionForward对象
	 */
	@SuppressWarnings("finally")
	public ActionForward getCp(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		List<String> message = new ArrayList<String>();
		try {
			initDownList(request);
		} catch (Exception e) {
			LOGGER.error(e);
			message.add("获取cp列表失败!");
		} finally {
			if (request.getAttribute(WapConstant.WAP_GLOBAL_MESSAGES) 
					!= null) {
				request.removeAttribute(WapConstant.WAP_GLOBAL_MESSAGES);
			}
			request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES, message);
			return mapping.findForward("detailBusiness");
		}

	}

	/**
	 * 初始化下拉列表
	 * 
	 * @param request
	 *           HttpServletRequest对象
	 */
	protected void initDownList(HttpServletRequest request) {
		List<String> message = new ArrayList<String>();
		List<LabelValueBean> returnCpList = new ArrayList<LabelValueBean>();
		try {
			returnCpList.add(new LabelValueBean("---请选择---", ""));
			List cpList = (List) businessService.getCps();
			for (int i = 0; i < cpList.size(); i++) {
				Cp cp = (Cp) cpList.get(i);
				returnCpList.add(new LabelValueBean(cp.getCompanyName(), String
						.valueOf(cp.getCpId())));
			}
			request.setAttribute("cplist", returnCpList);
		} catch (Exception e) {
			LOGGER.error(e);
			message.add("获取cp列表失败!");

		}
	}

	/**
	 * 保存业务
	 * 
	 * @param mapping
	 *            ActionMapping对象
	 * @param form
	 *            ActionForm对象
	 * @param request
	 *            HttpServletRequest对象
	 * @param response
	 *            HttpServletResponse对象
	 * @return ActionForward对象
	 */
	@SuppressWarnings("finally")
	public ActionForward saveBusiness(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		BusinessEditForm bef = (BusinessEditForm) form;
		Business business = new Business();
		List<String> message = new ArrayList<String>();
		String businessName = bef.getBusinessName().trim();
		String forward = "listBusiness";
		try {
			if(businessName.equals("")) {
				message.add("业务名称为空!");
				forward = "init";
			} else {
				if (null != (Business) businessService
						.getBusinessByName(businessName)) {
					message.add("业务名称已存在");
					forward = "init";
				} else {
					business.setBusinessName(businessName);
					business.setCategory(Integer.parseInt(bef.getCategory()));
					business.setDuration(999);
					business.setPubDate(new Date());
					if (!bef.getCpId().equals("")) {
						Cp cp = businessService.getCpByCpId(Long.parseLong(bef
								.getCpId()));
						business.setCp(cp);
						businessService.saveBusiness(business);
						message.add("业务信息添加成功!");
					} else {
						message.add("您没有选择业务所属单位或者" 
								+ "您选择的单位可能已被删除");
					}
				}
			}

		} catch (Exception e) {
			LOGGER.error(e);
			message.add("业务信息保存失败!");
		} finally {
			if (request.getAttribute(WapConstant.WAP_GLOBAL_MESSAGES) 
					!= null) {
				request.removeAttribute(WapConstant.WAP_GLOBAL_MESSAGES);
			}

			request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES, message);
			return mapping.findForward(forward);
		}

	}

	/**
	 * 初始化
	 * 
	 * @param mapping
	 *            ActionMapping对象
	 * @param form
	 *            ActionForm对象
	 * @param request
	 *            HttpServletRequest对象
	 * @param response
	 *            HttpServletResponse对象
	 * @return ActionForward对象
	 */
	public ActionForward init(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		initDownList(request);
		return mapping.findForward("detailBusiness");
	}
}

⌨️ 快捷键说明

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