首页>代码>SSM+jsp开发综合类购物商城项目ShopProject,有简单的后台管理功能>/SSM-ShopProject-master/shop-controller/src/main/java/com/zt/controller/OperationController.java
package com.zt.controller;

import com.zt.pojo.cart;
import com.zt.pojo.custom;
import com.zt.pojo.order;
import com.zt.model.pay;
import com.zt.service.CartService;
import com.zt.service.CustomService;
import com.zt.service.OrderService;
import com.zt.util.NumberUtil;
import com.zt.util.PayUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@Controller
public class OperationController {
    @Resource
    private CartService cartService;
    @Resource
    private OrderService orderService;
    @Resource
    private CustomService customService;

    // 加入购物车
    @RequestMapping(value = "/addCart.action",method = RequestMethod.POST)
    public void addCart(@RequestParam(value = "cname") String cname,
                        @RequestParam(value = "id") String id,
                        @RequestParam(value = "img") String img,
                        @RequestParam(value = "name") String name,
                        @RequestParam(value = "price") String price,
                        @RequestParam(value = "number") String number,
                        HttpServletResponse response){
        PrintWriter out = null;
        try{
            out = response.getWriter();
            int p = new Integer(price);
            int n = new Integer(number);
            String result = cartService.addCartService(new cart(cname,id,img,name,p,n));
            out.print(result);
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 删除购物车记录
    @RequestMapping(value = "/removeCart.action",method = RequestMethod.POST)
    public void removeCart(@RequestParam(value = "id") String id,
                           HttpServletRequest request,HttpServletResponse response){
        HttpSession session = null;
        PrintWriter out = null;
        try{
            session = request.getSession();
            out = response.getWriter();
            String cname = session.getAttribute("cname").toString();
            cartService.deleteCartService(cname,id);
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 提交订单
    @RequestMapping(value = "/submitOrder.action",method = RequestMethod.POST)
    public void submitOrder(HttpServletRequest request,HttpServletResponse response){
        HttpSession session = null;
        PrintWriter out = null;
        try{
            session = request.getSession();
            out = response.getWriter();
            String c_id = NumberUtil.createNumber();
            String cname = session.getAttribute("cname").toString();
            List<pay> list = (List<pay>) session.getAttribute("pay");
            String price = session.getAttribute("allprice").toString();
            order order = PayUtil.createOrder(c_id,list,cname,price);
            System.out.println(order);
            orderService.addOrderService(order);
            for(pay e : list){
                cartService.deleteCartService(cname,e.getId());
            }
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
    }

    // 删除订单记录
    @RequestMapping(value = "/removeOrder.action",method = RequestMethod.POST)
    public void removeOrder(@RequestParam(value = "rid") String rid,
                            HttpServletRequest request,HttpServletResponse response){
        PrintWriter out = null;
        try{
            out = response.getWriter();
            orderService.deleteOrderService(rid);
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 跟新用户信息
    @RequestMapping(value = "/updateCustom.action",method = RequestMethod.POST)
    public void updateCustom(@RequestParam(value = "name") String name,
                             @RequestParam(value = "phone") String phone,
                             @RequestParam(value = "address") String address,
                             @RequestParam(value = "password") String password,
                             @RequestParam(value = "question") String question,
                             @RequestParam(value = "answer") String answer,
                             HttpServletRequest request,HttpServletResponse response){
        PrintWriter out = null;
        HttpSession session = null;
        try{
            out = response.getWriter();
            session = request.getSession();
            String cname = session.getAttribute("cname").toString();
            custom custom = new custom(cname,password,name,phone,address,question,answer);
            customService.updateCustomService(custom);
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }
}
最近下载更多
SDLFJL  LV6 2023年8月15日
ai1017659012  LV9 2023年6月11日
苏拉德666  LV4 2023年5月15日
全栈小白  LV34 2023年4月15日
吴尚宇  LV2 2023年4月7日
计算机暴龙战士  LV19 2023年4月5日
a1017514773  LV6 2023年3月14日
gaoxuyang  LV8 2023年2月22日
jrqlove  LV5 2023年2月14日
7477444  LV1 2023年1月6日
最近浏览更多
brownwang  LV1 2023年10月14日
zhaozhiqi  LV5 2023年10月10日
爽朗的凯  LV2 2023年10月10日
cissy123 2023年9月30日
暂无贡献等级
lwllll  LV2 2023年9月25日
暂无贡献等级
aaaaooa  LV4 2023年8月29日
一纸凉生  LV5 2023年8月2日
SDLFJL  LV6 2023年7月23日
qq1154180193 2023年7月18日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友