• 基于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

    售出记录

    个人资料修改

    管理员管理功能

    用户管理

    商品清单

    公告管理

    销售分析

    四,核心代码展示

    1. package com.controller;
    2. import com.entity.Collect;
    3. import com.service.CollectService;
    4. import com.util.GetDate;
    5. import com.util.KeyUtil;
    6. import com.util.StatusCode;
    7. import com.vo.LayuiPageVo;
    8. import com.vo.ResultVo;
    9. import org.springframework.beans.factory.annotation.Autowired;
    10. import org.springframework.stereotype.Controller;
    11. import org.springframework.util.StringUtils;
    12. import org.springframework.web.bind.annotation.*;
    13. import javax.servlet.http.HttpSession;
    14. import java.util.List;
    15. /**
    16. *

    17. * 收藏控制器
    18. *

    19. *
    20. * @author znz
    21. * @since 2022-12-21
    22. */
    23. @Controller
    24. public class CollectController {
    25. @Autowired
    26. private CollectService collectService;
    27. /**
    28. * 商品详情界面:收藏商品or取消收藏
    29. * 前端传入收藏操作(colloperate:1收藏,2取消收藏),获取session中用户id信息,判断是否登录
    30. * (1). 收藏商品
    31. * 1.前端传入商品id(commid)、商品名(commname)、商品描述(commdesc)、商品用户id(cmuserid)
    32. * 商品用户名(username)、商品所在学校(school)
    33. * 2.session中获取收藏用户id(couserid)
    34. * 3.进行收藏操作
    35. * (2). 取消收藏
    36. * 1.前端传入商品id(commid)
    37. * 2.判断是否本人取消收藏
    38. * 3.进行取消收藏操作
    39. */
    40. @ResponseBody
    41. @PostMapping("/collect/operate")
    42. public ResultVo insertcollect(@RequestBody Collect collect, HttpSession session){
    43. String couserid = (String) session.getAttribute("userid");
    44. Integer colloperate = collect.getColloperate();
    45. collect.setCouserid(couserid);
    46. if (StringUtils.isEmpty(couserid)){
    47. return new ResultVo(false, StatusCode.ACCESSERROR,"请先登录");
    48. }
    49. if (colloperate == 1){
    50. Collect collect1 = collectService.queryCollectStatus(collect);
    51. if(!StringUtils.isEmpty(collect1)){
    52. /**更改原来的收藏信息和状态*/
    53. collect1.setCommname(collect.getCommname()).setCommdesc(collect.getCommdesc()).setSchool(collect.getSchool())
    54. .setSoldtime(GetDate.strToDate());
    55. Integer i = collectService.updateCollect(collect);
    56. if (i == 1){
    57. return new ResultVo(true, StatusCode.OK,"收藏成功");
    58. }
    59. return new ResultVo(false,StatusCode.ERROR,"收藏失败");
    60. }else{
    61. collect.setId(KeyUtil.genUniqueKey());
    62. Integer i = collectService.insertCollect(collect);
    63. if (i == 1){
    64. return new ResultVo(true, StatusCode.OK,"收藏成功");
    65. }
    66. return new ResultVo(false,StatusCode.ERROR,"收藏失败");
    67. }
    68. }else {
    69. Collect collect1 = collectService.queryCollectStatus(collect);
    70. /**判断是否为本人操作*/
    71. if (collect1.getCouserid().equals(couserid)){
    72. Integer i = collectService.updateCollect(collect);
    73. if (i == 1){
    74. return new ResultVo(true, StatusCode.OK,"取消成功");
    75. }
    76. return new ResultVo(false,StatusCode.ERROR,"取消失败");
    77. }
    78. return new ResultVo(false,StatusCode.ACCESSERROR,"禁止操作");
    79. }
    80. }
    81. /**
    82. * 收藏列表界面取消收藏
    83. * 1.前端传入收藏id(id)
    84. * 2.判断是否本人取消收藏
    85. * 3.进行取消收藏操作
    86. */
    87. @ResponseBody
    88. @PutMapping("/collect/delete/{id}")
    89. public ResultVo deletecollect(@PathVariable("id") String id,HttpSession session){
    90. String couserid = (String) session.getAttribute("userid");
    91. Collect collect = new Collect().setId(id).setCouserid(couserid);
    92. Collect collect1 = collectService.queryCollectStatus(collect);
    93. /**判断是否为本人操作*/
    94. if (collect1.getCouserid().equals(couserid)){
    95. collect.setColloperate(2);
    96. Integer i = collectService.updateCollect(collect);
    97. if (i == 1){
    98. return new ResultVo(true, StatusCode.OK,"取消成功");
    99. }
    100. return new ResultVo(false,StatusCode.ERROR,"取消失败");
    101. }
    102. return new ResultVo(false,StatusCode.ACCESSERROR,"禁止操作");
    103. }
    104. /**
    105. * 分页查看用户所有收藏内容
    106. * 前端传入页码、分页数量
    107. * 查询分页数据
    108. */
    109. @ResponseBody
    110. @GetMapping("/user/collect/queryall")
    111. public LayuiPageVo usercollect(int limit, int page, HttpSession session) {
    112. String couserid = (String) session.getAttribute("userid");
    113. List collectList = collectService.queryAllCollect((page - 1) * limit, limit, couserid);
    114. Integer dataNumber = collectService.queryCollectCount(couserid);
    115. return new LayuiPageVo("",0,dataNumber,collectList);
    116. }
    117. }

    1. package com.controller;
    2. import org.apache.shiro.authz.annotation.RequiresPermissions;
    3. import org.springframework.stereotype.Controller;
    4. import org.springframework.ui.ModelMap;
    5. import org.springframework.util.StringUtils;
    6. import org.springframework.web.bind.annotation.GetMapping;
    7. import javax.servlet.http.HttpServletRequest;
    8. import javax.servlet.http.HttpServletResponse;
    9. import javax.servlet.http.HttpSession;
    10. import java.io.IOException;
    11. @Controller
    12. public class IndexController {
    13. /**
    14. * 网站首页
    15. * */
    16. @GetMapping("/")
    17. public String index(){
    18. return "/index";
    19. }
    20. /**
    21. * 联系我们
    22. * */
    23. @GetMapping("/contacts")
    24. public String contacts(){
    25. return "/common/contacts";
    26. }
    27. /**
    28. * 关于我们
    29. * */
    30. @GetMapping("/about")
    31. public String about(){
    32. return "/common/about";
    33. }
    34. /**
    35. * 后台管理首页
    36. * */
    37. @GetMapping("/admin/index")
    38. public String adminindex(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException {
    39. String admin = (String) session.getAttribute("admin");
    40. /**拦截器:如果不是管理员,则进行重定向*/
    41. if (StringUtils.isEmpty(admin)){
    42. response.sendRedirect(request.getContextPath() + "/");//重定向
    43. }
    44. return "/admin/index";
    45. }
    46. /**
    47. * 用户登录注册
    48. * */
    49. @GetMapping("/login")
    50. public String login(){
    51. return "/user/logreg";
    52. }
    53. /**
    54. * 用户忘记密码
    55. * */
    56. @GetMapping("/forget")
    57. public String forget(){
    58. return "user/forget";
    59. }
    60. /**
    61. * 个人中心
    62. * */
    63. @GetMapping("/user/center")
    64. public String usercenter(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException {
    65. String userid = (String) session.getAttribute("userid");
    66. /**拦截器:如果不是用户角色登录,则进行重定向*/
    67. if (StringUtils.isEmpty(userid)){
    68. response.sendRedirect(request.getContextPath() + "/");//重定向
    69. }
    70. return "/user/user-center";
    71. }
    72. /**
    73. * 用户修改密码
    74. * */
    75. @RequiresPermissions("user:userinfo")
    76. @GetMapping("/user/pass")
    77. public String userinfo(){
    78. return "/user/updatepass";
    79. }
    80. /**
    81. * 用户更换手机号
    82. * */
    83. @RequiresPermissions("user:userinfo")
    84. @GetMapping("/user/phone")
    85. public String userphone(){
    86. return "/user/updatephone";
    87. }
    88. /**
    89. * 用户商品列表
    90. * */
    91. @GetMapping("/user/product")
    92. public String userproduct(){
    93. return "/user/product/productlist";
    94. }
    95. /**
    96. * 通知消息
    97. * */
    98. @GetMapping("/user/message")
    99. public String commonmessage(){
    100. return "/user/message/message";
    101. }
    102. /**
    103. * 弹出式通知消息
    104. * */
    105. @GetMapping("/user/alertmessage")
    106. public String alertmessage(){
    107. return "/user/message/alertmessage";
    108. }
    109. /**
    110. * 跳转到产品清单界面
    111. * */
    112. @GetMapping("/product-listing")
    113. public String toproductlisting() {
    114. return "/common/product-listing";
    115. }
    116. /**
    117. * 跳转到产品清单搜索界面
    118. * */
    119. @GetMapping("/product-search")
    120. public String toProductSearchs(String keys, ModelMap modelMap) {
    121. if(keys==null){
    122. return "/error/404";
    123. }
    124. modelMap.put("keys",keys);
    125. return "/common/product-search";
    126. }
    127. /**用户个人中心默认展示图*/
    128. @GetMapping("/home/console")
    129. public String homeconsole(){
    130. return "/admin/home/console";
    131. }
    132. /**
    133. * 管理员首页默认展示图
    134. * */
    135. @GetMapping("/echars/console")
    136. public String echars(){
    137. return "/admin/echars/console";
    138. }
    139. @GetMapping("/app/message/index")
    140. public String appmessageindex(){
    141. return "/admin/app/message/index";
    142. }
    143. /**
    144. * 用户收藏列表
    145. * */
    146. @GetMapping("/user/collect")
    147. public String usercollect(){
    148. return "/user/collect/collectlist";
    149. }
    150. /**
    151. * 用户售出记录
    152. * */
    153. @GetMapping("/user/sold")
    154. public String sold(){
    155. return "/user/sold/soldrecord";
    156. }
    157. /**
    158. * 销量列表
    159. * */
    160. @GetMapping("/admin/sold")
    161. public String adminSold(){
    162. return "/admin/sold/soldrecord";
    163. }
    164. /**
    165. * 首页公告清单
    166. * */
    167. @GetMapping("/user/newslist")
    168. public String userNews(){
    169. return "/common/listnews";
    170. }
    171. /**
    172. * 管理员公告列表
    173. * */
    174. @GetMapping("/admin/newslist")
    175. public String adminNews(){
    176. return "/admin/news/newslist";
    177. }
    178. }

    1. package com.controller;
    2. import com.entity.Notices;
    3. import com.service.NoticesService;
    4. import com.util.StatusCode;
    5. import com.vo.LayuiPageVo;
    6. import com.vo.ResultVo;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.stereotype.Controller;
    9. import org.springframework.web.bind.annotation.GetMapping;
    10. import org.springframework.web.bind.annotation.PathVariable;
    11. import org.springframework.web.bind.annotation.PutMapping;
    12. import org.springframework.web.bind.annotation.ResponseBody;
    13. import javax.servlet.http.HttpSession;
    14. import java.util.List;
    15. /**
    16. *

    17. * 消息通知控制器
    18. *

    19. *
    20. * @author znz
    21. * @since 2022-12-25
    22. */
    23. @Controller
    24. public class NoticesController {
    25. @Autowired
    26. private NoticesService noticesService;
    27. /**
    28. * 用户查看通知消息后
    29. * 1.前端传入通知id(id)
    30. * 2.将其设置为已读
    31. * */
    32. @ResponseBody
    33. @PutMapping("/notices/look/{id}")
    34. public ResultVo LookNoticesById (@PathVariable("id") String id) {
    35. Integer i = noticesService.updateNoticesById(id);
    36. if (i == 1){
    37. return new ResultVo(true, StatusCode.OK,"设置成功");
    38. }
    39. return new ResultVo(true, StatusCode.ERROR,"设置失败");
    40. }
    41. /**
    42. *查询前10条公告
    43. * **/
    44. @ResponseBody
    45. @GetMapping("/notices/queryNotices")
    46. public ResultVo queryNotices (HttpSession session){
    47. String userid = (String) session.getAttribute("userid");
    48. List noticesList = noticesService.queryNotices(userid);
    49. return new ResultVo(true,StatusCode.OK,"查询成功",noticesList);
    50. }
    51. /**
    52. * 取消新通知标志
    53. * 用户点击查看最新通知后会将所有通知设置为非最新通知
    54. * */
    55. @ResponseBody
    56. @GetMapping("/notices/cancelLatest")
    57. public ResultVo CancelLatest (HttpSession session){
    58. String userid = (String) session.getAttribute("userid");
    59. Integer i = noticesService.CancelLatest(userid);
    60. if (i == 1){
    61. return new ResultVo(true,StatusCode.OK,"设置成功");
    62. }
    63. return new ResultVo(true,StatusCode.ERROR,"设置失败");
    64. }
    65. /**
    66. * 分类分页查询用户所有通知消息
    67. * 1.前端传入消息通知类型(tpname)
    68. * 2.session中获取用户id(userid)
    69. * 3.返回分页数据
    70. * */
    71. @ResponseBody
    72. @GetMapping("/notices/queryall")
    73. public LayuiPageVo queryallSold(int limit, int page, HttpSession session) {
    74. String userid = (String) session.getAttribute("userid");
    75. List noticesList = noticesService.queryAllNotices((page - 1) * limit, limit, userid);
    76. Integer dataNumber = noticesService.queryNoticesCount(userid);
    77. return new LayuiPageVo("", 0,dataNumber,noticesList);
    78. }
    79. }

    五,项目总结

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

  • 相关阅读:
    字节与字符与常见编码方式
    知识点滴 - 英语词汇
    SprIngSecurity实战(二)各种架构中所应用的安全性
    连接命令文件.cmd
    学习C语言的好处:
    腾讯智影数字人工具
    解放双手,推荐一款阿里开源的低代码工具,YYDS
    springboot 多线程实现
    对人脸图像进行性别和年龄的判断
    使用 B+ 树 or 使用跳表?
  • 原文地址:https://blog.csdn.net/whirlwind526/article/details/126071630