源码获取:俺的博客首页 "资源" 里下载!
项目介绍
本项目分为前后台,分为管理员与普通用户两种角色,管理员登录后台,普通用户登录前台;
管理员登录包含以下功能:
登录,订单管理操作发货,客户管理,生鲜管理,生鲜类目管理等功能。
用户角色包含以下功能:
用户首页,用户登录,全部分类,查看生鲜,查看购物车,提交订单,查看订单等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:否;
技术栈
JSP+CSS+jQuery+bootstrap+mysql+servlet
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中src/utils/DBUtil.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/jsp_shenxian_shop/ 登录 注:tomcat中配置项目路径必须为jsp_shenxian_shop,否则会有异常;
用户账号/密码:user/123456
管理员账号/密码:admin/admin
用户管理控制层:
@RestControllerpublic class UserController {@AutowiredUserService userService;/*** 用户登录*/@PostMapping("/login")public ResultResp login(@RequestBody LoginVo loginVo){System.out.println(loginVo);return userService.login(loginVo);}/*** 根据用户名查找用户*/@PostMapping("/userinfo")public ResultResp getUser(String userName){UserInfoVo vo = userService.getUser(userName);return Response.ok(vo);}@PostMapping("/updateuser")public ResultResp updateUser(UserDto userDto){return userService.updateUser(userDto);}/*** 用户列表* @return*/@GetMapping("/userlist")public ResultResp UserList(@RequestParam(required = false, defaultValue = "1") int pageIndex,@RequestParam(required = false, defaultValue = "8") int pageSize){return userService.userList(pageIndex,pageSize);}/*** 我的中心数据统计* @return*/@GetMapping("/mycount")public ResultResp UserList(@RequestParam String userName){return userService.myCount(userName);}/*** 通过用户名搜索*/@GetMapping("/findusernamelist")public ResultResp finByUserNameAdminList(@RequestParam String userName,@RequestParam(required = false, defaultValue = "1") int pageIndex,@RequestParam(required = false, defaultValue = "8") int pageSize){return userService.findByUserNameList(userName, pageIndex, pageSize);}/*** 用户列表* @return*/@GetMapping("/adminuserlist")public ResultResp adminUserList(@RequestParam(required = false, defaultValue = "1") int pageIndex,@RequestParam(required = false, defaultValue = "8") int pageSize){return userService.adminUserList(pageIndex,pageSize);}/*** 通过用户名搜索*/@GetMapping("/findbyadminusernamelist")public ResultResp findByAdminUserNameList(@RequestParam String userName,@RequestParam(required = false, defaultValue = "1") int pageIndex,@RequestParam(required = false, defaultValue = "8") int pageSize){return userService.findByAdminUserNameList(userName, pageIndex, pageSize);}/*** 通过用户编号查看详情*/@GetMapping("/userdetail")public ResultResp findByUserId(@RequestParam String userName){return userService.findByUserName(userName);}/*** 删除用户*/@DeleteMapping("/deleteuser")public ResultResp deleteUser(@RequestParam int userId){return userService.deleteUser(userId);}/*** 恢复用户*/@GetMapping("/adduser")public ResultResp addUser(@RequestParam int userId){return userService.adminAddUser(userId);}/*** 重置密码*/@PostMapping("/resetpwd")public ResultResp resetPwd(@RequestParam int userId){return userService.resetPwd(userId);}/*** 修改密码*/@GetMapping("/repwd")public ResultResp rePwd(@RequestParam String userName,@RequestParam String userPwd,@RequestParam String newPwd){return userService.rePwd(userName,userPwd,newPwd);}@PostMapping("/findName")public ResultResp findNmae(@RequestParam String userName){System.out.println(userName);return userService.isUsernameExist(userName);}/*** 添加用户*/@GetMapping("/adduserName")public ResultResp adduserName(@RequestParam String userName,@RequestParam String userPwd ){return userService.addUser(userName, userPwd);}}
订单管理控制层:
@RestControllerpublic class OrderController {@ResourceOrderService orderService;/*** 生成订单* @param userName* @param bookId* @param addressId* @return*/@PostMapping("/addorder")public ResultResp addOrder(@RequestParam String userName,@RequestParam int bookId,@RequestParam int addressId){return orderService.addOrder(bookId,addressId,userName);}/*** 订单列表* @return*/@GetMapping("/orderlist")public ResultResp orderList(@RequestParam String userName){return orderService.orderList(userName);}/*** 订单详情* @return*/@GetMapping("/orderlist/detail")public ResultResp orderList(@RequestParam int orderId){return orderService.orderDetail(orderId);}/*** 确认收货* @return*/@PostMapping("/confirmreceipt")public ResultResp confirmReceipt(@RequestParam int orderId){return orderService.confirmReceipt(orderId);}/*** 取消收货* @return*/@PostMapping("/cancelorder")public ResultResp cancelOrder(@RequestParam int orderId){return orderService.cancelOrder(orderId);}}
商品管理控制层:
@Controllerpublic 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 = "";@Autowiredpublic 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);}}
源码获取:俺的博客首页 "资源" 里下载!