首页>代码>基于SpringBoot的爱购商城>/day15_eshop/src/main/java/com/eshop/controller/admin/BrandController.java
package com.eshop.controller.admin;

import com.eshop.domain.Brand;
import com.eshop.domain.ProductType;
import com.eshop.service.BrandService;
import com.eshop.service.ProductTypeService;
import com.eshop.utils.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/admin/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @Autowired
    private ProductTypeService productTypeService;
    @RequestMapping("/list")
    public String list( @RequestParam(defaultValue = "1") Integer pageNo,
                       @RequestParam(defaultValue = "5")Integer pageSize,
                       Model model){
        try {
            PageModel<Brand> brandPages = brandService.queryBrandPages(pageNo, pageSize);
            model.addAttribute("brandPages", brandPages);
        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute("errMessage", "查询失败:"+e.getMessage());
            return  "500";
        }
        return "admin/brand/list";
    }
    @RequestMapping("addPage")
    public String addPage(Model model){
        List<ProductType> productTypes= productTypeService.queryProductTypeAll();
        model.addAttribute("productTypes",productTypes);
        return "admin/brand/add";
    }
    @RequestMapping("/add")
    private String addBrand(Brand brand,Model model){
        try {
            int i = brandService.addBrand(brand);
            if (i==0){
                model.addAttribute("errMessage","服务器繁忙操作失败");
                return "500";
            }
        }catch (Exception e){
            model.addAttribute("errMessage",e.getMessage());
            return "500";
        }
        model.addAttribute("url", "admin/brand/list");
        return "success";


    }
    @RequestMapping("updatePage")
    public String updatePage(String id,Model model){
       Brand brand= brandService.queryBrandById(id);
        List<ProductType> productTypes= productTypeService.queryProductTypeAll();
        model.addAttribute("productTypes",productTypes);
        model.addAttribute("brand",brand);
        return "admin/brand/update";
    }
    @RequestMapping("/update")
    private String update(Brand brand,Model model){
        try {
            int i = brandService.updateBrand(brand);
            if (i==0){
                model.addAttribute("errMessage","服务器繁忙操作失败");
                return "500";
            }
        }catch (Exception e){
            model.addAttribute("errMessage",e.getMessage());
            return "500";
        }
        model.addAttribute("url", "admin/brand/list");
        return "success";


    }
    @RequestMapping("deletePage")
    public String deletePage(String id,Model model){
        model.addAttribute("id",id);
        return "admin/carousel/delete";
    }
    @RequestMapping("/delete")
    public String delete(String id, Model model){
        try {
            int i = brandService.delete(id);
            if (i==0){
                model.addAttribute("errMessage","服务器繁忙操作失败");
                return "500";
            }
        }catch (Exception e){
            model.addAttribute("errMessage",e.getMessage());
            return "500";
        }
        model.addAttribute("url", "admin/brand/list");
        return "success";

    }
    @RequestMapping("batchDel")
    @ResponseBody
    public String batchDel(String[] ids) {
        System.out.println("进来了");
        brandService.batchProductTypeDel(ids);
        return "/admin/brand/list";

    }
}
最近下载更多
五折也挺好的  LV13 4小时前
orang801  LV2 2月20日
cys18318001508  LV12 2024年11月28日
daixinheng  LV2 2024年11月26日
微信网友_6377331253415936  LV3 2024年11月24日
yvimib  LV3 2024年10月26日
微信网友_6786215447367680  LV5 2024年10月8日
TY0165  LV20 2024年6月22日
A1314521anna  LV1 2024年5月18日
qtingchh  LV3 2024年5月3日
最近浏览更多
orang801  LV2 2月20日
ryadmin123  LV2 2月12日
cherrylxj  LV3 1月13日
微信网友_7041036943331328  LV7 2024年12月31日
6899230 2024年12月21日
暂无贡献等级
ma406805131  LV19 2024年12月17日
hbyl123 2024年12月15日
暂无贡献等级
sjwc88  LV3 2024年12月4日
王愉悦  LV4 2024年12月3日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友