📄 categoryaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.yuanchung.sales.struts.service.action;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.beans.BeanUtils;
import com.yuanchung.sales.exception.ApplicationException;
import com.yuanchung.sales.model.service.Category;
import com.yuanchung.sales.service.service.CategoryMgr;
import com.yuanchung.sales.struts.service.form.CategoryForm;
import com.yuanchung.sales.util.Constants;
/**
* MyEclipse Struts Creation date: 12-04-2008
*
* XDoclet definition:
*
* @struts.action path="/category" name="categoryForm" parameter="method"
* scope="request"
*/
public class CategoryAction extends DispatchAction {
private static Logger logger = Logger.getLogger(CategoryAction.class);
private CategoryMgr categoryMgr;
public CategoryMgr getCategoryMgr() {
return categoryMgr;
}
public void setCategoryMgr(CategoryMgr categoryMgr) {
this.categoryMgr = categoryMgr;
}
/*
* Generated Methods
*/
/**
* 新增类别
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
* @throws ApplicationException
*/
public ActionForward newCategory(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException, ApplicationException {
CategoryForm categoryForm = (CategoryForm) form;
String soIdStr = request.getParameter("soId");//从stockSericeOrder.jsp取得服务单ID再返回页面
logger.debug("服务单ID是:"+soIdStr);
Category category = new Category();
BeanUtils.copyProperties(categoryForm, category);
try{
categoryMgr.getCategoryDAO().save(category);
}catch(RuntimeException re){
logger.debug(re.getMessage());
throw new ApplicationException(Constants.ADD_CATEGORY);
}
response.getWriter().print("<script>alert('"+Constants.SAVESUCCESS+"');window.location.href='"+request.getContextPath()+"/serviceOrder.do?method=getServiceOrderToStock&id="+soIdStr+"'</script>");
return null;
}
/**
* 删除类别
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
* @throws ApplicationException
*/
public ActionForward delCategoryById(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException, ApplicationException {
CategoryForm categoryForm = (CategoryForm) form;
String soIdStr = request.getParameter("soId");//从stockSericeOrder.jsp取得服务单ID再返回页面
int id = 0;
String idStr = request.getParameter("id");
if(idStr!=null && !"".equals(idStr)){
id = Integer.parseInt(idStr);
}
logger.debug("服务单ID是:"+soIdStr);
Category category = new Category();
BeanUtils.copyProperties(categoryForm, category);
try{
category = categoryMgr.getCategoryDAO().findById(id);
categoryMgr.getCategoryDAO().delete(category);
}catch(RuntimeException re){
logger.debug(re.getMessage());
throw new ApplicationException(Constants.DEL_CATEGORY);
}
response.getWriter().print("<script>alert('"+Constants.DELETESUCCESS+"');window.location.href='"+request.getContextPath()+"/serviceOrder.do?method=getServiceOrderToStock&id="+soIdStr+"'</script>");
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -