0

0

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

WBOY

WBOY

发布时间:2023-05-12 10:01:19

|

1391人浏览过

|

来源于亿速云

转载

一、项目概述

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)垃圾信息增删改查

快写红薯通AI
快写红薯通AI

快写红薯通AI,专为小红书而生的AI写作工具

下载
/**
 * 添加垃圾信息
 **/
    @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怎么实现垃圾分类管理系统

相关专题

更多
mysql修改数据表名
mysql修改数据表名

MySQL修改数据表:1、首先查看数据库中所有的表,代码为:‘SHOW TABLES;’;2、修改表名,代码为:‘ALTER TABLE 旧表名 RENAME [TO] 新表名;’。php中文网还提供MySQL的相关下载、相关课程等内容,供大家免费下载使用。

665

2023.06.20

MySQL创建存储过程
MySQL创建存储过程

存储程序可以分为存储过程和函数,MySQL中创建存储过程和函数使用的语句分别为CREATE PROCEDURE和CREATE FUNCTION。使用CALL语句调用存储过程智能用输出变量返回值。函数可以从语句外调用(通过引用函数名),也能返回标量值。存储过程也可以调用其他存储过程。php中文网还提供MySQL创建存储过程的相关下载、相关课程等内容,供大家免费下载使用。

247

2023.06.21

mongodb和mysql的区别
mongodb和mysql的区别

mongodb和mysql的区别:1、数据模型;2、查询语言;3、扩展性和性能;4、可靠性。本专题为大家提供mongodb和mysql的区别的相关的文章、下载、课程内容,供大家免费下载体验。

281

2023.07.18

mysql密码忘了怎么查看
mysql密码忘了怎么查看

MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS 应用软件之一。那么mysql密码忘了怎么办呢?php中文网给大家带来了相关的教程以及文章,欢迎大家前来阅读学习。

515

2023.07.19

mysql创建数据库
mysql创建数据库

MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS 应用软件之一。那么mysql怎么创建数据库呢?php中文网给大家带来了相关的教程以及文章,欢迎大家前来阅读学习。

255

2023.07.25

mysql默认事务隔离级别
mysql默认事务隔离级别

MySQL是一种广泛使用的关系型数据库管理系统,它支持事务处理。事务是一组数据库操作,它们作为一个逻辑单元被一起执行。为了保证事务的一致性和隔离性,MySQL提供了不同的事务隔离级别。php中文网给大家带来了相关的教程以及文章欢迎大家前来学习阅读。

386

2023.08.08

sqlserver和mysql区别
sqlserver和mysql区别

SQL Server和MySQL是两种广泛使用的关系型数据库管理系统。它们具有相似的功能和用途,但在某些方面存在一些显著的区别。php中文网给大家带来了相关的教程以及文章,欢迎大家前来学习阅读。

531

2023.08.11

mysql忘记密码
mysql忘记密码

MySQL是一种关系型数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。那么忘记mysql密码我们该怎么解决呢?php中文网给大家带来了相关的教程以及其他关于mysql的文章,欢迎大家前来学习阅读。

600

2023.08.14

c++空格相关教程合集
c++空格相关教程合集

本专题整合了c++空格相关教程,阅读专题下面的文章了解更多详细内容。

0

2026.01.23

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Vue 教程
Vue 教程

共42课时 | 7万人学习

Vue3.x 工具篇--十天技能课堂
Vue3.x 工具篇--十天技能课堂

共26课时 | 1.4万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号