pricemanageraction.java

来自「电信计费项目 该系统在Sun Solaris下开发,运行于Apache Tom」· Java 代码 · 共 104 行

JAVA
104
字号
package com.tarena.netctoss.controller.actions;import java.util.*;import javax.servlet.http.*;import org.apache.struts.action.*;import org.apache.struts.actions.MappingDispatchAction;import com.tarena.netctoss.model.biz.entity.*;import com.tarena.netctoss.model.biz.*;import com.tarena.netctoss.model.form.PriceForm;public class PriceManagerAction extends MappingDispatchAction {		public ActionForward findAll(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws PriceActionException{		ActionForward forward = mapping.findForward("fail");		IPriceService service = ServiceFactory.getPriceService();		HttpSession session = request.getSession(false);		try {//			if(session.getAttribute("type").equals("admin") && getAdminModel((Admin)session.getAttribute("login_user"))){				List<Price> prices = service.findAll();				request.setAttribute("prices", prices);				forward = mapping.findForward("success");//			}		} catch (RuntimeException e) {			e.printStackTrace();			throw new PriceActionException();		}		return forward;	}		public ActionForward addPrice(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws PriceActionException{		ActionForward forward = mapping.findForward("fail");		IPriceService service = ServiceFactory.getPriceService();		try {			PriceForm pform = (PriceForm)form;			Price price = pform.getPrice();			service.add(price);			forward = mapping.findForward("success");		} catch (RuntimeException e) {			e.printStackTrace();			throw new PriceActionException();					}		return forward;	}		public ActionForward modifyPrice(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws PriceActionException{		ActionForward forward = null;		IPriceService service = ServiceFactory.getPriceService();		try {			PriceForm pform = (PriceForm)form;			Price price = pform.getPrice();			price.setPrice_id(Long.valueOf(request.getParameter("price_id")));			service.modify(price);			forward = mapping.findForward("success");		} catch (RuntimeException e) {			e.printStackTrace();			throw new PriceActionException();					}		return forward;	}		public ActionForward toModifyPrice(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws PriceActionException{		ActionForward forward = null;		IPriceService service = ServiceFactory.getPriceService();		try {			Long price_id=Long.valueOf(request.getParameter("price_id"));			Price price=service.findByID(price_id);			request.setAttribute("price", price);			forward = mapping.findForward("success");		} catch (NumberFormatException e) {			e.printStackTrace();		}		return forward;	}		public ActionForward deletePrice(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws PriceActionException{		ActionForward forward = mapping.findForward("fail");		IPriceService service = ServiceFactory.getPriceService();		try {			String[] price_id = request.getParameterValues("price_id");			for(int i=0;i<price_id.length;i++){				if(null!=price_id){					service.delete(price_id);				}			}			forward = mapping.findForward("success");		} catch (RuntimeException e) {			e.printStackTrace();		}		return forward;	}		public boolean getAdminModel(Admin admin){		Set<ManagerModel> models = admin.getModels();		for(ManagerModel model:models){			if(model.getName().equals("�ʷѹ���")){				return true;			}		}		return false;	}}

⌨️ 快捷键说明

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