基于Springboot開發(fā)實(shí)現(xiàn)二手交易商城
項(xiàng)目編號(hào):BS-XX-126
一,項(xiàng)目簡介
??? 本項(xiàng)目基于Springboot開發(fā)實(shí)現(xiàn),主要實(shí)現(xiàn)了一個(gè)二手交易的商城系統(tǒng),用戶注冊后可以實(shí)現(xiàn)在線售賣二手物品的功能,管理員主要實(shí)現(xiàn)對(duì)一些基本數(shù)據(jù)的管理功能。普通用戶的主要功能有:注冊登陸、發(fā)布商品信息、商品收藏管理、售出記錄管理、個(gè)人資料管理、前端信息查看展示、全文檢索、公告新聞查看等。管理員主要實(shí)現(xiàn)的功能有:用戶管理、公告管理、商品管理、銷售分析等功能。
二,環(huán)境介紹
語言環(huán)境:Java:? jdk1.8
數(shù)據(jù)庫:Mysql: mysql5.7
應(yīng)用服務(wù)器:Tomcat:? tomcat8.5.31
開發(fā)工具:IDEA或eclipse
前端開發(fā)技術(shù):Layui+Vuejs
后臺(tái)開發(fā)技術(shù):Springboot+Mybatis+Shiro
亮點(diǎn):使用Shiro進(jìn)行權(quán)限控制、使用Websocket實(shí)現(xiàn)信息發(fā)送、使用阿里云短信發(fā)送(SmsUtil中修改阿里云賬號(hào))、文件上傳(目錄為D:\campusshops\file)
三,系統(tǒng)展示
前端展示:

登陸注冊

商品詳情

個(gè)人中心

收藏管理

商品管理:可上傳圖片和展示視頻

消息通知:使用Websocktet

售出記錄

個(gè)人資料修改

管理員管理功能
用戶管理

商品清單

公告管理

銷售分析


四,核心代碼展示
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)、商品所在學(xué)校(school)
? ? * 2.session中獲取收藏用戶id(couserid)
? ? * 3.進(jìn)行收藏操作
? ? * (2). 取消收藏
? ? * 1.前端傳入商品id(commid)
? ? * 2.判斷是否本人取消收藏
? ? * 3.進(jìn)行取消收藏操作
? ? */
? ?
? ?
? ?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,"請(qǐng)先登錄");
? ? ? ?} ? ? ? ?if (colloperate == 1){ ? ? ? ? ? ?Collect collect1 = collectService.queryCollectStatus(collect); ? ? ? ? ? ?if(!StringUtils.isEmpty(collect1)){ ? ? ? ? ? ? ? ?/**更改原來的收藏信息和狀態(tài)*/
? ? ? ? ? ? ? ?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.進(jìn)行取消收藏操作
? ? */
? ?
? ?
? ?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,"禁止操作");
? ?} ? ?/**
? ? * 分頁查看用戶所有收藏內(nèi)容
? ? * 前端傳入頁碼、分頁數(shù)量
? ? * 查詢分頁數(shù)據(jù)
? ? */
? ?
? ?
? ?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 { ? ?/**
? ? * 網(wǎng)站首頁
? ? * */
? ?
? ?public String index(){ ? ? ? ?return "/index";
? ?} ? ?/**
? ? * 聯(lián)系我們
? ? * */
? ?
? ?public String contacts(){ ? ? ? ?return "/common/contacts";
? ?} ? ?/**
? ? * 關(guān)于我們
? ? * */
? ?
? ?public String about(){ ? ? ? ?return "/common/about";
? ?} ? ?/**
? ? * 后臺(tái)管理首頁
? ? * */
? ?
? ?public String adminindex(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException { ? ? ? ?String admin = (String) session.getAttribute("admin"); ? ? ? ?/**攔截器:如果不是管理員,則進(jìn)行重定向*/
? ? ? ?if (StringUtils.isEmpty(admin)){
? ? ? ? ? ?response.sendRedirect(request.getContextPath() + "/");//重定向
? ? ? ?} ? ? ? ?return "/admin/index";
? ?} ? ?/**
? ? * 用戶登錄注冊
? ? * */
? ?
? ?public String login(){ ? ? ? ?return "/user/logreg";
? ?} ? ?/**
? ? * 用戶忘記密碼
? ? * */
? ?
? ?public String forget(){ ? ? ? ?return "user/forget";
? ?} ? ?/**
? ? * 個(gè)人中心
? ? * */
? ?
? ?public String usercenter(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException { ? ? ? ?String userid = (String) session.getAttribute("userid"); ? ? ? ?/**攔截器:如果不是用戶角色登錄,則進(jìn)行重定向*/
? ? ? ?if (StringUtils.isEmpty(userid)){
? ? ? ? ? ?response.sendRedirect(request.getContextPath() + "/");//重定向
? ? ? ?} ? ? ? ?return "/user/user-center";
? ?} ? ?/**
? ? * 用戶修改密碼
? ? * */
? ?
? ?
? ?public String userinfo(){ ? ? ? ?return "/user/updatepass";
? ?} ? ?/**
? ? * 用戶更換手機(jī)號(hào)
? ? * */
? ?
? ?
? ?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";
? ?} ? ?/**
? ? * 跳轉(zhuǎn)到產(chǎn)品清單界面
? ? * */
? ?
? ?public String toproductlisting() { ? ? ? ?return "/common/product-listing";
? ?} ? ?/**
? ? * 跳轉(zhuǎn)到產(chǎn)品清單搜索界面
? ? * */
? ?
? ?public String toProductSearchs(String keys, ModelMap modelMap) { ? ? ? ?if(keys==null){ ? ? ? ? ? ?return "/error/404";
? ? ? ?}
? ? ? ?modelMap.put("keys",keys); ? ? ? ?return "/common/product-search";
? ?} ? ?/**用戶個(gè)人中心默認(rèn)展示圖*/
? ?
? ?public String homeconsole(){ ? ? ? ?return "/admin/home/console";
? ?} ? ?/**
? ? * 管理員首頁默認(rèn)展示圖
? ? * */
? ?
? ?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.將其設(shè)置為已讀
? ? * */
? ?
? ?
? ?public ResultVo LookNoticesById ( { ? ? ? ? String id)Integer i = noticesService.updateNoticesById(id); ? ? ? ?if (i == 1){ ? ? ? ? ? ?return new ResultVo(true, StatusCode.OK,"設(shè)置成功");
? ? ? ?} ? ? ? ?return new ResultVo(true, StatusCode.ERROR,"設(shè)置失敗");
? ?} ? ?/**
? ? *查詢前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);
? ?} ? ?/**
? ? * 取消新通知標(biāo)志
? ? * 用戶點(diǎn)擊查看最新通知后會(huì)將所有通知設(shè)置為非最新通知
? ? * */
? ?
? ?
? ?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,"設(shè)置成功");
? ? ? ?} ? ? ? ?return new ResultVo(true,StatusCode.ERROR,"設(shè)置失敗");
? ?} ? ?/**
? ? * 分類分頁查詢用戶所有通知消息
? ? * 1.前端傳入消息通知類型(tpname)
? ? * 2.session中獲取用戶id(userid)
? ? * 3.返回分頁數(shù)據(jù)
? ? * */
? ?
? ?
? ?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);
? ?}
}
五,項(xiàng)目總結(jié)
? ? ? ?項(xiàng)目前后端功能都有,比較完整,未實(shí)現(xiàn)在線支付功能,可以在此基礎(chǔ)上來進(jìn)行修改完善,項(xiàng)目結(jié)構(gòu)簡單清晰,修改方便,比較適合做畢業(yè)設(shè)計(jì)或課程設(shè)計(jì)使用。