(免费分享)基于ssm在线点餐

news2025/2/26 22:57:49

源码获取:关注文末gongzhonghao,017领取下载链接

开发工具:IDEA ,Tomcat8.0,数据库:mysql5.7

/**
 * FileName: CategoryController
 *
 * Date:     2020/9/30 17:04
 * Description:
 */
package com.qst.goldenarches.controller;

import com.github.pagehelper.PageHelper;
import com.qst.goldenarches.pojo.Category;
import com.qst.goldenarches.pojo.Msg;
import com.qst.goldenarches.pojo.Product;
import com.qst.goldenarches.service.CategoryService;
import com.sun.org.apache.regexp.internal.RE;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.PrivateKeyResolver;
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.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /***
     * 商品类别:获取类别
     * 根据传入的商品类别id获取有商品的商品类别
     * @param categoryid
     * @return
     */
    @ResponseBody
    @RequestMapping("getCategories")
    public Msg getHaveProductCategories(Integer[] categoryid){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("categoryids", categoryid);
        List<Category> categories =categoryService.getHaveProductCategories(map);
        return  Msg.success().add("categoryList",categories);
    }

    /***
     * 商品类别:批量删除商品类别
     * @param categoryid
     * @returns
     */
    @ResponseBody
    @RequestMapping("deleteBatch")
    public Msg deleteBatch(Integer[] categoryid){
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("categoryids", categoryid);
            if (!categoryService.deleteProducts(map)){
                return Msg.fail();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Msg.fail();
        }
        return Msg.success();
    }
    /**
     * 商品类别:执行单个删除商品类别
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("deleteOne")
    public Msg deleteOne(Integer id){
        try {

            if(!categoryService.reomveCategory(id)){
                return Msg.fail();
            }
        }catch (Exception e){
            e.printStackTrace();
            return Msg.fail();
        }
        return Msg.success();
    }
    /**
     * 商品类别:执行商品信息修改方法
     * @param category
     * @return
     */
    @ResponseBody
    @RequestMapping("doEdit")
    public Msg doEdit(Category category){
        try {
            if(!categoryService.editCategory(category)){
                return Msg.fail();
            }
        }catch (Exception e){
            e.printStackTrace();
            return Msg.fail();
        }
        return Msg.success();
    }
    /**
     * 商品类别:跳转方法
     * 跳转到商品类别修改界面
     * @return
     */
    @RequestMapping("edit")
    public String toEdit(Category category, Model model){
        model.addAttribute("category", category);
        return "category/edit";
    }

    /**
     * 商品类别:添加商品类别
     * @param category
     * @return
     */
    @ResponseBody
    @RequestMapping("doAdd")
    public Msg doAdd(Category category){
        Boolean flag =categoryService.addCategory(category);
        if (flag){
            return Msg.success().add("category",category);
        }
        return Msg.fail();
    }
    /***
     * 商品类别:跳转方法
     * 跳转到商品类别添加界面
     * @return
     */
    @RequestMapping("add")
    public String toAdd(){
        return "category/add";
    }
    /**
     * 商品类别:分页查找
     * 查询全部商品类别并分页显示
     * @param pn 页码
     * @return json数据 Msg
     */
    @ResponseBody
    @RequestMapping("pagedGetAll")
    public Msg pagedGetAll(@RequestParam(value = "pageno",defaultValue = "1") Integer pn, String queryText){
        PageHelper.startPage(pn,5);
        List<Category> categories =categoryService.getAll(queryText);
        com.github.pagehelper.PageInfo<Category> categoryPageInfo =new com.github.pagehelper.PageInfo<Category>(categories,5);
        return Msg.success().add("pageInfo",categoryPageInfo);
    }

    /**
     * 商品后台:跳转方法
     * 跳转至商品类别主页
     * @return
     */
    @RequestMapping("index")
    public String toIndex(){
        return "category/index";
    }
    /***
     * 商品后台:获取全部商品类别
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAll")
    public Msg getAll(){
        List<Category> categories =categoryService.getAll(null);
        return Msg.success().add("categoryInfo",categories);
    }

}

/**
 * FileName: AdminController
 *
 * Date:     2020/10/6 17:59
 * Description: 管理员控制类
 */
package com.qst.goldenarches.controller;
import com.github.pagehelper.PageHelper;
import com.qst.goldenarches.pojo.*;
import com.qst.goldenarches.service.AdminService;
import com.qst.goldenarches.service.PermissionService;
import com.qst.goldenarches.service.RoleService;
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 javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private PermissionService permissionService;


    /**
     * 跳转到错误页面(权限不足)
     * @return
     */
    @RequestMapping("error")
    public String error() {
        return "admin/error";
    }

    /**
     * 删除管理员的角色
     * @param adminId
     * @param assignRoleIds
     * @return
     */
    @ResponseBody
    @RequestMapping("doUnAssign")
    public Object dounAssign( Integer adminId, Integer[] assignRoleIds ) {
        try {
            // 删除关系表数据
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("adminId", adminId);
            map.put("roleIds", assignRoleIds);
            adminService.removeAdminRoles(map);
            return Msg.success();
        } catch ( Exception e ) {
            e.printStackTrace();
            return Msg.fail();
        }
    }
    /**
     * 为管理员分配角色
     * @param adminId
     * @param unassignRoleIds
     * @return
     */
    @ResponseBody
    @RequestMapping("doAssign")
    public Object doAssign( Integer adminId, Integer[] unassignRoleIds ) {
        try {
            // 增加admin_role关系表数据
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("adminId", adminId);
            map.put("roleIds", unassignRoleIds);
            adminService.addAdminRoles(map);
            return Msg.success();
        } catch ( Exception e ) {
            e.printStackTrace();
            return Msg.fail();
        }
    }
    /**
     * 页面跳转:
     * 跳转到管理员角色分配页面
     * 数据回显,显示已经分配的角色
     * 和没有分配的角色
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("/assign")
    public String assign( Integer id, Model model ) {

        Admin admin = adminService.getAdminById(id);
        model.addAttribute("admin", admin);

        List<Role> roles = roleService.getAllRoles(null);

        List<Role> assingedRoles = new ArrayList<Role>();
        List<Role> unassignRoles = new ArrayList<Role>();

        // 获取关系表的数据
        List<Integer> roleids = adminService.getRoleIdsByAdminId(id);
        for ( Role role : roles ) {
            if ( roleids.contains(role.getId()) ) {
                assingedRoles.add(role);
            } else {
                unassignRoles.add(role);
            }
        }
        model.addAttribute("assingedRoles", assingedRoles);
        model.addAttribute("unassignRoles", unassignRoles);
        return "admin/assign";
    }
    /**
     * 根据id删除管理员
     * @param adminid
     * @return
     */
    @ResponseBody
    @RequestMapping("/deletes")
    public Msg deletes( Integer[] adminid ) {
        try {
            if (adminid.length>0){
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("adminids", adminid);
                adminService.removeAdmins(map);
                return Msg.success();
            }
            return  Msg.fail();
        } catch ( Exception e ) {
            e.printStackTrace();
             return Msg.fail();
        }
    }
    /**
     * 实现用户修改业务逻辑
     * @param admin
     * @return
     */
    @ResponseBody
    @RequestMapping("/doEdit")
    public Msg update(HttpSession session, Admin admin ) {
        try {
            Admin sessionAdmin =(Admin) session.getAttribute("loginAdmin");
            if(sessionAdmin.getId()==admin.getId()){
                adminService.editAdmin(admin);
                session.setAttribute("loginAdmin",admin);
                return Msg.success();
            }
            return Msg.fail();
        } catch ( Exception e ) {
            e.printStackTrace();
             return Msg.fail();
        }
    }

    /**
     * 跳转到修改个人信息(admin)界面
     * @param model
     * @return
     */
    @RequestMapping("/edit")
    public String edit(HttpSession session,Model model ) {
        Admin admin =(Admin) session.getAttribute("loginAdmin");
        model.addAttribute("admin",admin);
        return "admin/edit";
    }

    /**
     * 新增界面实现新增业务
     * @param admin
     * @return
     */
    @ResponseBody
    @RequestMapping("doAdd")
    public Msg doAdd( Admin admin ) {
        try {
            if (adminService.validateAccountUnique(admin.getAccount())){
                admin.setPassword("1234");//默认密码
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                admin.setCreateTime(sdf.format(new Date()));
                adminService.addAdmin(admin);
                return Msg.success();
            }
            return Msg.fail();
        } catch ( Exception e ) {
            e.printStackTrace();
             return Msg.fail();
        }

    }

    /**
     * 检验用户账户唯一性
     * @param account
     * @return
     */
    @RequestMapping("uniqueAcct")
    @ResponseBody
    public Msg validateAccountUnique(String account,HttpSession session){
        try {
            if(account!=null) {
                boolean flag = adminService.validateAccountUnique(account);
                if (flag){
                    return Msg.success();
                }
            }
            return Msg.fail().add("va_msg","账户已存在");
        }catch (Exception e){
            e.printStackTrace();
            return Msg.fail().add("va_mag","服务异常,稍后重试");
        }
    }
    /**
     * 跳转到新增界面
     * @return
     */
    @RequestMapping("add")
    public String toAdd(){
        return "admin/add";
    }

    /**
     *
     * @param pn
     * @param pagesize
     * @param queryText
     * @return
     */
    @ResponseBody
    @RequestMapping("/pageQuery")
    public Msg pageQuery( @RequestParam(value = "pageno",defaultValue = "1") Integer pn,
                          @RequestParam(value = "pagesize",defaultValue = "10")Integer pagesize , String queryText) {
        try {
            PageHelper.startPage(pn,pagesize);
            List<Admin> admins =adminService.getAllAdmin(queryText);

            com.github.pagehelper.PageInfo<Admin> adminPageInfo =
                    new com.github.pagehelper.PageInfo<Admin>(admins,5);
            return Msg.success().add("pageInfo",adminPageInfo);
        } catch ( Exception e ) {
            e.printStackTrace();
             return Msg.fail();
        }
    }
    /**
     * 页面跳转
     * 管理员列表主界面
     * @return
     */
    @RequestMapping("/index")
    public String index(){
        return "admin/index";
    }

    /***
     * 管理员退出
     * @param session
     * @return
     */
    @RequestMapping("logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:/admin/login";
    }
    /**
     * 跳转到登陆后的主页面,
     * 也是数据分析主页面
     * @return
     */
    @RequestMapping("main")
    public String toMain(){
        return "admin/main";
    }
    /**
     * 执行管理员登陆
     * @param admin
     * @param session
     * @return
     */
    @ResponseBody
    @RequestMapping("/doLogin")
    public Msg doLogin(Admin admin, HttpSession session){

        Admin dbAdmin =adminService.login(admin);
        if (dbAdmin!=null){
            session.setAttribute("loginAdmin",dbAdmin);

            // 获取用户权限信息
            List<Permission> permissions = permissionService.getPermissionsByAdmin(dbAdmin);
            Map<Integer, Permission> permissionMap = new HashMap<Integer, Permission>();
            Permission root = null;
            Set<String> uriSet = new HashSet<String>();
            for ( Permission permission : permissions ) {
                permissionMap.put(permission.getId(), permission);
                if ( permission.getUrl() != null && !"".equals(permission.getUrl()) ) {
                    uriSet.add(session.getServletContext().getContextPath() + permission.getUrl());
                }
            }
            session.setAttribute("authUriSet", uriSet);
            for ( Permission permission : permissions ) {
                Permission child = permission;
                if ( child.getPid() == 0 ) {
                    root = permission;
                } else {
                    Permission parent = permissionMap.get(child.getPid());
                    parent.getChildren().add(child);
                }
            }
            session.setAttribute("rootPermission", root);
            return Msg.success();
        }else {
            return Msg.fail();
        }
    }
    /**
     * 跳转到登陆页面
     * @return
     */
    @RequestMapping("login")
    public String toLogin(){
        return "admin/login";
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/39377.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

关于环境保护html网页设计完整版-4环保垃圾分类5页

⛵ 源码获取 文末联系 ✈ Web前端开发技术 描述 网页设计题材&#xff0c;DIVCSS 布局制作,HTMLCSS网页设计期末课程大作业 | 环境保护 | 保护地球 | 校园环保 | 垃圾分类 | 绿色家园 | 等网站的设计与制作HTML期末大学生网页设计作业 HTML&#xff1a;结构 CSS&#xff1a;样…

Node.js 入门教程 14 使用 exports 从 Node.js 文件中公开功能

Node.js 入门教程 Node.js官方入门教程 Node.js中文网 本文仅用于学习记录&#xff0c;不存在任何商业用途&#xff0c;如侵删 文章目录Node.js 入门教程14 使用 exports 从 Node.js 文件中公开功能14 使用 exports 从 Node.js 文件中公开功能 Node.js 具有内置的模块系统。 …

Python脚本实现BJTU校园网自动登录

文章目录 1.背景介绍2.登录分析3.代码分析4.源代码1.背景介绍 BJTU的校园网连接好以后需要输入账号和密码才能正确登录,如下图所示。整个流程比较繁琐,尤其是很多服务器、工作站是无图形化的系统,大部分时间需要SSH连接,所以通过界面登录十分不方便。 所以就想了一个办法,…

(附源码)计算机毕业设计Java办公自动化管理系统

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat8.5 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; Springboot mybatis Maven Vue 等等组成&#xff0c;B/…

(附源码)计算机毕业设计Java巴州监控中心人事管理系统

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat8.5 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; Springboot mybatis Maven Vue 等等组成&#xff0c;B/…

java_ 多线程知识笔记(一)

文章目录前言:1.如何理解线程2.进程和线程的关系3.多线程编程第一种:继承Thread类第二种:实现Runnable 接口:第三种:使用Lambda表达式4.Thread 用法1.Thread常见的构造方法2.Thread的几个常见的属性5.等待一个线程6.并发和并行前言: 为什么要引入多线程编程 java引用进程的概…

【好书推荐】计算机网络:自顶向下方法(第七版)

人生的美妙之处在于迷上一样东西。人生苦短&#xff0c;少做些虚无缥缈的事。 – 刘慈欣-《三体》 推荐理由 自计算机网络诞生以来&#xff0c;经过数十年的发展&#xff0c;计算机的体系已经非常庞大&#xff0c;同时计算机网络也大大促进了人类社会的发展。无数大佬前赴后继…

【python量化】将Informer用于股价预测

写在前面Informer模型来自发表于AAAI21的一篇best paper《Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting》。Informer模型针对Transformer存在的一系列问题&#xff0c;如二次时间复杂度、高内存使用率以及Encoder-Decoder的结构限制&…

后台管理不可忽视,华为云会议最新支持管理员分权分域

如今&#xff0c;跨地域&#xff0c; 跨组织&#xff0c;需要随时随地接入的远程沟通协作变得愈加频繁&#xff0c;众多企业开始纷纷建设符合自身需求的智能会议室。在会议系统的众多能力中&#xff0c;后台管理&#xff0c;这项常常被C端用户忽略的能力&#xff0c;B端的企业却…

真的够可以的,基于Netty实现了RPC框架

RPC全称Remote Procedure Call&#xff0c;即远程过程调用&#xff0c;对于调用者无感知这是一个远程调用功能。目前流行的开源RPC 框架有阿里的Dubbo、Google 的 gRPC、Twitter 的Finagle 等。本次RPC框架的设计主要参考的是阿里的Dubbo&#xff0c;这里Netty 基本上是作为架构…

1. Spring Boot 3 入门学习教程之开发第一个 Spring Boot 应用程序

Spring Boot 3 入门学习教程之开发第一个 Spring Boot 应用程序0. 前言1. Spring Boot 介绍2. 系统要求2.1 Servlet容器2.2 GraalVM Native Image&#xff08;GraalVM 原生镜像&#xff09;3. 安装Spring Boot 开发环境3.1 安装JDK3.2 安装Spring Boot构建工具3.2.1 方式一&…

C++标准库分析总结(九)——<仿函数/函数对象>

目录 1.functor仿函数简介 2 仿函数的分类 3 仿函数使用 4 仿函数可适配的条件 1.functor仿函数简介 仿函数是STL中最简单的部分&#xff0c;存在的本质就是为STL算法部分服务的&#xff0c;一般不单独使用。仿函数&#xff08;functors&#xff09;又称为函数对象&…

【InnoDB Cluster】修改已有集群实例名称及成员实例选项

【InnoDB Cluster】修改已有集群实例名称&#xff0c;成员实例名称和选项 文章目录【InnoDB Cluster】修改已有集群实例名称&#xff0c;成员实例名称和选项修改名称修改已有集群实例名称修改已有集群实例的成员实例名称修改成员服务器操作系统的主机名直接修改元数据库中的表使…

力扣(LeetCode)88. 合并两个有序数组(C++)

朴素思想 朴素思想&#xff0c;开第三个数组&#xff0c;对 nums1nums1nums1 和 nums2nums2nums2 进行二路归并。 class Solution { public:void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {vector<int> nums3(mn);int i 0,j …

2.2 Linux启动初始化文件系统

为了方便了解和调试我们的Linux系统,我们需要将proc,debugfs,tmp等挂载起来,否则我们我发了解系统的进程,负载等信息,如下是未进行任何挂载时,我们无法通过ps等方法查看系统任何进程信息: 一,挂载proc fs proc是一个伪文件系统,(伪文件系统只存在内存中,而不占用存…

Node.js 入门教程 2 Node.js 简史

Node.js 入门教程 Node.js官方入门教程 Node.js中文网 本文仅用于学习记录&#xff0c;不存在任何商业用途&#xff0c;如侵删 文章目录Node.js 入门教程2 Node.js 简史2.1 一点历史2.2 20092.3 20102.4 20112.5 20122.6 20132.7 20142.8 20152.9 20162.10 20172.11 20182.12 2…

聊一聊微服务常见配置中心工作原理

0. 环境 nacos版本&#xff1a;1.4.1 Spring Cloud : 2020.0.2 Spring Boot &#xff1a;2.4.4 Spring Cloud alibaba: 2.2.5.RELEASE Spring Cloud openFeign 2.2.2.RELEASE 测试代码&#xff1a;github.com/hsfxuebao/s… 1. 配置中心基础 1.1 为什么要用配置中心&…

Js逆向教程-15滑块流程 极验

作者&#xff1a;虚坏叔叔 博客&#xff1a;https://xuhss.com 早餐店不会开到晚上&#xff0c;想吃的人早就来了&#xff01;&#x1f604; Js逆向教程-15滑块流程 极验 一、滑块是什么&#xff1f; 区分是否是机器人。根据滑动轨迹区分是否是人操作的。 滑块肯定有滑动条 …

亚马逊云科技持续创新、领势而行,re:Invent颠覆想象

当一行行代码成为托起数字社会的基础架构&#xff0c;社会发展开始面临真正意义上的变革与重塑。作为云计算领域的探路者与引领者&#xff0c;亚马逊云科技持续创新、领势而行&#xff0c;正不断塑造并颠覆着大众关于云计算未来的想象。 2006年 开端 2006年&#xff0c;亚马逊…

【单片机基础】I2C通信-基于STC89C52RC

文章目录1、IIC总线结构2、IIC总线传输协议3、完成工程代码1、IIC总线结构 IIC总线是philips公司在八十年代初推出的一种串行、半双工总线。主要用于近距离、低速的芯片之间通信&#xff1b;IIC总线有两根双向的信号线&#xff0c;一根数据线SDA用于收发数据一根时钟线SCL用于…