基于Springboot开发实现二手交易商城

Posted 编程指南针

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于Springboot开发实现二手交易商城相关的知识,希望对你有一定的参考价值。

作者主页:编程指南针

作者简介:Java领域优质创作者、CSDN博客专家 、掘金特邀作者、多年架构师设计经验、腾讯课堂常驻讲师

主要内容:Java项目、毕业设计、简历模板、学习资料、面试题库、技术互助

文末获取源码 

项目编号:BS-XX-126

一,项目简介

    本项目基于Springboot开发实现,主要实现了一个二手交易的商城系统,用户注册后可以实现在线售卖二手物品的功能,管理员主要实现对一些基本数据的管理功能。普通用户的主要功能有:注册登陆、发布商品信息、商品收藏管理、售出记录管理、个人资料管理、前端信息查看展示、全文检索、公告新闻查看等。管理员主要实现的功能有:用户管理、公告管理、商品管理、销售分析等功能。

二,环境介绍

语言环境:Java:  jdk1.8

数据库:mysql: mysql5.7

应用服务器:Tomcat:  tomcat8.5.31

开发工具:IDEA或eclipse

前端开发技术:Layui+Vuejs

后台开发技术:Springboot+Mybatis+Shiro

亮点:使用Shiro进行权限控制、使用Websocket实现信息发送、使用阿里云短信发送(SmsUtil中修改阿里云账号)、文件上传(目录为D:\\campusshops\\file)

三,系统展示

前端展示:

登陆注册

商品详情

个人中心

收藏管理

商品管理:可上传图片和展示视频

消息通知:使用Websocktet

售出记录

个人资料修改

管理员管理功能

用户管理

商品清单

公告管理

销售分析

四,核心代码展示

package com.controller;


import com.entity.Collect;
import com.service.CollectService;
import com.util.GetDate;
import com.util.KeyUtil;
import com.util.StatusCode;
import com.vo.LayuiPageVo;
import com.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  收藏控制器
 * </p>
 *
 * @author znz
 * @since 2022-12-21
 */
@Controller
public class CollectController 
    @Autowired
    private CollectService collectService;

    /**
     * 商品详情界面:收藏商品or取消收藏
     * 前端传入收藏操作(colloperate:1收藏,2取消收藏),获取session中用户id信息,判断是否登录
     * (1). 收藏商品
     * 1.前端传入商品id(commid)、商品名(commname)、商品描述(commdesc)、商品用户id(cmuserid)
     *   商品用户名(username)、商品所在学校(school)
     * 2.session中获取收藏用户id(couserid)
     * 3.进行收藏操作
     * (2). 取消收藏
     * 1.前端传入商品id(commid)
     * 2.判断是否本人取消收藏
     * 3.进行取消收藏操作
     */
    @ResponseBody
    @PostMapping("/collect/operate")
    public ResultVo insertcollect(@RequestBody Collect collect, HttpSession session)
        String couserid = (String) session.getAttribute("userid");
        Integer colloperate = collect.getColloperate();
        collect.setCouserid(couserid);

        if (StringUtils.isEmpty(couserid))
            return new ResultVo(false, StatusCode.ACCESSERROR,"请先登录");
        

        if (colloperate == 1)
            Collect collect1 = collectService.queryCollectStatus(collect);
            if(!StringUtils.isEmpty(collect1))
                /**更改原来的收藏信息和状态*/
                collect1.setCommname(collect.getCommname()).setCommdesc(collect.getCommdesc()).setSchool(collect.getSchool())
                        .setSoldtime(GetDate.strToDate());
                Integer i = collectService.updateCollect(collect);
                if (i == 1)
                    return new ResultVo(true, StatusCode.OK,"收藏成功");
                
                return new ResultVo(false,StatusCode.ERROR,"收藏失败");
            else
                collect.setId(KeyUtil.genUniqueKey());
                Integer i = collectService.insertCollect(collect);
                if (i == 1)
                    return new ResultVo(true, StatusCode.OK,"收藏成功");
                
                return new ResultVo(false,StatusCode.ERROR,"收藏失败");
            

        else 
            Collect collect1 = collectService.queryCollectStatus(collect);
            /**判断是否为本人操作*/
            if (collect1.getCouserid().equals(couserid))
                Integer i = collectService.updateCollect(collect);
                if (i == 1)
                    return new ResultVo(true, StatusCode.OK,"取消成功");
                
                return new ResultVo(false,StatusCode.ERROR,"取消失败");
            
            return new ResultVo(false,StatusCode.ACCESSERROR,"禁止操作");
        
    

    /**
     * 收藏列表界面取消收藏
     * 1.前端传入收藏id(id)
     * 2.判断是否本人取消收藏
     * 3.进行取消收藏操作
     */
    @ResponseBody
    @PutMapping("/collect/delete/id")
    public ResultVo deletecollect(@PathVariable("id") String id,HttpSession session)
        String couserid = (String) session.getAttribute("userid");
        Collect collect = new Collect().setId(id).setCouserid(couserid);
        Collect collect1 = collectService.queryCollectStatus(collect);
        /**判断是否为本人操作*/
        if (collect1.getCouserid().equals(couserid))
            collect.setColloperate(2);
            Integer i = collectService.updateCollect(collect);
            if (i == 1)
                return new ResultVo(true, StatusCode.OK,"取消成功");
            
            return new ResultVo(false,StatusCode.ERROR,"取消失败");
        
        return new ResultVo(false,StatusCode.ACCESSERROR,"禁止操作");
    

    /**
     * 分页查看用户所有收藏内容
     * 前端传入页码、分页数量
     * 查询分页数据
     */
    @ResponseBody
    @GetMapping("/user/collect/queryall")
    public LayuiPageVo usercollect(int limit, int page, HttpSession session) 
        String couserid = (String) session.getAttribute("userid");
        List<Collect> collectList = collectService.queryAllCollect((page - 1) * limit, limit, couserid);
        Integer dataNumber = collectService.queryCollectCount(couserid);
        return new LayuiPageVo("",0,dataNumber,collectList);
    


package com.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class IndexController 
    /**
     * 网站首页
     * */
    @GetMapping("/")
    public String index()
        return "/index";
    

    /**
     * 联系我们
     * */
    @GetMapping("/contacts")
    public String contacts()
        return "/common/contacts";
    

    /**
     * 关于我们
     * */
    @GetMapping("/about")
    public String about()
        return "/common/about";
    

    /**
     * 后台管理首页
     * */
    @GetMapping("/admin/index")
    public String adminindex(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException 
        String admin = (String) session.getAttribute("admin");
        /**拦截器:如果不是管理员,则进行重定向*/
        if (StringUtils.isEmpty(admin))
            response.sendRedirect(request.getContextPath() + "/");//重定向
        
        return "/admin/index";
    

    /**
     * 用户登录注册
     * */
    @GetMapping("/login")
    public String login()
        return "/user/logreg";
    

    /**
     * 用户忘记密码
     * */
    @GetMapping("/forget")
    public String forget()
        return "user/forget";
    

    /**
     * 个人中心
     * */
    @GetMapping("/user/center")
    public String usercenter(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException 
        String userid = (String) session.getAttribute("userid");
        /**拦截器:如果不是用户角色登录,则进行重定向*/
        if (StringUtils.isEmpty(userid))
            response.sendRedirect(request.getContextPath() + "/");//重定向
        
        return "/user/user-center";
    

    /**
     * 用户修改密码
     * */
    @RequiresPermissions("user:userinfo")
    @GetMapping("/user/pass")
    public String userinfo()
        return "/user/updatepass";
    

    /**
     * 用户更换手机号
     * */
    @RequiresPermissions("user:userinfo")
    @GetMapping("/user/phone")
    public String userphone()
        return "/user/updatephone";
    

    /**
     * 用户商品列表
     * */
    @GetMapping("/user/product")
    public String userproduct()
        return "/user/product/productlist";
    

    /**
     * 通知消息
     * */
    @GetMapping("/user/message")
    public String commonmessage()
        return "/user/message/message";
    
    /**
     * 弹出式通知消息
     * */
    @GetMapping("/user/alertmessage")
    public String alertmessage()
        return "/user/message/alertmessage";
    
    /**
     * 跳转到产品清单界面
     * */
    @GetMapping("/product-listing")
    public String toproductlisting() 
        return "/common/product-listing";
    

    /**
     * 跳转到产品清单搜索界面
     * */
    @GetMapping("/product-search")
    public String toProductSearchs(String keys, ModelMap modelMap) 
        if(keys==null)
            return "/error/404";
        
        modelMap.put("keys",keys);
        return "/common/product-search";
    

    /**用户个人中心默认展示图*/
    @GetMapping("/home/console")
    public String homeconsole()
        return "/admin/home/console";
    

    /**
     * 管理员首页默认展示图
     * */
    @GetMapping("/echars/console")
    public String echars()
        return "/admin/echars/console";
    


    @GetMapping("/app/message/index")
    public String appmessageindex()
        return "/admin/app/message/index";
    

    /**
     * 用户收藏列表
     * */
    @GetMapping("/user/collect")
    public String usercollect()
        return "/user/collect/collectlist";
    

    /**
     * 用户售出记录
     * */
    @GetMapping("/user/sold")
    public String sold()
        return "/user/sold/soldrecord";
    

    /**
     * 销量列表
     * */
    @GetMapping("/admin/sold")
    public String adminSold()
        return "/admin/sold/soldrecord";
    

    /**
     * 首页公告清单
     * */
    @GetMapping("/user/newslist")
    public String userNews()
        return "/common/listnews";
    

    /**
     * 管理员公告列表
     * */
    @GetMapping("/admin/newslist")
    public String adminNews()
        return "/admin/news/newslist";
    

package com.controller;


import com.entity.Notices;
import com.service.NoticesService;
import com.util.StatusCode;
import com.vo.LayuiPageVo;
import com.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  消息通知控制器
 * </p>
 *
 * @author znz
 * @since 2022-12-25
 */
@Controller
public class NoticesController 
    @Autowired
    private NoticesService noticesService;

    /**
     * 用户查看通知消息后
     * 1.前端传入通知id(id)
     * 2.将其设置为已读
     * */
    @ResponseBody
    @PutMapping("/notices/look/id")
    public ResultVo LookNoticesById (@PathVariable("id") String id) 
        Integer i = noticesService.updateNoticesById(id);
        if (i == 1)
            return new ResultVo(true, StatusCode.OK,"设置成功");
        
        return new ResultVo(true, StatusCode.ERROR,"设置失败");
    

    /**
     *查询前10条公告
     * **/
    @ResponseBody
    @GetMapping("/notices/queryNotices")
    public ResultVo queryNotices (HttpSession session)
        String userid = (String) session.getAttribute("userid");
        List<Notices> noticesList = noticesService.queryNotices(userid);
        return new ResultVo(true,StatusCode.OK,"查询成功",noticesList);
    

    /**
     * 取消新通知标志
     * 用户点击查看最新通知后会将所有通知设置为非最新通知
     * */
    @ResponseBody
    @GetMapping("/notices/cancelLatest")
    public ResultVo CancelLatest (HttpSession session)
        String userid = (String) session.getAttribute("userid");
        Integer i = noticesService.CancelLatest(userid);
        if (i == 1)
            return new ResultVo(true,StatusCode.OK,"设置成功");
        
        return new ResultVo(true,StatusCode.ERROR,"设置失败");
    

    /**
     * 分类分页查询用户所有通知消息
     * 1.前端传入消息通知类型(tpname)
     * 2.session中获取用户id(userid)
     * 3.返回分页数据
     * */
    @ResponseBody
    @GetMapping("/notices/queryall")
    public LayuiPageVo queryallSold(int limit, int page, HttpSession session) 
        String userid = (String) session.getAttribute("userid");
        List<Notices> noticesList = noticesService.queryAllNotices((page - 1) * limit, limit, userid);
        Integer dataNumber = noticesService.queryNoticesCount(userid);
        return new LayuiPageVo("", 0,dataNumber,noticesList);
    



五,项目总结

       项目前后端功能都有,比较完整,未实现在线支付功能,可以在此基础上来进行修改完善,项目结构简单清晰,修改方便,比较适合做毕业设计或课程设计使用。

以上是关于基于Springboot开发实现二手交易商城的主要内容,如果未能解决你的问题,请参考以下文章

基于springboot电商生鲜购物商城平台设计与实现(含源码+数据库文件)

基于springboot在线购物书城商城设计与实现源码.rar(含源码及数据库文件)

基于Vue + SpringBoot实现的前后端分离的商城项目,包含秒杀模块(毕设)

springboot基于电脑商城的购物系统l.rar(项目源码+数据库文件)

计算机毕业设计之java+springboot基于vue的生鲜交易系统-生鲜商城网站

Java精品项目源码第106期嘟嘟二手书商城系统