——————————DescriptionStart——————————
运行环境 Java≥8、MySQL≥5.7
开发工具 eclipse/idea/myeclipse/sts等均可配置运行
适用 课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot电商书城平台系统设计和实现(java+springboot+mysql+spring+jsp+maven)
JAVA springboot 电商书城平台系统(已调试) 主要实现了书城网站的浏览、加入购物车操作、订单操作、支付操作、分类查看、搜索、以及后台上传图书信息以及订单管理和一些基本操作功能
主要功能截图如下:
模拟支付宝支付:
主要技术:java springboot springbmvc shiro mybatis mysql jquery css js jsp bootstarp.js
——————————CodeStart——————————
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 } @Override public BSResult clearCart (HttpServletRequest request, String sessionName) { request.getSession().removeAttribute(sessionName); return BSResultUtil.success(); } @Override public BSResult deleteCartItem (int bookId, HttpServletRequest request) { Cart cart = (Cart) request.getSession().getAttribute("cart" ); Map<Integer, CartItem> cartItems = cart.getCartItems(); if (cartItems.containsKey(bookId)) { CartItem cartItem = cartItems.get(bookId); cart.setTotal(cart.getTotal() - cartItem.getSubTotal()); cartItems.remove(bookId); } request.getSession().setAttribute("cart" , cart); return BSResultUtil.success(); } @Override public BSResult updateBuyNum (int bookId, int newNum, HttpServletRequest request) { Cart cart = (Cart) request.getSession().getAttribute("cart" ); Map<Integer, CartItem> cartItems = cart.getCartItems(); if (cartItems.containsKey(bookId)) { CartItem cartItem = cartItems.get(bookId); cart.setTotal(cart.getTotal() - cartItem.getSubTotal()); BookInfo bookInfo = cartItem.getBookInfo(); cartItem.setSubTotal( bookInfo.getPrice().doubleValue() * newNum); cartItem.setBuyNum(newNum); cart.setTotal(cart.getTotal() + cartItem.getSubTotal()); } request.getSession().setAttribute("cart" , cart);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 if (categoryList == null ){ categoryList = cateService.getCategoryList(); } List<BookInfo> bookInfos = bookInfoService.findBookListByCateId(categoryList.get(new Random().nextInt(6 )).getCateId(), new Random().nextInt(3 ), 18 ); model.addAttribute("bookInfos" , bookInfos); return "index" ; } @RequestMapping("/index/category/{cateId}") public String bookListByCategoryId (@PathVariable("cateId") int cateId, Model model) { List<BookInfo> bookInfos = bookInfoService.findBookListByCateId(cateId, new Random().nextInt(3 ), 18 ); model.addAttribute("bookInfos" , bookInfos); model.addAttribute("cateId" , cateId); return "index" ; } @PostMapping("/write") public void write (String url) throws IOException, ParseException, SQLException { HttpClient httpclient = new DefaultHttpClient(); List<BookInfo> books = URLEntity.URLParse(httpclient, url, BOOK_CATEGORY); writeToMysql.executeInsert(books); } } package org.zdd.bookstore.web.controller;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 public String editStore (Store store,Model model) { storeService.updateStore(store); model.addAttribute("saveMsg" , "保存成功" ); return "forward:" +store.getStoreId(); } @RequestMapping("/deletion/{storeId}") @RequiresPermissions("store-delete") public String deleteStore (@PathVariable("storeId") int storeId) { storeService.deleteStore(storeId); return "redirect:/admin/store/list" ; } @RequestMapping("/addition") @RequiresPermissions("store-add") public String addStore (Store store) { storeService.addStore(store); return "redirect:/admin/store/list" ; } } package org.zdd.bookstore.exception;@ControllerAdvice public class BSExceptionHandler { public static final String BS_ERROR_VIEW_NAME = "exception" ; @ExceptionHandler(value = Exception.class) @ResponseStatus(HttpStatus.OK)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 @RequestMapping("/user") public class UserController { @Autowired private IUserService userService; @Autowired private IMailService mailService; @Autowired private IStoreService storeService; @Value("${mail.fromMail.addr}") private String from; @Value("${my.ip}") private String ip; private final String USERNAME_PASSWORD_NOT_MATCH = "用户名或密码错误" ; private final String USERNAME_CANNOT_NULL = "用户名不能为空" ; @RequestMapping("/login") public String login (@RequestParam(value = "username", required = false) String username, @RequestParam(value = "password", required = false) String password, HttpServletRequest request, Model model) { if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { return "login" ; } Subject userSubject = SecurityUtils.getSubject(); if (!userSubject.isAuthenticated()) { UsernamePasswordToken token = new UsernamePasswordToken(username, password); token.setRememberMe(false ); try { userSubject.login(token); User loginUser = (User) userSubject.getPrincipal(); request.getSession().setAttribute("loginUser" , loginUser); Store store = storeService.findStoreByUserId(loginUser.getUserId()); request.getSession().setAttribute("loginStore" , store); SavedRequest savedRequest = WebUtils.getSavedRequest(request); String url = "/" ; if (savedRequest != null ) {
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 @Controller @RequestMapping("admin/privilege") @RequiresPermissions("privilege-manage") public class PrivilegeController { @Autowired private IPrivilegeService privilegeService; @ResponseBody @RequestMapping("/treeNodes") public List<ZTreeNode> treeNodesJsonData () { return privilegeService.getZTreeNodes(); } @ResponseBody @RequestMapping("/rolePrivileges/{roleId}") public List<ZTreeNode> treeRolePrivileges (@PathVariable("roleId") int roleId) { return privilegeService.getRolePrivileges(roleId); } @ResponseBody @RequestMapping("/{privId}") public BSResult getPrivilege (@PathVariable("privId") int privId) { return privilegeService.findById(privId); } @RequestMapping("/toEdit/{roleId}")
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 Cart cart = (Cart) request.getSession().getAttribute("cart" ); Map<Integer, CartItem> cartItems = cart.getCartItems(); if (cartItems.containsKey(bookId)) { CartItem cartItem = cartItems.get(bookId); cart.setTotal(cart.getTotal() - cartItem.getSubTotal()); BookInfo bookInfo = cartItem.getBookInfo(); cartItem.setSubTotal( bookInfo.getPrice().doubleValue() * newNum); cartItem.setBuyNum(newNum); cart.setTotal(cart.getTotal() + cartItem.getSubTotal()); } request.getSession().setAttribute("cart" , cart); return BSResultUtil.success(); } @Override public BSResult checkedOrNot (Cart cart, int bookId) { Map<Integer, CartItem> cartItems = cart.getCartItems(); if (cartItems.containsKey(bookId)) { CartItem cartItem = cartItems.get(bookId); if (cartItem.isChecked()) { cartItem.setChecked(false ); cart.setTotal(cart.getTotal() - cartItem.getSubTotal()); cartItem.setSubTotal(0.00 ); } else { cartItem.setChecked(true ); cartItem.setSubTotal(cartItem.getBuyNum() * cartItem.getBookInfo().getPrice().doubleValue()); cart.setTotal(cart.getTotal() + cartItem.getSubTotal()); } return BSResultUtil.success(); } else return BSResultUtil.build(400 , "购物车没有这本书籍!" ); }
——————————PayStart——————————
项目链接: https://javayms.github.io?id=201422322105200kb https://javayms.pages.dev?id=201422322105200kb