基于Springboot开发实现二手交易商城
项目编号: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
*/public class CollectController {
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.进行取消收藏操作
*/
public ResultVo insertcollect({ 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.进行取消收藏操作
*/
public ResultVo deletecollect({ 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,"禁止操作");
} /**
* 分页查看用户所有收藏内容
* 前端传入页码、分页数量
* 查询分页数据
*/
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;public class IndexController { /**
* 网站首页
* */
public String index(){ return "/index";
} /**
* 联系我们
* */
public String contacts(){ return "/common/contacts";
} /**
* 关于我们
* */
public String about(){ return "/common/about";
} /**
* 后台管理首页
* */
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";
} /**
* 用户登录注册
* */
public String login(){ return "/user/logreg";
} /**
* 用户忘记密码
* */
public String forget(){ return "user/forget";
} /**
* 个人中心
* */
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";
} /**
* 用户修改密码
* */
public String userinfo(){ return "/user/updatepass";
} /**
* 用户更换手机号
* */
public String userphone(){ return "/user/updatephone";
} /**
* 用户商品列表
* */
public String userproduct(){ return "/user/product/productlist";
} /**
* 通知消息
* */
public String commonmessage(){ return "/user/message/message";
} /**
* 弹出式通知消息
* */
public String alertmessage(){ return "/user/message/alertmessage";
} /**
* 跳转到产品清单界面
* */
public String toproductlisting() { return "/common/product-listing";
} /**
* 跳转到产品清单搜索界面
* */
public String toProductSearchs(String keys, ModelMap modelMap) { if(keys==null){ return "/error/404";
}
modelMap.put("keys",keys); return "/common/product-search";
} /**用户个人中心默认展示图*/
public String homeconsole(){ return "/admin/home/console";
} /**
* 管理员首页默认展示图
* */
public String echars(){ return "/admin/echars/console";
}
public String appmessageindex(){ return "/admin/app/message/index";
} /**
* 用户收藏列表
* */
public String usercollect(){ return "/user/collect/collectlist";
} /**
* 用户售出记录
* */
public String sold(){ return "/user/sold/soldrecord";
} /**
* 销量列表
* */
public String adminSold(){ return "/admin/sold/soldrecord";
} /**
* 首页公告清单
* */
public String userNews(){ return "/common/listnews";
} /**
* 管理员公告列表
* */
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
*/public class NoticesController {
private NoticesService noticesService; /**
* 用户查看通知消息后
* 1.前端传入通知id(id)
* 2.将其设置为已读
* */
public ResultVo LookNoticesById ( { String id)Integer i = noticesService.updateNoticesById(id); if (i == 1){ return new ResultVo(true, StatusCode.OK,"设置成功");
} return new ResultVo(true, StatusCode.ERROR,"设置失败");
} /**
*查询前10条公告
* **/
public ResultVo queryNotices (HttpSession session){ String userid = (String) session.getAttribute("userid");
List<Notices> noticesList = noticesService.queryNotices(userid); return new ResultVo(true,StatusCode.OK,"查询成功",noticesList);
} /**
* 取消新通知标志
* 用户点击查看最新通知后会将所有通知设置为非最新通知
* */
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.返回分页数据
* */
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);
}
}
五,项目总结
项目前后端功能都有,比较完整,未实现在线支付功能,可以在此基础上来进行修改完善,项目结构简单清晰,修改方便,比较适合做毕业设计或课程设计使用。