.#businesseditaction.java.1.8

来自「这个是完整的wap项目的源码 开发语言 Java 系统架构 Struts +」· 8 代码 · 共 110 行

8
110
字号
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.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;

public class BusinessEditAction extends DispatchActionSupport {

	private BusinessService businessService = null;
	public void setBusinessService(BusinessService businessService) {
		this.businessService = businessService;
	}

	@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) {
			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);
		}
	}


	@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").toString();
//		String reset = request.getParameter("reset");
//		if (!"yes".equals(reset)) {
//			request.getSession().setAttribute("businessId", businessId);
//		} else if ("yes".equals(reset)) {
//			businessId = request.getSession().getAttribute("businessId")
//					.toString();
//		}
		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").toString());
		} catch (Exception 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 + =
减小字号Ctrl + -
显示快捷键?