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;
    }
}

五,项目总结


相关文章
|
21天前
|
监控 JavaScript Java
2025版基于springboot的校园打印社管理系统
本系统旨在解决传统校园打印社管理效率低、排队时间长、耗材管理难等问题,集成订单管理、设备监控、耗材统计、线上预约、自助打印与在线支付等功能,提升运营效率与用户体验,助力校园信息化建设。
|
2月前
|
前端开发 JavaScript Java
基于springboot+vue开发的校园食堂评价系统【源码+sql+可运行】【50809】
本系统基于SpringBoot与Vue3开发,实现校园食堂评价功能。前台支持用户注册登录、食堂浏览、菜品查看及评价发布;后台提供食堂、菜品与评价管理模块,支持权限控制与数据维护。技术栈涵盖SpringBoot、MyBatisPlus、Vue3、ElementUI等,适配响应式布局,提供完整源码与数据库脚本,可直接运行部署。
101 0
基于springboot+vue开发的校园食堂评价系统【源码+sql+可运行】【50809】
|
2月前
|
数据安全/隐私保护
springboot3 vue3校园失物招领系统实战开发
本项目基于SpringBoot3与Vue3开发全新校园失物招领系统,支持用户发布失物、招领信息,提供私信交流、物品领取、管理员管理功能,含详细角色设计与功能模块,适合学习参考。
|
10月前
|
JavaScript 关系型数据库 MySQL
基于VUE的校园二手交易平台系统设计与实现毕业设计论文模板
基于Vue的校园二手交易平台是一款专为校园用户设计的在线交易系统,提供简洁高效、安全可靠的二手商品买卖环境。平台利用Vue框架的响应式数据绑定和组件化特性,实现用户友好的界面,方便商品浏览、发布与管理。该系统采用Node.js、MySQL及B/S架构,确保稳定性和多功能模块设计,涵盖管理员和用户功能模块,促进物品循环使用,降低开销,提升环保意识,助力绿色校园文化建设。
|
10月前
|
存储 JavaScript 前端开发
基于 SpringBoot 和 Vue 开发校园点餐订餐外卖跑腿Java源码
一个非常实用的校园外卖系统,基于 SpringBoot 和 Vue 的开发。这一系统源于黑马的外卖案例项目 经过站长的进一步改进和优化,提供了更丰富的功能和更高的可用性。 这个项目的架构设计非常有趣。虽然它采用了SpringBoot和Vue的组合,但并不是一个完全分离的项目。 前端视图通过JS的方式引入了Vue和Element UI,既能利用Vue的快速开发优势,
360 13
|
11月前
|
JavaScript NoSQL Java
CC-ADMIN后台简介一个基于 Spring Boot 2.1.3 、SpringBootMybatis plus、JWT、Shiro、Redis、Vue quasar 的前后端分离的后台管理系统
CC-ADMIN后台简介一个基于 Spring Boot 2.1.3 、SpringBootMybatis plus、JWT、Shiro、Redis、Vue quasar 的前后端分离的后台管理系统
288 0
|
开发者 Java 存储
JSF 与 CDI 携手共进,紧跟技术热点,激发开发者情感共鸣,开启高效开发新征程
【8月更文挑战第31天】JavaServer Faces (JSF) 与 Contexts and Dependency Injection (CDI) 在 Java EE 领域中紧密协作,助力开发者高效构建现代 Web 应用。JSF 凭借其丰富的组件库和页面导航功能受到青睐,而 CDI 则优雅地管理对象生命周期并实现依赖注入。两者结合,不仅简化了复杂企业应用的开发,还实现了松耦合架构,增强了代码的灵活性、可维护性和可扩展性。通过示例展示了如何利用 CDI 将业务服务对象注入 JSF Managed Bean,以及如何在不同页面间共享数据,突显了这一组合的强大功能。
118 0
|
18天前
|
JavaScript
Vue中如何实现兄弟组件之间的通信
在Vue中,兄弟组件可通过父组件中转、事件总线、Vuex/Pinia或provide/inject实现通信。小型项目推荐父组件中转或事件总线,大型项目建议使用Pinia等状态管理工具,确保数据流清晰可控,避免内存泄漏。
152 2
|
4月前
|
人工智能 JavaScript 算法
Vue 中 key 属性的深入解析:改变 key 导致组件销毁与重建
Vue 中 key 属性的深入解析:改变 key 导致组件销毁与重建
584 0
|
4月前
|
JavaScript UED
用组件懒加载优化Vue应用性能
用组件懒加载优化Vue应用性能