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

import com.zt.pojo.cart;
import com.zt.pojo.custom;
import com.zt.pojo.goods;
import com.zt.pojo.order;
import com.zt.service.*;
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 org.springframework.web.servlet.ModelAndView;

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

@Controller
public class BackstageController {
    @Resource
    private AdminService adminService;
    @Resource
    private GoodsService goodsService;
    @Resource
    private OrderService orderService;
    @Resource
    private CustomService customService;
    @Resource
    private CartService cartService;

    // 管理员后台界面跳转
    @RequestMapping(value = "/admin")
    public ModelAndView toBackstage(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("page/alogin.jsp");
        return modelAndView;
    }

    // 处理管理员登录
    @RequestMapping(value = "/alogin.action",method = RequestMethod.POST)
    public void alogin(@RequestParam(value = "cname") String cname,
                       @RequestParam(value = "password") String password,
                       HttpServletResponse response){
        PrintWriter out = null;
        try{
            out = response.getWriter();
            String result = adminService.loginService(cname,password);
            out.print(result);
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 添加商品信息
    @RequestMapping(value = "/addGoods.action",method = RequestMethod.POST)
    public void addGoods(@RequestParam(value = "id") String id,
                         @RequestParam(value = "img") String img,
                         @RequestParam(value = "title") String title,
                         @RequestParam(value = "info") String info,
                         @RequestParam(value = "name") String name,
                         @RequestParam(value = "price") String price,
                         @RequestParam(value = "stock") String stock,
                         @RequestParam(value = "para") String para,
                         @RequestParam(value = "type") String type,
                         @RequestParam(value = "weight") String weight,
                         HttpServletResponse response){
        PrintWriter out = null;
        try{
            out = response.getWriter();
            goods goods = new goods(id,img,title,info,name,new Integer(price),new Integer(stock),para,type,new Integer(weight));
            goodsService.addGoodsService(goods);
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 添加订单信息
    @RequestMapping(value = "/addOrder.action",method = RequestMethod.POST)
    public void addOrder(@RequestParam(value = "rid") String rid,
                         @RequestParam(value = "cname") String cname,
                         @RequestParam(value = "ids") String ids,
                         @RequestParam(value = "names") String names,
                         @RequestParam(value = "price") String price,
                         HttpServletResponse response){
        PrintWriter out = null;
        try{
            out = response.getWriter();
            order order = new order(rid,cname,ids,names,new Integer(price));
            orderService.addOrderService(order);
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 删除单个字段
    @RequestMapping(value = "/deleteItem.action",method = RequestMethod.POST)
    public void deleteItem1(@RequestParam("table") String table,
                            @RequestParam("id") String id,
                            HttpServletResponse response){
        PrintWriter out = null;
        try{
            out = response.getWriter();
            switch (table){
                case "custom":{
                    customService.deleteCustomService(id);
                    break;
                }
                case "goods":{
                    goodsService.deleteGoodsService(id);
                    break;
                }
                case "cart":{
                    String[] s = id.split("_");
                    cartService.deleteCartService(s[0],s[1]);
                    break;
                }
                case "order":{
                    orderService.deleteOrderService(id);
                    break;
                }
                default:break;
            }
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 修改客户信息
    @RequestMapping(value = "/updateCustom2.action",method = RequestMethod.POST)
    public void updateCustom2(@RequestParam(value = "cname") String cname,
                             @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,
                             HttpServletResponse response){
        PrintWriter out = null;
        try{
            out = response.getWriter();
            custom c = new custom(cname,password,name,phone,address,question,answer);
            customService.updateCustomService(c);
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 修改商品信息
    @RequestMapping(value = "/updateGoods.action",method = RequestMethod.POST)
    public void updateGoods(@RequestParam(value = "id") String id,
                            @RequestParam(value = "img") String img,
                            @RequestParam(value = "title") String title,
                            @RequestParam(value = "info") String info,
                            @RequestParam(value = "name") String name,
                            @RequestParam(value = "price") String price,
                            @RequestParam(value = "stock") String stock,
                            @RequestParam(value = "para") String para,
                            @RequestParam(value = "type") String type,
                            @RequestParam(value = "weight") String weight,
                            HttpServletResponse response){
        PrintWriter out = null;
        try{
            out = response.getWriter();
            goods goods = new goods(id,img,title,info,name,new Integer(price),new Integer(stock),para,type,new Integer(weight));
            goodsService.updateGoodsService(goods);
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 修改购物车信息
    @RequestMapping(value = "/updateCart.action",method = RequestMethod.POST)
    public void updateCart(@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();
            cart cart = new cart(cname,id,img,name,new Integer(price),new Integer(number));
            cartService.updateCartService(cart);
            out.print("success");
            out.flush();
        }catch (IOException e){
            e.printStackTrace();
        }finally {}
        out.close();
    }

    // 修改订单信息
    @RequestMapping(value = "/updateOrder.action",method = RequestMethod.POST)
    public void updateCart(@RequestParam(value = "rid") String rid,
                           @RequestParam(value = "cname") String cname,
                           @RequestParam(value = "ids") String ids,
                           @RequestParam(value = "names") String names,
                           @RequestParam(value = "price") String price,
                           HttpServletResponse response){
        PrintWriter out = null;
        try{
            out = response.getWriter();
            order order = new order(rid,cname,ids,names,new Integer(price));
            orderService.updateOrderService(order);
            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日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友