📄 orderaction.java
字号:
package com.tarena.shoppingcart.action;import java.util.ArrayList;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.MappingDispatchAction;import com.tarena.shoppingcart.dao.ShoppingCartHibernateImpl;import com.tarena.shoppingcart.entity.Order;import com.tarena.shoppingcart.entity.*;public class OrderAction extends MappingDispatchAction { private ShoppingCartHibernateImpl service = new ShoppingCartHibernateImpl(); public ActionForward viewOrder(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward forward = null; ArrayList<Order> orders = new ArrayList<Order>(); try { HttpSession session = request.getSession(false); User user = (User) session.getAttribute("user"); Integer id = user.getId(); orders = service.listOrders(id); session.setAttribute("orders", orders); forward = mapping.findForward("viewOrder"); } catch (Exception e) { e.printStackTrace(); forward = mapping.findForward("error"); } return forward; } public ActionForward deleteSelectedOrder(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward forward = null; try { Integer id = Integer.valueOf(request.getParameter("orderid")); service.deleteOrderByOrderId(id); forward = mapping.findForward("toViewOrder"); } catch (Exception e) { e.printStackTrace(); forward = mapping.findForward("error"); } return forward; } public ActionForward viewSelectedOrderDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward forward =null; Order order =new Order(); try{ HttpSession session=request.getSession(false); Integer id=Integer.valueOf(request.getParameter("orderid")); order=service.findOrderByOrderId(id); session.setAttribute("order", order); forward=mapping.findForward("toViewOrderDetail"); }catch(Exception e){ e.printStackTrace(); forward=mapping.findForward("error"); } return forward;} public ActionForward manager_viewOrder(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward forward = null; ArrayList<Order> allOrders = new ArrayList<Order>(); try { HttpSession session = request.getSession(false); allOrders = service.AllListOrders(); session.setAttribute("allOrders", allOrders); forward = mapping.findForward("manager_viewOrder"); } catch (Exception e) { e.printStackTrace(); forward = mapping.findForward("error"); } return forward; } public ActionForward operateOrder(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward forward = null; try { HttpSession session = request.getSession(false); Integer id =Integer.valueOf(request.getParameter("id")); service.changeStatusById(id); forward = mapping.findForward("manager_viewOrder"); } catch (Exception e) { e.printStackTrace(); forward = mapping.findForward("error"); } return forward; } public ActionForward newViewOrderDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward forward = null; Order order=new Order(); User user=new User(); try { Integer id =Integer.valueOf(request.getParameter("id")); order=service.findOrderByOrderId(id); request.setAttribute("thisOrder", order); Integer user_id =order.getUser().getId(); user = service.findUserByUserId(user_id); request.setAttribute("thisUser", user); forward = mapping.findForward("newViewOrderDetail"); } catch (Exception e) { e.printStackTrace(); forward = mapping.findForward("error"); } return forward; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -