Springboot+Nodejs+Vue实现前后端分离校园二手交易平台

简介: Springboot+Nodejs+Vue实现前后端分离校园二手交易平台

项目编号:BS-PT-066

一,项目简介


本项目基于springboot+vue实现了一个前后端分离模式的校园二手交易平台。校内师生可以在此平台上注册自己的账户,然后发布自己想要处理的二手物品,平台本身不实现在线交易功能,发布的二手物品由买卖双方自行联系进行线下交易。主要实现的功能有用户注册、登陆、发布商品、收藏商品、统计浏览量和收藏量、在线留言、全文检索、管理个人发布的商品和留言等功能。系统功能完整,业务模式清晰,开发结构简单,比较符合目前后端分离模式开发的主流诉求,可以用作毕业设计或课程设计以及期未作业使用。

二,环境介绍


语言环境:Java:  jdk1.8

数据库:Mysql: mysql5.7   REDIS缓存数据库

应用服务器:Tomcat:  tomcat8.5.31

开发工具:IDEA或eclipse

后台开发技术:springboot+mybatisplus+jdk8+mysql5.6

前后台开发技术:VUE+ElementsUI

三,系统展示


image.png

用户登陆注册

image.png

image.png

发布二手物品

image.png

查看详情

image.png

查看我的收藏

image.png

查看我发布的商品:可以进行商品上下架 和删除操作

image.png

管理我发布的留言

image.png

四,核心代码展示


package cn.fleamarket.controller;
import cn.fleamarket.common.R;
import cn.fleamarket.domain.Favorites;
import cn.fleamarket.domain.User;
import cn.fleamarket.service.FavoritesService;
import cn.fleamarket.service.UserService;
import cn.fleamarket.utils.StringTool;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
 * 产品收藏表
 *
 * @author znz
 * @date 2022-09-12 10:46:22
 */
@RestController
@RequestMapping("/favorites")
public class FavoritesController {
    @Autowired
    private FavoritesService favoritesService;
    @Autowired
    UserService userService;
    @PostMapping(value = "/favoriteList", produces = "application/json")
    @ApiOperation("收藏分页查询列表,入参是page:第几页,number:每页几条")
    public R<List<Favorites>> favoritesList(@RequestBody Map<String,Object> params) {
        if (Objects.isNull(params)) {
            return R.error("参数错误!");
        }
        User nowUser = userService.qureyByUserName(params.getOrDefault("username","").toString());
        if (Objects.isNull(nowUser)) {
            return R.error("用户未登录!");
        }
        params.put("userId",nowUser.getId());
        Page<Favorites> favoritesPage = favoritesService.selectListPage(params);
        List<Favorites> data = favoritesPage
                .getRecords().stream()
                .filter(distinctByKey(Favorites::getProductId))
                .collect(Collectors.toList());
        return R.pageBuild(favoritesPage.getTotal(),
                favoritesPage.hasNext(),
                favoritesPage.hasPrevious(), data);
    }
    @PostMapping(value = "/addFavorites", produces = "application/json")
    @ApiOperation("添加收藏,pid:商品id")
    public JSONObject addFavorites(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) {
        JSONObject ret = new JSONObject();
        User user = null;
        try {
            user =  userService.qureyByUserName(jsonObject.getString("username"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            List<Favorites> list = favoritesService.selectByUid(user.getId());
            if (list.size() != 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getProductId().equals(jsonObject.getString("pid"))) {
                        ret.put("code", -1);
                        ret.put("data", false);
                        ret.put("msg", "添加失败");
                        return ret;
                    }
                }
            }
            if (user != null) {
                String productId = jsonObject.getString("pid");
                Integer state = jsonObject.getInteger("state");
                Favorites favorites = new Favorites();
                favorites.setId(StringTool.getUUID());
                favorites.setUserId(user.getId());
                favorites.setProductId(productId);
                favorites.setCreateTime(new Date());
                favorites.setState(state);
                Integer isS = favoritesService.addFavorites(favorites);
                if (isS > 0) {
                    ret.put("data", true);
                    ret.put("code", 0);
                    ret.put("msg", "添加成功");
                } else {
                    ret.put("code", -1);
                    ret.put("data", false);
                    ret.put("msg", "添加失败");
                }
            } else {
                ret.put("msg", "用户未登录");
            }
        } catch (Exception e) {
            e.printStackTrace();
            ret.put("code", -1);
            ret.put("data", false);
            ret.put("msg", "未知错误");
        }
        return ret;
    }
    @PostMapping(value = "/deleteFavorites", produces = "application/json")
    @ApiOperation("删除收藏,fid:收藏id")
    public JSONObject deleteFavorites(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) {
        JSONObject ret = new JSONObject();
        User user = null;
        try {
            user = userService.qureyByUserName(jsonObject.getString("username"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if (user != null) {
                String fid = jsonObject.getString("fid");
                Integer isS = favoritesService.deleteFavorites(fid);
                if (isS > 0) {
                    ret.put("code", 0);
                    ret.put("data", true);
                    ret.put("msg", "删除成功");
                }
            } else {
                ret.put("msg", "用户未登录");
            }
        } catch (Exception e) {
            e.printStackTrace();
            ret.put("code", -1);
            ret.put("data", false);
            ret.put("msg", "删除失败");
        }
        return ret;
    }
    private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        Map<Object, Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }
}
package cn.fleamarket.controller;
import cn.fleamarket.common.R;
import cn.fleamarket.config.PathConfig;
import cn.fleamarket.domain.Image;
import cn.fleamarket.service.ImageService;
import cn.fleamarket.utils.StringTool;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.Objects;
/**
 * 图片表
 *
 * @author znz
 * @date 2022-09-12 10:46:22
 */
@RestController
@RequestMapping("/image")
@Api("图片接口")
@CrossOrigin
public class ImageController {
    @Autowired
    ImageService imageService;
    @Autowired
    private PathConfig pathConfig;
    /**
     * 上传img
     *
     * @param file 文件
     * @return {@link JSONObject}
     */
    @SneakyThrows
    @PostMapping("/uploadImg")
    @ApiOperation("图片上传")
    public R<String> uploadImg(MultipartFile file) {
        JSONObject ret = new JSONObject();
        String fileName = file.getOriginalFilename();
        String newFileName = StringTool.getUUID() + Objects.requireNonNull(fileName).substring(fileName.indexOf("."));
        Image image = new Image();
        File file1;
        String os = System.getProperty("os.name");
        if (os.toLowerCase().startsWith("win")) {
            file1 = new File(pathConfig.getWinPath(), newFileName);
        } else {
            file1 = new File(pathConfig.getWinPath(), newFileName);
        }
        if (!file1.exists()) {
            System.out.println(file1.mkdir());
        }
        file.transferTo(file1);
        image.setId(StringTool.getUUID());
        image.setImgUrl(newFileName);
        imageService.insert(image);
        return R.ok(0,"图片上传成功",File.separator + "static" + File.separator + "img" + File.separator + image.getImgUrl());
    }
}
package cn.fleamarket.controller;
import cn.fleamarket.domain.Message;
import cn.fleamarket.domain.User;
import cn.fleamarket.service.MessageService;
import cn.fleamarket.service.UserService;
import cn.fleamarket.utils.StringTool;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 留言接口
 */
@RestController
@RequestMapping("/message")
@Api("留言接口")
public class MessageController {
    @Autowired
    MessageService messageService;
    @Autowired
    UserService userService;
    @PostMapping(value = "/messageList", produces = "application/json")
    @ApiOperation("分页查询留言列表,入参是page:第几页,number:每页几条,pId:属于哪个商品的id")
    public JSONObject messageList(@RequestBody JSONObject jsonObject) {
        JSONObject ret = new JSONObject();
        try {
            Long page = jsonObject.getLong("page");
            Long number = jsonObject.getLong("number");
            String pId = jsonObject.getString("pId");
            Map<String, Object> map = new HashMap<>();
            map.put("page", page);
            map.put("number", number);
            map.put("pId", pId);
            if (page != null && number != null) {
                Page<Message> messagePage = messageService.selectListPage(map);
                List<Message> messagesList = messagePage.getRecords();
                ret.put("code", 0);
                ret.put("data", StringTool.ListToJsonArray(messagesList));
                ret.put("total", messagePage.getTotal());//总数
                ret.put("next", messagePage.hasNext());//下一页
                ret.put("previous", messagePage.hasPrevious());//上一页
                ret.put("msg", "查询成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            ret.put("code", -1);
            ret.put("data", null);
            ret.put("msg", "查询失败");
        }
        return ret;
    }
    @PostMapping("/addMessage")
    @ApiOperation("新增留言接口,text:留言内容,tid:发送人(不用填),fid:接受人(填商品id)")
    public JSONObject addMessage(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
        JSONObject ret = new JSONObject();
        Message message = new Message();
        try {
            User user = userService.qureyByUserName(jsonObject.getString("username"));
            message.setTid(user.getId());
            message.setTime(new Date());
            message.setId(StringTool.getUUID());
            message.setFid(jsonObject.getString("fid"));
            message.setText(jsonObject.getString("text"));
            if (messageService.addMessage(message) > 0) {
                ret.put("code", 0);
                ret.put("data", true);
                ret.put("msg", "新增留言成功");
            } else {
                ret.put("code", -1);
                ret.put("data", false);
                ret.put("msg", "新增留言失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            ret.put("code", -1);
            ret.put("data", false);
            ret.put("msg", "新增留言失败");
        }
        return ret;
    }
    @PostMapping(value = "/messageListByUser", produces = "application/json")
    @ApiOperation("分页查询我的留言,入参是page:第几页,number:每页几条")
    public JSONObject productListByUser(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
        JSONObject ret = new JSONObject();
        try {
            Long page = jsonObject.getLong("page");
            Long number = jsonObject.getLong("number");
            Map<String, Object> map = new HashMap<>();
            User user = userService.qureyByUserName(jsonObject.getString("username"));
            map.put("page", page);
            map.put("number", number);
            map.put("userId", user.getId());
            if (page != null && number != null) {
                Page<Message> messagePage = messageService.selectListPageByUser(map);
                List<Message> messageList = messagePage.getRecords();
                ret.put("code", 0);
                  ret.put("data", StringTool.ListToJsonArray(messageList));
                ret.put("total", messagePage.getTotal());//总数
                ret.put("next", messagePage.hasNext());//下一页
                ret.put("previous", messagePage.hasPrevious());//上一页
                ret.put("msg", "查询成功");
            }
        } catch (Exception e) {
            ret.put("code", -1);
            ret.put("data", null);
            ret.put("msg", "查询失败");
            e.printStackTrace();
        }
        return ret;
    }
    @PostMapping("/delete")
    @ApiOperation("删除留言接口,主要传留言id即可")
    public JSONObject delete(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
        JSONObject ret = new JSONObject();
        String pId = jsonObject.getString("id");
        User user = null;
        try {
            user = userService.qureyByUserName(jsonObject.getString("username"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            int i = messageService.delete(user.getId(), pId);
            if (i > 0) {
                ret.put("code", "0");
                ret.put("data", true);
                ret.put("msg", "删除留言成功");
            } else {
                ret.put("code", "-1");
                ret.put("data", false)        ;
                ret.put("msg", "删除留言失败");
            }
        } catch (Exception e) {
            ret.put("code", "-1");
            ret.put("data", false);
            ret.put("msg", "删除留言失败");
            e.printStackTrace();
        }
        return ret;
    }
}

五,项目总结


相关文章
|
前端开发 Java 关系型数据库
基于Java+Springboot+Vue开发的鲜花商城管理系统源码+运行
基于Java+Springboot+Vue开发的鲜花商城管理系统(前后端分离),这是一项为大学生课程设计作业而开发的项目。该系统旨在帮助大学生学习并掌握Java编程技能,同时锻炼他们的项目设计与开发能力。通过学习基于Java的鲜花商城管理系统项目,大学生可以在实践中学习和提升自己的能力,为以后的职业发展打下坚实基础。技术学习共同进步
900 7
|
JavaScript 前端开发 Java
制造业ERP源码,工厂ERP管理系统,前端框架:Vue,后端框架:SpringBoot
这是一套基于SpringBoot+Vue技术栈开发的ERP企业管理系统,采用Java语言与vscode工具。系统涵盖采购/销售、出入库、生产、品质管理等功能,整合客户与供应商数据,支持在线协同和业务全流程管控。同时提供主数据管理、权限控制、工作流审批、报表自定义及打印、在线报表开发和自定义表单功能,助力企业实现高效自动化管理,并通过UniAPP实现移动端支持,满足多场景应用需求。
1310 1
|
11月前
|
前端开发 安全 Java
基于springboot+vue开发的会议预约管理系统
一个完整的会议预约管理系统,包含前端用户界面、管理后台和后端API服务。 ### 后端 - **框架**: Spring Boot 2.7.18 - **数据库**: MySQL 5.6+ - **ORM**: MyBatis Plus 3.5.3.1 - **安全**: Spring Security + JWT - **Java版本**: Java 11 ### 前端 - **框架**: Vue 3.3.4 - **UI组件**: Element Plus 2.3.8 - **构建工具**: Vite 4.4.5 - **状态管理**: Pinia 2.1.6 - **HTTP客户端
1476 4
基于springboot+vue开发的会议预约管理系统
|
前端开发 JavaScript Java
基于springboot+vue开发的校园食堂评价系统【源码+sql+可运行】【50809】
本系统基于SpringBoot与Vue3开发,实现校园食堂评价功能。前台支持用户注册登录、食堂浏览、菜品查看及评价发布;后台提供食堂、菜品与评价管理模块,支持权限控制与数据维护。技术栈涵盖SpringBoot、MyBatisPlus、Vue3、ElementUI等,适配响应式布局,提供完整源码与数据库脚本,可直接运行部署。
638 6
基于springboot+vue开发的校园食堂评价系统【源码+sql+可运行】【50809】
|
供应链 JavaScript BI
ERP系统源码,基于SpringBoot+Vue+ElementUI+UniAPP开发
这是一款专为小微企业打造的 SaaS ERP 管理系统,基于 SpringBoot+Vue+ElementUI+UniAPP 技术栈开发,帮助企业轻松上云。系统覆盖进销存、采购、销售、生产、财务、品质、OA 办公及 CRM 等核心功能,业务流程清晰且操作简便。支持二次开发与商用,提供自定义界面、审批流配置及灵活报表设计,助力企业高效管理与数字化转型。
991 2
ERP系统源码,基于SpringBoot+Vue+ElementUI+UniAPP开发
|
NoSQL JavaScript 应用服务中间件
node+mongo + vue 开发管理平台部署到阿里云服务器入坑之旅
导语:使用vue+element-ui开发前端,node.js+express+mongodb开发后端,部署到阿里云服务器(镜像信息Node.js)。 1、申请阿里云服务器 可以申请一个最便宜的用来练手。
3036 0
|
JavaScript Unix Linux
nvm与node.js的安装指南
通过以上步骤,你可以在各种操作系统上成功安装NVM和Node.js,从而在不同的项目中灵活切换Node.js版本。这种灵活性对于管理不同项目的环境依赖而言是非常重要的。
3814 11
|
存储 JavaScript 搜索推荐
Node框架的安装和配置方法
安装 Node 框架是进行 Node 开发的第一步,通过正确的安装和配置,可以为后续的开发工作提供良好的基础。在安装过程中,需要仔细阅读相关文档和提示,遇到问题及时解决,以确保安装顺利完成。
1302 155
|
弹性计算 JavaScript 前端开发
一键安装!阿里云新功能部署Nodejs环境到ECS竟然如此简单!
Node.js 是一种高效的 JavaScript 运行环境,基于 Chrome V8 引擎,支持在服务器端运行 JavaScript 代码。本文介绍如何在阿里云上一键部署 Node.js 环境,无需繁琐配置,轻松上手。前提条件包括 ECS 实例运行中且操作系统为 CentOS、Ubuntu 等。功能特点为一键安装和稳定性好,支持常用 LTS 版本。安装步骤简单:登录阿里云控制台,选择扩展程序管理页面,安装 Node.js 扩展,选择实例和版本,等待创建完成并验证安装成功。通过阿里云的公共扩展,初学者和经验丰富的开发者都能快速进入开发状态,开启高效开发之旅。
|
资源调度 JavaScript 前端开发
前端开发必备!Node.js 18.x LTS保姆级安装教程(附国内镜像源配置)
本文详细介绍了Node.js的安装与配置流程,涵盖环境准备、版本选择(推荐LTS版v18.x)、安装步骤(路径设置、组件选择)、环境验证(命令测试、镜像加速)及常见问题解决方法。同时推荐开发工具链,如VS Code、Yarn等,并提供常用全局包安装指南,帮助开发者快速搭建高效稳定的JavaScript开发环境。内容基于官方正版软件,确保合规性与安全性。
15990 23