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

📄 businesseditaction.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.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.springframework.web.struts.DispatchActionSupport;

import com.longtime.wap.common.WapConstant;
import com.longtime.wap.model.Business;
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 BusinessEditAction extends DispatchActionSupport {
	private static final Log LOGGER = 
		LogFactory.getLog(BusinessEditAction.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 saveBusiness(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		BusinessEditForm bef = (BusinessEditForm) form;
		List<String> message = new ArrayList<String>();
		String forward = "listBusiness";
		try {

			Business business = businessService.getBusinessById(Long
					.parseLong(bef.getBusinessId()));
			String businessName = bef.getBusinessName().trim();
			if ("".equals(businessName)) {
				message.add("业务名称不能为空");
			} else {
				if (null == businessService.getBusinessByName(businessName)) {
					business.setBusinessName(businessName);
					businessService.saveBusiness(business);
					message.add("更新业务信息成功");
				} else if (businessService.getBusinessByName(businessName)
						.getBusinessId() == Long.valueOf(bef.getBusinessId())) {
					business.setBusinessName(businessName);
					businessService.saveBusiness(business);
					message.add("更新业务信息成功");
				} else {
					message.add("该业务名称已存在!");
					forward = "detailBusiness";
				}
			}
		} 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对象
	 */
	@SuppressWarnings("finally")
	public ActionForward getBusiness(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		List<String> message = new ArrayList<String>();
		String businessId = "";
		businessId = request.getParameter("businessId");
		try {
			Business business = (Business) businessService.getBusinessById(Long
					.parseLong(businessId));
			BusinessEditForm bef = (BusinessEditForm) form;
			bef.setBusinessName(business.getBusinessName());
			String category = "";
			if (business.getCategory() == 0) {
				category = "文字";
			} else if (business.getCategory() == 1) {
				category = "音乐";
			} else {
				category = "图片";
			}
			bef.setCategory(category);
			bef.setCpName(business.getCp().getCompanyName());
			bef.setBusinessId("" + business.getBusinessId());
			bef.setFlug(request.getParameter("flug"));
		} 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("detailBusiness");
		}

	}

}

⌨️ 快捷键说明

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