当前位置:

首页 > 编程开发 > 基于springboot+vue怎么实现垃圾分类管理系统

基于springboot+vue怎么实现垃圾分类管理系统

一、项目概述1.项目内容本项目利用IDEA,VisualStudioCode开发工具,借助Mysql,NavicatforMySQL工具,实现了一个基于springboot+vue的垃圾分类管理系统。系统为两种类型的用户提供服务,用户和管理员。2.实现功能(1)登陆功能通过和数据库建立联系后,数据库内的用户和管理员可在登录页面输入账号和密码登陆网页。(2)数据的增、查、改、删功能①垃圾的增、查、改、删②管理员的增、查、改、删③用户的增、查、改、删(3)通过饼状图,柱状图可显示用户的性别比例,入库垃圾的数量

本文目录

    一、项目概述

    1.项目内容

    本项目利用IDEA,Visual Studio Code 开发工具,借助Mysql,Navicat for MySQL 工具,实现了一个基于springboot+vue的垃圾分类管理系统。系统为两种类型的用户提供服务,用户和管理员。

    2.实现功能

    (1)登陆功能

    通过和数据库建立联系后,数据库内的用户和管理员可在登录页面输入账号和密码登陆网页。

    (2)数据的增、查、改、删功能

     ① 垃圾的增、查、改、删

     ② 管理员的增、查、改、删

     ③ 用户的增、查、改、删

    (3)通过饼状图,柱状图可显示用户的性别比例,入库垃圾的数量信息,用户总数,管理员总数,入库垃圾数量,查询次数等。

    二、具体实现

    1.前端登陆界面

    
    
    

    2.增删改查实现

    (1)管理员信息增删改查:

     /**
      * 添加管理员
      **/
        @RequestMapping(value = "/add",method = RequestMethod.POST)
        public Object addAdminGuanli(HttpServletRequest request){
            JSONObject jsonObject = new JSONObject();
            String name = request.getParameter("name").trim();
            String username = request.getParameter("username").trim();
            String password = request.getParameter("password").trim();
            String pic = request.getParameter("pic").trim();
            String location = request.getParameter("location").trim();
            String introduction = request.getParameter("introduction").trim();
    
            //保存到管理员的对象中
            AdminGuanli adminGuanli = new AdminGuanli();
            adminGuanli.setName(name);
            adminGuanli.setUsername(username);
            adminGuanli.setPassword(password);
            adminGuanli.setPic(pic);
            adminGuanli.setLocation(location);
            adminGuanli.setIntroduction(introduction);
            boolean flag = AdminGuanliService.insert(adminGuanli);
            if(flag){
                jsonObject.put(Consts.CODE,1);
                jsonObject.put(Consts.MSG,"添加成功");
                return jsonObject;
            }
            jsonObject.put(Consts.CODE,0);
            jsonObject.put(Consts.MSG,"添加失败");
            return jsonObject;
        }
        /**
         * 修改管理员
         **/
        @RequestMapping(value ="/update",method = RequestMethod.POST)
        public Object updateAdminGuanli(HttpServletRequest request){
    
            JSONObject jsonObject = new JSONObject();
            String id = request.getParameter("id").trim();
            String name = request.getParameter("name").trim();
            String username = request.getParameter("username").trim();
            String password = request.getParameter("password").trim();
    
            String location = request.getParameter("location").trim();
            String introduction = request.getParameter("introduction").trim();
            //保存到管理员的对象中
            AdminGuanli adminGuanli = new AdminGuanli();
            adminGuanli.setId(Integer.parseInt(id));
            adminGuanli.setName(name);
            adminGuanli.setUsername(username);
            adminGuanli.setPassword(password);
    
            adminGuanli.setLocation(location);
            adminGuanli.setIntroduction(introduction);
            boolean flag = AdminGuanliService.update(adminGuanli);
            if(flag){
                jsonObject.put(Consts.CODE,1);
                jsonObject.put(Consts.MSG,"修改成功");
                System.out.println("11111111111111111");
                return jsonObject;
            }
            jsonObject.put(Consts.CODE,0);
            jsonObject.put(Consts.MSG,"修改失败");
            return jsonObject;
        }
    
        /**
         * 删除管理员
         **/
        @RequestMapping(value ="/delete",method = RequestMethod.GET)
        public Object deleteAdminGuanli(HttpServletRequest request){
    
            String id = request.getParameter("id").trim();
            boolean flag = AdminGuanliService.delete(Integer.parseInt(id));
            return flag;
        }
    
        /**
         * 查询管理员
         **/
        @RequestMapping(value ="/selectByPrimaryKey",method = RequestMethod.GET)
        public Object selectByPrimaryKey(HttpServletRequest request){
            String id = request.getParameter("id").trim();
            return AdminGuanliService.selectByPrimaryKey(Integer.parseInt(id));
        }
    
    
        @RequestMapping(value ="/allAdminGuanli",method = RequestMethod.GET)
        public Object allAdminGuanli(HttpServletRequest request){
            return AdminGuanliService.allAdminGuanli();
        }
    
        @RequestMapping(value ="/AdminGuanliOfName",method = RequestMethod.GET)
        public Object AdminGuanliOfName(HttpServletRequest request){
            String name = request.getParameter("name").trim();
            return AdminGuanliService.AdminGuanliOfName("%"+name+"#");
        }
    
    
        /**
         * 更新管理员图片
         **/
        @RequestMapping(value ="/updateAdminPic",method = RequestMethod.POST)
        public Object updateAdminPic(@RequestParam("file") MultipartFile avatorFile, @RequestParam("id")int id){
            JSONObject jsonObject = new JSONObject();
            if(avatorFile.isEmpty()){
                jsonObject.put(Consts.CODE,0);
                jsonObject.put(Consts.MSG,"文件上传失败");
                return jsonObject;
            }
            //文件名=当前时间到毫秒+原来文件名
            String fileName = System.currentTimeMillis()+avatorFile.getOriginalFilename();
            //文件路径
            String filePath = System.getProperty("user.dir")+System.getProperty("file.separator")+"img"
                    +System.getProperty("file.separator")+"AdminPic";
            //如果文件路径不存在,新增该路径
            File file1 = new File(filePath);
            if(file1.exists()){
                file1.mkdir();
            }
            //实际文件路径
            File dest = new File(filePath+System.getProperty("file.separator")+fileName);
            //存储到数据库的相对文件地址
            String storeAvatorPath = "/img/AdminPic/"+fileName;
            try {
                avatorFile.transferTo(dest);
                AdminGuanli adminGuanli = new AdminGuanli();
                adminGuanli.setId(id);
                adminGuanli.setPic(storeAvatorPath);
                boolean flag = AdminGuanliService.update(adminGuanli);
                if(flag){
                    jsonObject.put(Consts.CODE,1);
                    jsonObject.put(Consts.MSG,"上传成功");
                    jsonObject.put("pic",storeAvatorPath);
                    return jsonObject;
                }
                jsonObject.put(Consts.CODE,0);
                jsonObject.put(Consts.MSG,"修改失败");
                return jsonObject;
            } catch (IOException e) {
                jsonObject.put(Consts.CODE,0);
                jsonObject.put(Consts.MSG,"修改失败"+e.getMessage());
            }finally {
                return jsonObject;
            }
    
        }
    
    }

    (2)垃圾信息增删改查

    /**
     * 添加垃圾信息
     **/
        @RequestMapping(value="/add",method= RequestMethod.POST)
        public Object addGarbage(HttpServletRequest request){
            JSONObject jsonObject=new JSONObject();
            String name=request.getParameter("name").trim();
            String type=request.getParameter("type").trim();
            String introduction=request.getParameter("introduction").trim();
    
            //保存到垃圾信息的对象当中
            Garbage garbage=new Garbage();
            garbage.setName(name);
            garbage.setType(type);
            garbage.setIntroduction(introduction);
            boolean flag=GarbageService.insert(garbage);
            if(flag){
                jsonObject.put(Consts.CODE,1);
                jsonObject.put(Consts.MSG,"添加成功");
                return jsonObject;
            }
            jsonObject.put(Consts.CODE,0);
            jsonObject.put(Consts.MSG,"添加失败");
            return jsonObject;
        }
    
    
        /**
         * 修改垃圾信息
         **/
        @RequestMapping(value = "/update",method = RequestMethod.POST)
        public Object updateGarbage(HttpServletRequest request){
            JSONObject jsonObject=new JSONObject();
            String id=request.getParameter("id").trim();
            String name=request.getParameter("name").trim();
            String type=request.getParameter("type").trim();
            String introduction=request.getParameter("introduction");
    
            //保存到垃圾信息的对象中去
            Garbage garbage=new Garbage();
            garbage.setId(Integer.parseInt(id));
            garbage.setName(name);
            garbage.setType(type);
            garbage.setIntroduction(introduction);
            boolean flag=GarbageService.update(garbage);
            if(flag){
                jsonObject.put(Consts.CODE,1);
                jsonObject.put(Consts.MSG,"修改成功");
                return jsonObject;
            }
            jsonObject.put(Consts.CODE,0);
            jsonObject.put(Consts.MSG,"修改失败");
            return jsonObject;
        }
    
    /**
     * 删除垃圾信息
     **/
        @RequestMapping(value = "/delete",method = RequestMethod.GET)
        public Object deleteGarbage(HttpServletRequest request){
    
            String id=request.getParameter("id").trim();
            boolean flag=GarbageService.delete(Integer.parseInt(id));
            return flag;
        }
    
    /**
     * 查询垃圾信息
     **/
    
        @RequestMapping(value = "/allGarbage",method = RequestMethod.GET)
        public Object allGarbage(HttpServletRequest request){
            return GarbageService.allGarbage();
        }
    
    
    }

    (3)用户信息增删改查

    /**
     * 添加用户
     **/
        @RequestMapping(value = "/add",method = RequestMethod.POST)
        public Object addUser(HttpServletRequest request){
            JSONObject jsonObject = new JSONObject();
            String name = request.getParameter("name").trim();
            String username = request.getParameter("username").trim();
            String password = request.getParameter("password").trim();
            String sex = request.getParameter("sex").trim();
            String pic = request.getParameter("pic").trim();
            String birth = request.getParameter("birth").trim();
            String location = request.getParameter("location").trim();
            String contact = request.getParameter("contact").trim();
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date birthDate = new Date();
            try {
                birthDate = dateFormat.parse(birth);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            System.out.println(name);
            //保存到用户的对象中
            User user=new User();
            user.setName(name);
            user.setUsername(username);
            user.setPassword(password);
            user.setSex(new Byte(sex));
            user.setPic(pic);
            user.setBirth(birthDate);
            user.setLocation(location);
            user.setContact(contact);
    
            boolean flag = UserService.insert(user);
            if(flag){
                jsonObject.put(Consts.CODE,1);
                jsonObject.put(Consts.MSG,"添加成功");
                return jsonObject;
            }
            jsonObject.put(Consts.CODE,0);
            jsonObject.put(Consts.MSG,"添加失败");
            return jsonObject;
        }
    /**
     * 修改用户
     **/
        @RequestMapping(value ="/update",method = RequestMethod.POST)
        public Object updateUser(HttpServletRequest request){
    
            JSONObject jsonObject = new JSONObject();
            String id = request.getParameter("id").trim();
            String name = request.getParameter("name").trim();
            String username = request.getParameter("username").trim();
            String password = request.getParameter("password").trim();
            String sex = request.getParameter("sex").trim();
            String pic = request.getParameter("pic").trim();
            String birth = request.getParameter("birth").trim();
            String location = request.getParameter("location").trim();
            String contact = request.getParameter("contact").trim();
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date birthDate = new Date();
            try {
                birthDate = dateFormat.parse(birth);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            //保存到用户的对象中
            User user=new User();
            user.setId(Integer.parseInt(id));
            user.setName(name);
            user.setPassword(password);
            user.setSex(new Byte(sex));
            user.setPic(pic);
            user.setBirth(birthDate);
            user.setLocation(location);
            user.setContact(contact);
            boolean flag = UserService.update(user);
            if(flag){
                jsonObject.put(Consts.CODE,1);
                jsonObject.put(Consts.MSG,"修改成功");
                System.out.println("11111111111111111");
                return jsonObject;
            }
            jsonObject.put(Consts.CODE,0);
            jsonObject.put(Consts.MSG,"修改失败");
            return jsonObject;
        }
    
    /**
     * 删除用户
     **/
        @RequestMapping(value ="/delete",method = RequestMethod.GET)
        public Object deleteUser(HttpServletRequest request){
    
            String id = request.getParameter("id").trim();
            boolean flag = UserService.delete(Integer.parseInt(id));
            return flag;
        }
    
    /**   
     * 查询用户
     **/
        @RequestMapping(value ="/selectByPrimaryKey",method = RequestMethod.GET)
        public Object selectByPrimaryKey(HttpServletRequest request){
            String id = request.getParameter("id").trim();
            return UserService.selectByPrimaryKey(Integer.parseInt(id));
        }
    
    
        @RequestMapping(value ="/allUser",method = RequestMethod.GET)
        public Object allUser(HttpServletRequest request){
            return UserService.allUser();
        }
    
        @RequestMapping(value ="/UserOfName",method = RequestMethod.GET)
        public Object UserOfName(HttpServletRequest request){
            String name = request.getParameter("name").trim();
            return UserService.userOfName("%"+name+"#");
        }
    
    
    /** 
     * 更新用户图片
     **/
        @RequestMapping(value ="/updateUserPic",method = RequestMethod.POST)
        public Object updateUserPic(@RequestParam("file") MultipartFile avatorFile, @RequestParam("id")int id){
            JSONObject jsonObject = new JSONObject();
            if(avatorFile.isEmpty()){
                jsonObject.put(Consts.CODE,0);
                jsonObject.put(Consts.MSG,"文件上传失败");
                return jsonObject;
            }
            //文件名=当前时间到毫秒+原来文件名
            String fileName = System.currentTimeMillis()+avatorFile.getOriginalFilename();
            //文件路径
            String filePath = System.getProperty("user.dir")+System.getProperty("file.separator")+"img"
                    +System.getProperty("file.separator")+"userPic";
            //如果文件路径不存在,新增该路径
            File file1 = new File(filePath);
            if(file1.exists()){
                file1.mkdir();
            }
            //实际文件路径
            File dest = new File(filePath+System.getProperty("file.separator")+fileName);
            //存储到数据库的相对文件地址
            String storeAvatorPath = "/img/userPic/"+fileName;
            try {
                avatorFile.transferTo(dest);
                User user = new User();
                user.setId(id);
                user.setPic(storeAvatorPath);
                boolean flag = UserService.update(user);
                if(flag){
                    jsonObject.put(Consts.CODE,1);
                    jsonObject.put(Consts.MSG,"上传成功");
                    jsonObject.put("pic",storeAvatorPath);
                    return jsonObject;
                }
                jsonObject.put(Consts.CODE,0);
                jsonObject.put(Consts.MSG,"修改失败");
                return jsonObject;
            } catch (IOException e) {
                jsonObject.put(Consts.CODE,0);
                jsonObject.put(Consts.MSG,"修改失败"+e.getMessage());
            }finally {
                return jsonObject;
            }
    
        }
    
    }

    3.解决跨域问题

    public class WebMvcConfig implements WebMvcConfigurer {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowCredentials(true) /*访问是否需要验证*/
                    .allowedOriginPatterns("*")
                    .allowedMethods("*");
        }
    }

    三、功能演示

    1.跟随前端网址访问网页

    基于springboot+vue怎么实现垃圾分类管理系统

    2.登陆主页

    基于springboot+vue怎么实现垃圾分类管理系统

    3.查看垃圾信息

    基于springboot+vue怎么实现垃圾分类管理系统

    4.用户管理页面

    基于springboot+vue怎么实现垃圾分类管理系统

    5.管理员管理页面

    基于springboot+vue怎么实现垃圾分类管理系统

    本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系bd@zhengruan.com
    作者最新文章
    编程开发 VUE
    相关文章 更多
    vue上传文件格式怎么设置及要求说明
    vue上传文件格式怎么设置及要求说明

    学习如何在Vue项目中设置文件上传格式限制。本文介绍使用HTML accept属性进行基础过滤,以及结合JavaScript进行严格后缀名校验的方法,确保只允许指定类型的文件被上传。

    vue创建项目很慢怎么解决及常见原因排查教程
    vue创建项目很慢怎么解决及常见原因排查教程

    分析Vue项目创建缓慢的常见原因,包括网络延迟和依赖下载问题,提供切换镜像源、更换包管理器及使用Vite等具体优化方案,提升开发环境搭建效率。

    vue下载文件怎么做到点上就有反应在浏览器显示进度条
    vue下载文件怎么做到点上就有反应在浏览器显示进度条

    详解如何在Vue项目中利用Axios的onDownloadProgress回调捕获下载进度,并结合UI组件实时渲染进度条,同时分析Blob对象处理大文件时的内存限制与替代方案。

    uniapp网络请求拦截怎么设置方法详细教程
    uniapp网络请求拦截怎么设置方法详细教程

    学习如何在UniApp项目中设置网络请求拦截器,实现统一的Token管理、请求参数处理和响应错误捕获,优化前端开发体验。

    Vue页面空白的排查方法及解决办法
    Vue页面空白的排查方法及解决办法

    遇到Vue项目页面空白不要慌,本文通过路由匹配、组件生命周期、异步数据加载及权限控制四个真实场景,详解排查步骤与解决办法,助你快速恢复页面显示。

    Sublime实现一键生成Vue模板_自定义Snippet实战
    Sublime实现一键生成Vue模板_自定义Snippet实战

    在Sublime中为Vue文件自定义Snippet时,scope参数错误是最常见的Tab无响应原因。需通过Developer:ShowScopeName确认正确语法作用域。占位符需依次递增,$0可选但建议添加。相同数字占位符会同步编辑,可通过不同编号解耦。Snippet无法在新建文件时自动展开,需手动输入tabTrigger后按Tab。务必确保文件已正确识别

    VSCode如何解决Prettier和Vue单引号双引号的冲突问题
    VSCode如何解决Prettier和Vue单引号双引号的冲突问题

    在Vue项目中,为解决Prettier默认双引号与Vue单引号规则的冲突,必须在项目根目录创建.prettierrc并设置singleQuote:true。同时VSCode全局设置失效,需依赖项目级配置。此外,需配置Vetur使JS格式化使用Prettier;Vue3项目禁用Vetur启用Volar。最后在ESLint的extends末尾添加eslint-c

    VSCode自动补全代码必备扩展_Vue项目开发必装
    VSCode自动补全代码必备扩展_Vue项目开发必装

    Vue3项目需安装Volar并彻底卸载Vetur,否则代码补全失效。ESLint需配置import/resolver以支持别名路径补全。避免同时启用Copilot与TabNine,防止卡顿及补全冲突,推荐二选一使用。

    VSCode离线环境插件管理_VSCode自动格式化Vue代码【指南】
    VSCode离线环境插件管理_VSCode自动格式化Vue代码【指南】

    离线环境VSCode自动格式化Vue文件需确保插件版本兼容、路径正确、签名有效。Vue2使用vetur,Vue3使用volar,不可混用。项目级配置写入.vscode/settings.json,保存失败多因ESLint冲突或缺失prettier依赖。建议预先离线安装prettier并验证签名。

    VSCode离线插件安装技巧_VSCode自动格式化Vue文件【配置】
    VSCode离线插件安装技巧_VSCode自动格式化Vue文件【配置】

    离线安装VSCode插件需通过命令面板或输出日志确认加载成功,避免静默失败。Vue文件格式化需确保语言模式正确且每块有对应格式化器,离线环境下Prettier需完整复制插件目录及依赖。关键配置如editor.formatOnSave和语言专属格式化器必须正确设置,防止相互覆盖。

    查看更多
    精品专题 更多
    装机必备
    装机必备

    正软商城装机必备专区,精选办公、浏览器、安全防护、影音播放、压缩解压、设计创作和系统工具等电脑常用正版软件,帮助用户快速完成新电脑软件配置。

    Windows
    Windows

    正软商城Windows软件专区,汇集适用于Windows电脑的办公、设计、安全防护、影音播放、开发工具和系统优化软件,提供软件介绍、系统要求、正版授权及购买下载服务。

    PDF教程
    PDF教程

    正软商城PDF教程频道提供PDF编辑、转换、合并、拆分、压缩及格式处理方法,同时介绍常用PDF软件和工具的使用技巧。

    Mac软件 更多
    讯飞智作 网页版
    讯飞智作 网页版
    Windows/ macOS/ Linux

    讯飞智作是一款基于语音合成技术、虚拟人驱动技术与数字人形象声音构建能力的 AI 数字人音视频创作平台。

    火山引擎 网页版
    火山引擎 网页版
    Windows/ macOS/ Linux

    火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。

    Aperty macOS版
    Aperty macOS版
    macOS

    Aperty 是 Skylum 推出的 AI 人像修图软件,支持自然肤质修饰、瑕疵处理、面部与身体调整、预设及批量同步。

    WINDOWS 更多
    讯飞智作 网页版
    讯飞智作 网页版
    Windows/ macOS/ Linux

    讯飞智作是一款基于语音合成技术、虚拟人驱动技术与数字人形象声音构建能力的 AI 数字人音视频创作平台。

    火山引擎 网页版
    火山引擎 网页版
    Windows/ macOS/ Linux

    火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。

    PixTV 网页版
    PixTV 网页版
    Windows

    PixTV 是一款在浏览器中使用的 AI 视觉内容创作平台,提供图片、视频、音频、文字生成、AI 分镜、局部重绘、提示词反推和无限画布等工具,适合短剧、漫剧、广告及社交媒体内容制作。