源码获取:俺的博客首页 "资源" 里下载!
项目介绍
基于SpringBoot Vue的校园闲置物品租售系统
角色:管理员、用户、卖家
管理员;管理员使用本系统涉到的功能主要有:首页、个人中心、用户管理、卖家管理、商品种类管理、商品信息管理商品租借管理
商品购买管理、闲置鱼塘、系统管理。
用户:主要包括用户、登录、注册首页、个人中心、限制鱼塘、校园资讯、后台管理、商品租借管理、商品购买管理、我的收藏管理。
卖家;卖家、首页、个人中心、商品种类管理、商品信息管理、商品租借管理、商品购买管理、我的收藏管理。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
4.数据库:MySql 5.7/8.0版本均可;
5.是否Maven项目:是;
技术栈
后端:SpringBoot+Mybaits
前端:layui+Vue+ELementUI;
使用说明
项目运行:
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入项目地址:http://localhost:8080/springboot56c50/front/index.html
5. 管理员用户名密码:abo/abo
普通用户名密码:用户1/123456
卖家用户名密码:卖家1/123456
管理员控制层:
@Controller
@RequestMapping(value = "admin")
public class AdminController {
private final UserService userService;
private final GoodService goodService;
private final TypeService typeService;
private final OrderService orderService;
@Autowired
public AdminController(UserService userService, GoodService goodService, TypeService typeService, OrderService orderService) {
this.userService = userService;
this.goodService = goodService;
this.typeService = typeService;
this.orderService = orderService;
}
@RequestMapping(value = "/adminLogin", method = RequestMethod.GET)
public String getAdminLogin(){
return "admin/adminLogin";
}
@RequestMapping(value = "/adminLogin", method = RequestMethod.POST)
public String postAdminLogin(ModelMap model,
@RequestParam(value = "email", required = false) String email,
@RequestParam(value = "password", required = false) String password,
HttpSession session) {
User admin = userService.getUserByEmail(email);
String message;
if (admin != null){
String mdsPass = DigestUtils.md5DigestAsHex((password + admin.getCode()).getBytes());
// if (!mdsPass .equals(admin.getPassword())){
// message = "用户密码错误!";
// }
if (!password .equals(admin.getPassword())){
message = "用户密码错误!";
} else if (admin.getRoleId() != 101){
message = "用户没有权限访问!";
} else {
session.setAttribute("admin",admin);
return "redirect:/admin/adminPage";
}
} else {
message = "用户不存在!";
}
model.addAttribute("message", message);
return "admin/adminLogin";
}
@RequestMapping(value = "/adminLogout", method = RequestMethod.GET)
public String adminLogout(@RequestParam(required = false, defaultValue = "false" )String adminLogout, HttpSession session){
if (adminLogout.equals("true")){
session.removeAttribute("admin");
}
// adminLogout = "false";
return "redirect:/";
}
@RequestMapping(value = "/adminPage", method = RequestMethod.GET)
public String getAdminPage(ModelMap model,
HttpSession session){
User admin = (User) session.getAttribute("admin");
if (admin == null){
return "redirect:/admin/adminLogin";
}
List<Good> goodList = goodService.getAllGoodList();
for (Good good : goodList) {
good.setGoodUser(userService.getUserById(good.getUserId()));
good.setGoodSecondType(typeService.getSecondTypeById(good.getSecondTypeId()));
}
List<User> userList = userService.getAllUser();
List<FirstType> firstTypeList = typeService.getAllFirstType();
List<Order> orderList = orderService.getOrderList();
model.addAttribute("goodList", goodList);
model.addAttribute("userList", userList);
model.addAttribute("firstTypeList", firstTypeList);
model.addAttribute("orderList", orderList);
return "admin/adminPage";
}
@RequestMapping(value = "/user/update/status/{statusId}&{userId}", method = RequestMethod.GET)
public ResponseEntity updateUserStatus(@PathVariable Integer statusId,
@PathVariable Integer userId){
Boolean success = userService.updateUserStatus(statusId, userId);
if (success){
List<User> userList = userService.getAllUser();
return ResponseEntity.ok(userList);
}
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/user/delete/{userId}", method = RequestMethod.GET)
public ResponseEntity deleteUser(@PathVariable Integer userId){
Boolean success = userService.deleteUser(userId);
if (success){
List<User> userList = userService.getAllUser();
return ResponseEntity.ok(userList);
}
return ResponseEntity.ok(success);
}
}
商品控制层:
@Controller
public class GoodController {
private final GoodService goodService;
private final TypeService typeService;
private final ReviewService reviewService;
private final UserService userService;
private final ImageService imageService;
private final CollectService collectService;
private static String message = "";
@Autowired
public GoodController(GoodService goodService, TypeService typeService,
ReviewService reviewService, UserService userService,
ImageService imageService, CollectService collectService) {
this.goodService = goodService;
this.typeService = typeService;
this.reviewService = reviewService;
this.userService = userService;
this.imageService = imageService;
this.collectService = collectService;
}
@RequestMapping(value = "/", method = RequestMethod.GET)
public String getHomeGoods(
ModelMap model,
@RequestParam(required = false, defaultValue = "") String searchText,
@RequestParam(required = false) Integer secondTypeId,
@RequestParam(required = false, defaultValue = "0") int offset,
@RequestParam(required = false, defaultValue = "40") int limit) {
List<Good> goods = goodService.getGoodsBySearchAndType(searchText,
secondTypeId, offset, limit);
double goodsNum = goodService.getGoodsBySearchAndTypeCount(searchText,
secondTypeId);
List<FirstType> firstTypes = typeService.getAllFirstType();
for (FirstType firstType : firstTypes) {
firstType.setSecondType(typeService
.getSecondTypeByFirstTypeId(firstType.getId()));
}
model.addAttribute("firstTypes", firstTypes);
model.addAttribute("goods", goods);
model.addAttribute("pages", Math.ceil(goodsNum / limit));
model.addAttribute("goodsNum", goodsNum);
model.addAttribute("offset", offset);
model.addAttribute("limit", limit);
return "home/homeGoods";
}
@RequestMapping(value = "/goods/goodInfo", method = RequestMethod.GET)
public String getGoodInfo(ModelMap model, HttpSession httpSession,
@RequestParam(required = false) Integer goodId) {
Good goodInfo = goodService.getGoodById(goodId);
if (goodInfo == null) {
return "goods/error";
}
Integer collect = 1;
User user = (User) httpSession.getAttribute("user");
if (user == null) {
collect = 0;
} else {
if (collectService.getCollect(goodId, user.getId())) {
collect = 2;
}
}
List<Image> images = imageService.getImageByGoodId(goodId);
User goodUser = userService.getUserById(goodInfo.getUserId());
goodInfo.setGoodUser(userService.getUserById(goodInfo.getUserId()));
goodInfo.setGoodSecondType(typeService.getSecondTypeById(goodInfo
.getSecondTypeId()));
List<Review> reviews = reviewService.gerReviewByGoodId(goodId);
for (Review review : reviews) {
review.setReplys(reviewService.gerReplyByReviewId(review.getId()));
}
List<Good> goods = goodService.getRECGoods(goodInfo.getSecondTypeId(),
goodInfo.getId());
model.addAttribute("message", message);
model.addAttribute("reviews", reviews);
model.addAttribute("goodInfo", goodInfo);
model.addAttribute("images", images);
model.addAttribute("goodUser", goodUser);
model.addAttribute("goods", goods);
model.addAttribute("collect", collect);
message = "";
return "goods/goodInfo";
}
@RequestMapping(value = "/goods/goodInfo", method = RequestMethod.POST)
public String putReview(
@RequestParam(value = "goodId", required = false) Integer goodId,
@RequestParam(value = "reviewId", required = false) Integer reviewId,
@RequestParam(value = "fromUserId", required = false) Integer fromUserId,
@RequestParam(value = "toUserId", required = false) Integer toUserId,
@RequestParam(value = "fromUser", required = false) String fromUser,
@RequestParam(value = "toUser", required = false) String toUser,
@RequestParam(value = "replyText", required = false, defaultValue = "") String replyText,
@RequestParam(value = "reviewText", required = false, defaultValue = "") String reviewText) {
if (reviewText.equals("")) {
if (replyText.equals("")) {
message = "内容不能为空!";
return "redirect:/goods/goodInfo?goodId=" + goodId;
} else {
Reply reply = new Reply();
reply.setReviewId(reviewId);
reply.setFromUser(fromUser);
reply.setFromUserId(fromUserId);
reply.setToUser(toUser);
reply.setToUserId(toUserId);
reply.setText(replyText);
if (reviewService.insertReply(reply) == 1) {
message = "回复成功!";
return "redirect:/goods/goodInfo?goodId=" + goodId;
} else {
message = "回复失败!";
return "redirect:/goods/goodInfo?goodId=" + goodId;
}
}
} else {
Review review = new Review();
review.setGoodId(goodId);
review.setFromUser(fromUser);
review.setFromUserId(fromUserId);
review.setToUserId(toUserId);
review.setText(reviewText);
if (reviewService.insertReview(review) == 1) {
message = "评论成功!";
return "redirect:/goods/goodInfo?goodId=" + goodId;
} else {
message = "评论失败!";
return "redirect:/goods/goodInfo?goodId=" + goodId;
}
}
}
@RequestMapping(value = "/goods/publishGood", method = RequestMethod.GET)
public String getPublishGood(ModelMap model, HttpSession session) {
User user = (User) session.getAttribute("user");
if (user == null) {
return "redirect:/";
}
Good good = new Good();
List<FirstType> firstTypes = typeService.getAllFirstType();
List<Good> goods = goodService.getAllGoods(0, 5);
model.addAttribute("goods", goods);
model.addAttribute("good", good);
model.addAttribute("firstTypes", firstTypes);
return "goods/publishGood";
}
@RequestMapping(value = "/goods/publishGood", method = RequestMethod.POST)
public String getGoodId(ModelMap model, HttpSession session,
@Valid Good good) {
List<FirstType> firstTypes = typeService.getAllFirstType();
User user = (User) session.getAttribute("user");
List<Good> goods = goodService.getAllGoods(0, 5);
good.setUserId(user.getId());
good.setPhotoUrl("/statics/image/goods/default/nophoto.png");
if (goodService.insertGood(good) != 1) {
System.out.println("插入物品失败!");
}
model.addAttribute("goods", goods);
model.addAttribute("good", good);
model.addAttribute("firstTypes", firstTypes);
return "goods/publishGood";
}
@RequestMapping(value = "/goods/publishGood/uploadImage", method = RequestMethod.POST)
public String uploadImage(
HttpSession session,
@RequestParam(value = "goodId", required = false) Integer goodId,
@RequestParam(value = "mainFile", required = false) MultipartFile mainFile,
@RequestParam(value = "file", required = false) MultipartFile[] file)
throws IOException {
User user = (User) session.getAttribute("user");
FileCheck fileCheck = new FileCheck();
RandomString randomString = new RandomString();
String filePath = "/statics/image/goods/" + user.getId() + "/" + goodId;
String pathRoot = fileCheck.checkGoodFolderExist(filePath);
String name;
if (!mainFile.isEmpty()) {
String fileName = goodId + randomString.getRandomString(10);
String contentType = mainFile.getContentType();
String imageName = contentType
.substring(contentType.indexOf("/") + 1);
name = fileName + "." + imageName;
mainFile.transferTo(new File(pathRoot + name));
String photoUrl = filePath + "/" + name;
goodService.updateGoodPhotoUrl(photoUrl, goodId);
}
for (MultipartFile mf : file) {
if (!mf.isEmpty()) {
// 生成uuid作为文件名称
String fileName = goodId + randomString.getRandomString(10);
// 获得文件类型(可以判断如果不是图片,禁止上传)
String contentType = mf.getContentType();
// 获得文件后缀名称
String imageName = contentType.substring(contentType
.indexOf("/") + 1);
name = fileName + "." + imageName;
System.out.println("name:" + name);
mf.transferTo(new File(pathRoot + name));
Image image = new Image();
image.setGoodId(goodId);
image.setName(name);
image.setUrl(filePath + "/" + name);
imageService.insertImage(image);
} else {
System.out.println("文件为空!");
}
}
return "redirect:/goods/goodInfo?goodId=" + goodId;
}
@RequestMapping(value = "/goods/userGoods", method = RequestMethod.GET)
public String getUserGoods(ModelMap model,
@RequestParam(value = "userId", required = false) Integer userId) {
User user = userService.getUserById(userId);
List<Good> userGoods = goodService.getGoodStatusByUserId(userId);
List<Good> goods = goodService.getAllGoods(0, 4);
model.addAttribute("user", user);
model.addAttribute("userGoods", userGoods);
model.addAttribute("goods", goods);
return "goods/userGood";
}
@RequestMapping(value = "/goods/userGoodEdit", method = RequestMethod.GET)
public String getUserGoodEdit(ModelMap model,
@RequestParam(value = "goodId", required = false) Integer goodId,
HttpSession session) {
User user = (User) session.getAttribute("user");
if (user == null) {
return "redirect:/";
}
Good good = goodService.getGoodById(goodId);
List<FirstType> firstTypes = typeService.getAllFirstType();
List<Good> goods = goodService.getAllGoods(0, 5);
List<Image> goodImages = imageService.getImageByGoodId(goodId);
model.addAttribute("goods", goods);
model.addAttribute("good", good);
model.addAttribute("goodImages", goodImages);
model.addAttribute("firstTypes", firstTypes);
return "goods/userGoodEdit";
}
@RequestMapping(value = "/goods/userGoodEdit", method = RequestMethod.POST)
public String postGoodEdit(ModelMap model, HttpSession session,
@Valid Good good) {
List<FirstType> firstTypes = typeService.getAllFirstType();
User user = (User) session.getAttribute("user");
if (user == null) {
return "redirect:/";
}
List<Good> goods = goodService.getAllGoods(0, 5);
if (!(goodService.updateGood(good) > 0)) {
System.out.println("修改物品失败!");
}
List<Image> goodImages = imageService.getImageByGoodId(good.getId());
model.addAttribute("goods", goods);
model.addAttribute("good", good);
model.addAttribute("goodImages", goodImages);
model.addAttribute("firstTypes", firstTypes);
return "goods/userGoodEdit";
}
@RequestMapping(value = "/goods/userGoodEdit/updateImage", method = RequestMethod.POST)
public String updateImage(
HttpSession session,
@RequestParam(value = "goodId", required = false) Integer goodId,
@RequestParam(value = "mainFile", required = false) MultipartFile mainFile,
@RequestParam(value = "file", required = false) MultipartFile[] file)
throws IOException {
User user = (User) session.getAttribute("user");
FileCheck fileCheck = new FileCheck();
imageService.deleteImage(goodId);
RandomString randomString = new RandomString();
String filePath = "/statics/image/goods/" + user.getId() + "/" + goodId;
String pathRoot = fileCheck.checkGoodFolderExist(filePath);
String name;
if (!mainFile.isEmpty()) {
String contentType = mainFile.getContentType();
String fileName = goodId + randomString.getRandomString(10);
String imageName = contentType
.substring(contentType.indexOf("/") + 1);
name = fileName + "." + imageName;
mainFile.transferTo(new File(pathRoot + name));
String photoUrl = filePath + "/" + name;
goodService.updateGoodPhotoUrl(photoUrl, goodId);
}
for (MultipartFile mf : file) {
if (!mf.isEmpty()) {
String contentType = mf.getContentType();
String fileName = goodId + randomString.getRandomString(10);
String imageName = contentType.substring(contentType
.indexOf("/") + 1);
name = fileName + "." + imageName;
System.out.println("name:" + name);
mf.transferTo(new File(pathRoot + name));
Image image = new Image();
image.setGoodId(goodId);
image.setName(name);
image.setUrl(filePath + "/" + name);
imageService.insertImage(image);
}
}
return "redirect:/goods/goodInfo?goodId=" + goodId;
}
@RequestMapping(value = "/goods/userGoodEdit/delete/{goodId}", method = RequestMethod.GET)
public ResponseEntity deleteGood(@PathVariable Integer goodId) {
Boolean success;
success = goodService.deleteGood(goodId) > 0;
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/goods/userGoodEdit/updateGoodStatus/{goodId}", method = RequestMethod.GET)
public ResponseEntity updateGoodStatus(@PathVariable Integer goodId) {
Boolean success;
success = goodService.updateGoodStatusId(0, goodId) > 0;
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/admin/goods/allGoods", method = RequestMethod.GET)
public ResponseEntity adminGetAllGoods() {
List<Good> goodList = goodService.getAllGoodList();
for (Good good : goodList) {
good.setGoodUser(userService.getUserById(good.getUserId()));
good.setGoodSecondType(typeService.getSecondTypeById(good
.getSecondTypeId()));
}
return ResponseEntity.ok(goodList);
}
}
订单控制层:
@Controller
public class OrderController {
private final GoodService goodService;
private final OrderService orderService;
@Autowired
public OrderController(GoodService goodService, OrderService orderService) {
this.goodService = goodService;
this.orderService = orderService;
}
@RequestMapping(value = "/user/orderInfo", method = RequestMethod.GET)
public String getOrderInfo(ModelMap model,
@RequestParam(value = "orderId", required = false) Integer orderId,
HttpSession session) {
User sessionUser = (User) session.getAttribute("user");
if (sessionUser == null) {
return "redirect:/";
}
Order orderInfo = orderService.getOrderById(orderId);
List<Order> orders = orderService.getOtherOrderByCustomerId(
sessionUser.getId(), orderId);
model.addAttribute("orderInfo", orderInfo);
model.addAttribute("orders", orders);
return "user/orderInfo";
}
@RequestMapping(value = "/user/sellerInfo", method = RequestMethod.GET)
public String getSellerInfo(ModelMap model,
@RequestParam(value = "orderId", required = false) Integer orderId,
HttpSession session) {
User sessionUser = (User) session.getAttribute("user");
if (sessionUser == null) {
return "redirect:/";
}
Order orderInfo = orderService.getOrderById(orderId);
List<Order> orders = orderService.getOtherOrderBySellerId(
sessionUser.getId(), orderId);
model.addAttribute("orderInfo", orderInfo);
model.addAttribute("orders", orders);
System.out.println("sellerInfo.size:" + orders.size());
return "user/sellerInfo";
}
@RequestMapping(value = "/user/order/delete/{orderId}", method = RequestMethod.GET)
public ResponseEntity deleteOrderById(@PathVariable Integer orderId) {
Boolean success;
success = orderService.deleteOrderById(orderId) > 0;
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/user/sellerOrder/delete/{orderId}&{goodId}", method = RequestMethod.GET)
public ResponseEntity deleteSellerOrderById(@PathVariable Integer orderId,
@PathVariable Integer goodId) {
Boolean success;
success = goodService.updateGoodStatusId(1, goodId) > 0;
if (success) {
success = orderService.deleteOrderById(orderId) > 0;
}
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/user/order/update/status/{orderId}&{statusId}", method = RequestMethod.GET)
public ResponseEntity updateOrderStatus(@PathVariable Integer orderId,
@PathVariable Integer statusId) {
Boolean success = orderService.updateStatus(statusId, orderId) > 0;
if (success) {
Order order = orderService.getOrderById(orderId);
return ResponseEntity.ok(order);
}
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/user/order/create", method = RequestMethod.POST)
public ResponseEntity createOrder(@RequestBody Order order) {
Boolean success = orderService.insertOrder(order) > 0;
if (success) {
success = goodService.updateGoodStatusId(0, order.getGoodId()) > 0;
if (success) {
return ResponseEntity.ok(order.getId());
} else {
orderService.deleteOrderById(order.getId());
return ResponseEntity.ok(success);
}
}
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/user/order/allOrder", method = RequestMethod.GET)
public ResponseEntity getAllOrders() {
List<Order> orderList = orderService.getOrderList();
return ResponseEntity.ok(orderList);
}
}
源码获取:俺的博客首页 "资源" 里下载!