Java商城系统,java商城系统开发
00-1010一、项目介绍二。项目运营三。效果图四。核心代码权限基础控制层用户信息操作控制层用户订单控制层后台管理员类别控制层后台管理-产品页面控制层
00-1010迷你天猫商城是基于SSM框架的综合性B2C电子商务平台。需求设计主要参考天猫商城的购物流程:用户从注册开始到登录、浏览商品、加入购物车、下单、确认收货、评价等等。
作为模拟天猫商城系统的核心组件之一,使用SSM框架的天猫数据管理后台包括商品管理、订单管理、品类管理、用户管理和交易量统计等。实现了整个商城的一站式管理和维护。
00-1010环境配置:JDK 1.8 Tomcat 8.5 MySQL eclispe(intellij idea,eclispe,my eclispe,STS全部支持)
技术:JSP Spring Boot Spring MVC Spring My Batis CSS JavaScript jQuery Ajax LaYui Maven等等。
目录
一、项目介绍
00-1010/* * * base controller */public class base controller {//log4j protected logger logger=log manager . get logger(log manager . root _ logger _ name);//检查管理员权限保护对象Check admin(http session session){ object o=session . get attribute( adminid );If(o==null){ logger.info(无管理权限,返回管理员登录页面);返回null} logger.info(权限验证成功,管理员ID: {} ,o);返回o;}//检查用户是否登录保护对象Check user(http session session){ Object o=session . get attribute( userid );If(o==null){ logger.info(用户未登录);返回null} logger.info(用户已登录,用户ID: {} ,o);返回o;}}
二、项目运行
@ controller public class for user controller扩展base controller { @ Autowired private address service address service;@ Autowired private UserService UserService;//进入前台天猫-用户详情页面@ request mapping(value= user details ,method=requestmethod.get)公共字符串gotouser detail(http session session,mapstring,objectmap) {logger.info(检查用户是否登录);object userId=check user(session);if (userId!=null) {logger.info(获取用户信息);user user=userservice . get(integer . parse int(userid . tostring()));map.put(用户
", user); logger.info("获取用户所在地区级地址"); String districtAddressId = user.getUser_address().getAddress_areaId(); Address districtAddress = addressService.get(districtAddressId); logger.info("获取市级地址信息"); Address cityAddress = addressService.get(districtAddress.getAddress_regionId().getAddress_areaId()); logger.info("获取其他地址信息"); List<Address> addressList = addressService.getRoot(); List<Address> cityList = addressService.getList(null,cityAddress.getAddress_regionId().getAddress_areaId()); List<Address> districtList = addressService.getList(null,cityAddress.getAddress_areaId()); map.put("addressList", addressList); map.put("cityList", cityList); map.put("districtList", districtList); map.put("addressId", cityAddress.getAddress_regionId().getAddress_areaId()); map.put("cityAddressId", cityAddress.getAddress_areaId()); map.put("districtAddressId", districtAddressId); return "fore/userDetails"; } else { return "redirect:/login"; } } //前台天猫-用户更换头像 @ResponseBody @RequestMapping(value = "user/uploadUserHeadImage", method = RequestMethod.POST, produces = "application/json;charset=utf-8") public String uploadUserHeadImage(@RequestParam MultipartFile file, HttpSession session ){ String originalFileName = file.getOriginalFilename(); logger.info("获取图片原始文件名:{}", originalFileName); String extension = originalFileName.substring(originalFileName.lastIndexOf(.)); String fileName = UUID.randomUUID() + extension; String filePath = session.getServletContext().getRealPath("/") + "res/images/item/userProfilePicture/" + fileName; logger.info("文件上传路径:{}", filePath); JSONObject jsonObject = new JSONObject(); try { logger.info("文件上传中..."); file.transferTo(new File(filePath)); logger.info("文件上传成功!"); jsonObject.put("success", true); jsonObject.put("fileName", fileName); } catch (IOException e) { logger.warn("文件上传失败!"); e.printStackTrace(); jsonObject.put("success", false); } return jsonObject.toJSONString(); } //前台天猫-用户详情更新 @RequestMapping(value="user/update",method=RequestMethod.POST,produces ="application/json;charset=utf-8") public String userUpdate(HttpSession session, Map<String,Object> map, @RequestParam(value = "user_nickname") String user_nickname /*用户昵称 */, @RequestParam(value = "user_realname") String user_realname /*真实姓名*/, @RequestParam(value = "user_gender") String user_gender /*用户性别*/, @RequestParam(value = "user_birthday") String user_birthday /*用户生日*/, @RequestParam(value = "user_address") String user_address /*用户所在地 */, @RequestParam(value = "user_profile_picture_src", required = false) String user_profile_picture_src /* 用户头像*/, @RequestParam(value = "user_password") String user_password/* 用户密码 */ ) throws ParseException, UnsupportedEncodingException { logger.info("检查用户是否登录"); Object userId = checkUser(session); if (userId != null) { logger.info("获取用户信息"); User user = userService.get(Integer.parseInt(userId.toString())); map.put("user", user); } else { return "redirect:/login"; } logger.info("创建用户对象"); if (user_profile_picture_src != null && "".equals(user_profile_picture_src)) { user_profile_picture_src = null; } User userUpdate = new User() .setUser_id(Integer.parseInt(userId.toString())) .setUser_nickname(new String(user_nickname.getBytes("ISO8859-1"),"UTF-8")) .setUser_realname(new String(user_realname.getBytes("ISO8859-1"),"UTF-8")) .setUser_gender(Byte.valueOf(user_gender)) .setUser_birthday(new SimpleDateFormat("yyyy-MM-dd").parse(user_birthday)) .setUser_address(new Address().setAddress_areaId(user_address)) .setUser_profile_picture_src(user_profile_picture_src) .setUser_password(user_password); logger.info("执行修改"); if (userService.update(userUpdate)){ logger.info("修改成功!跳转到用户详情页面"); return "redirect:/userDetails"; } throw new RuntimeException(); }}
用户订单控制层
@Controllerpublic class ForeOrderController extends BaseController { @Autowired private ProductService productService; @Autowired private UserService userService; @Autowired private ProductOrderItemService productOrderItemService; @Autowired private AddressService addressService; @Autowired private CategoryService categoryService; @Autowired private ProductImageService productImageService; @Autowired private ProductOrderService productOrderService; @Autowired private ReviewService reviewService; @Autowired private LastIDService lastIDService; //转到前台天猫-订单列表页 @RequestMapping(value = "order", method = RequestMethod.GET) public String goToPageSimple() { return "redirect:/order/0/10"; } @RequestMapping(value = "order/{index}/{count}", method = RequestMethod.GET) public String goToPage(HttpSession session, Map<String, Object> map, @RequestParam(required = false) Byte status, @PathVariable("index") Integer index/* 页数 */, @PathVariable("count") Integer count/* 行数*/) { logger.info("检查用户是否登录"); Object userId = checkUser(session); User user; if (userId != null) { logger.info("获取用户信息"); user = userService.get(Integer.parseInt(userId.toString())); map.put("user", user); } else { return "redirect:/login"; } Byte[] status_array = null; if (status != null) { status_array = new Byte[]{status}; } PageUtil pageUtil = new PageUtil(index, count); logger.info("根据用户ID:{}获取订单列表", userId); List<ProductOrder> productOrderList = productOrderService.getList(new ProductOrder().setProductOrder_user(new User().setUser_id(Integer.valueOf(userId.toString()))), status_array, new OrderUtil("productOrder_id", true), pageUtil); //订单总数量 Integer orderCount = 0; if (productOrderList.size() > 0) { orderCount = productOrderService.getTotal(new ProductOrder().setProductOrder_user(new User().setUser_id(Integer.valueOf(userId.toString()))), status_array); logger.info("获取订单项信息及对应的产品信息"); for (ProductOrder order : productOrderList) { List<ProductOrderItem> productOrderItemList = productOrderItemService.getListByOrderId(order.getProductOrder_id(), null); if (productOrderItemList != null) { for (ProductOrderItem productOrderItem : productOrderItemList) { Integer product_id = productOrderItem.getProductOrderItem_product().getProduct_id(); Product product = productService.get(product_id); product.setSingleProductImageList(productImageService.getList(product_id, (byte) 0, new PageUtil(0, 1))); productOrderItem.setProductOrderItem_product(product); if (order.getProductOrder_status() == 3) { productOrderItem.setIsReview(reviewService.getTotalByOrderItemId(productOrderItem.getProductOrderItem_id()) > 0); } } } order.setProductOrderItemList(productOrderItemList); } } pageUtil.setTotal(orderCount); logger.info("获取产品分类列表信息"); List<Category> categoryList = categoryService.getList(null, new PageUtil(0, 5)); map.put("pageUtil", pageUtil); map.put("productOrderList", productOrderList); map.put("categoryList", categoryList); map.put("status", status); logger.info("转到前台天猫-订单列表页"); return "fore/orderListPage"; } //转到前台天猫-订单建立页 @RequestMapping(value = "order/create/{product_id}", method = RequestMethod.GET) public String goToOrderConfirmPage(@PathVariable("product_id") Integer product_id, @RequestParam(required = false, defaultValue = "1") Short product_number, Map<String, Object> map, HttpSession session, HttpServletRequest request) throws UnsupportedEncodingException { logger.info("检查用户是否登录"); Object userId = checkUser(session); User user; if (userId != null) { logger.info("获取用户信息"); user = userService.get(Integer.parseInt(userId.toString())); map.put("user", user); } else { return "redirect:/login"; } logger.info("通过产品ID获取产品信息:{}", product_id); Product product = productService.get(product_id); if (product == null) { return "redirect:/"; } logger.info("获取产品的详细信息"); product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id())); product.setSingleProductImageList(productImageService.getList(product_id, (byte) 0, new PageUtil(0, 1))); logger.info("封装订单项对象"); ProductOrderItem productOrderItem = new ProductOrderItem(); productOrderItem.setProductOrderItem_product(product); productOrderItem.setProductOrderItem_number(product_number); productOrderItem.setProductOrderItem_price(product.getProduct_sale_price() * product_number); productOrderItem.setProductOrderItem_user(new User().setUser_id(Integer.valueOf(userId.toString()))); String addressId = "110000"; String cityAddressId = "110100"; String districtAddressId = "110101"; String detailsAddress = null; String order_post = null; String order_receiver = null; String order_phone = null; Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { String cookieName = cookie.getName(); String cookieValue = cookie.getValue(); switch (cookieName) { case "addressId": addressId = cookieValue; break; case "cityAddressId": cityAddressId = cookieValue; break; case "districtAddressId": districtAddressId = cookieValue; break; case "order_post": order_post = URLDecoder.decode(cookieValue, "UTF-8"); break; case "order_receiver": order_receiver = URLDecoder.decode(cookieValue, "UTF-8"); break; case "order_phone": order_phone = URLDecoder.decode(cookieValue, "UTF-8"); break; case "detailsAddress": detailsAddress = URLDecoder.decode(cookieValue, "UTF-8"); break; } } } logger.info("获取省份信息"); List<Address> addressList = addressService.getRoot(); logger.info("获取addressId为{}的市级地址信息", addressId); List<Address> cityAddress = addressService.getList(null, addressId); logger.info("获取cityAddressId为{}的区级地址信息", cityAddressId); List<Address> districtAddress = addressService.getList(null, cityAddressId); List<ProductOrderItem> productOrderItemList = new ArrayList<>(); productOrderItemList.add(productOrderItem); map.put("orderItemList", productOrderItemList); map.put("addressList", addressList); map.put("cityList", cityAddress); map.put("districtList", districtAddress); map.put("orderTotalPrice", productOrderItem.getProductOrderItem_price()); map.put("addressId", addressId); map.put("cityAddressId", cityAddressId); map.put("districtAddressId", districtAddressId); map.put("order_post", order_post); map.put("order_receiver", order_receiver); map.put("order_phone", order_phone); map.put("detailsAddress", detailsAddress); logger.info("转到前台天猫-订单建立页"); return "fore/productBuyPage"; } //转到前台天猫-购物车订单建立页 @RequestMapping(value = "order/create/byCart", method = RequestMethod.GET) public String goToOrderConfirmPageByCart(Map<String, Object> map, HttpSession session, HttpServletRequest request, @RequestParam(required = false) Integer[] order_item_list) throws UnsupportedEncodingException { logger.info("检查用户是否登录"); Object userId = checkUser(session); User user; if (userId != null) { logger.info("获取用户信息"); user = userService.get(Integer.parseInt(userId.toString())); map.put("user", user); } else { return "redirect:/login"; } if (order_item_list == null order_item_list.length == 0) { logger.warn("用户订单项数组不存在,回到购物车页"); return "redirect:/cart"; } logger.info("通过订单项ID数组获取订单信息"); List<ProductOrderItem> orderItemList = new ArrayList<>(order_item_list.length); for (Integer orderItem_id : order_item_list) { orderItemList.add(productOrderItemService.get(orderItem_id)); } logger.info("------检查订单项合法性------"); if (orderItemList.size() == 0) { logger.warn("用户订单项获取失败,回到购物车页"); return "redirect:/cart"; } for (ProductOrderItem orderItem : orderItemList) { if (orderItem.getProductOrderItem_user().getUser_id() != userId) { logger.warn("用户订单项与用户不匹配,回到购物车页"); return "redirect:/cart"; } if (orderItem.getProductOrderItem_order() != null) { logger.warn("用户订单项不属于购物车,回到购物车页"); return "redirect:/cart"; } } logger.info("验证通过,获取订单项的产品信息"); double orderTotalPrice = 0.0; for (ProductOrderItem orderItem : orderItemList) { Product product = productService.get(orderItem.getProductOrderItem_product().getProduct_id()); product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id())); product.setSingleProductImageList(productImageService.getList(product.getProduct_id(), (byte) 0, new PageUtil(0, 1))); orderItem.setProductOrderItem_product(product); orderTotalPrice += orderItem.getProductOrderItem_price(); } String addressId = "110000"; String cityAddressId = "110100"; String districtAddressId = "110101"; String detailsAddress = null; String order_post = null; String order_receiver = null; String order_phone = null; Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { String cookieName = cookie.getName(); String cookieValue = cookie.getValue(); switch (cookieName) { case "addressId": addressId = cookieValue; break; case "cityAddressId": cityAddressId = cookieValue; break; case "districtAddressId": districtAddressId = cookieValue; break; case "order_post": order_post = URLDecoder.decode(cookieValue, "UTF-8"); break; case "order_receiver": order_receiver = URLDecoder.decode(cookieValue, "UTF-8"); break; case "order_phone": order_phone = URLDecoder.decode(cookieValue, "UTF-8"); break; case "detailsAddress": detailsAddress = URLDecoder.decode(cookieValue, "UTF-8"); break; } } } logger.info("获取省份信息"); List<Address> addressList = addressService.getRoot(); logger.info("获取addressId为{}的市级地址信息", addressId); List<Address> cityAddress = addressService.getList(null, addressId); logger.info("获取cityAddressId为{}的区级地址信息", cityAddressId); List<Address> districtAddress = addressService.getList(null, cityAddressId); map.put("orderItemList", orderItemList); map.put("addressList", addressList); map.put("cityList", cityAddress); map.put("districtList", districtAddress); map.put("orderTotalPrice", orderTotalPrice); map.put("addressId", addressId); map.put("cityAddressId", cityAddressId); map.put("districtAddressId", districtAddressId); map.put("order_post", order_post); map.put("order_receiver", order_receiver); map.put("order_phone", order_phone); map.put("detailsAddress", detailsAddress); logger.info("转到前台天猫-订单建立页"); return "fore/productBuyPage"; } //转到前台天猫-订单支付页 @RequestMapping(value = "order/pay/{order_code}", method = RequestMethod.GET) public String goToOrderPayPage(Map<String, Object> map, HttpSession session, @PathVariable("order_code") String order_code) { logger.info("检查用户是否登录"); Object userId = checkUser(session); User user; if (userId != null) { logger.info("获取用户信息"); user = userService.get(Integer.parseInt(userId.toString())); map.put("user", user); } else { return "redirect:/login"; } logger.info("------验证订单信息------"); logger.info("查询订单是否存在"); ProductOrder order = productOrderService.getByCode(order_code); if (order == null) { logger.warn("订单不存在,返回订单列表页"); return "redirect:/order/0/10"; } logger.info("验证订单状态"); if (order.getProductOrder_status() != 0) { logger.warn("订单状态不正确,返回订单列表页"); return "redirect:/order/0/10"; } logger.info("验证用户与订单是否一致"); if (order.getProductOrder_user().getUser_id() != Integer.parseInt(userId.toString())) { logger.warn("用户与订单信息不一致,返回订单列表页"); return "redirect:/order/0/10"; } order.setProductOrderItemList(productOrderItemService.getListByOrderId(order.getProductOrder_id(), null)); double orderTotalPrice = 0.00; if (order.getProductOrderItemList().size() == 1) { logger.info("获取单订单项的产品信息"); ProductOrderItem productOrderItem = order.getProductOrderItemList().get(0); Product product = productService.get(productOrderItem.getProductOrderItem_product().getProduct_id()); product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id())); productOrderItem.setProductOrderItem_product(product); orderTotalPrice = productOrderItem.getProductOrderItem_price(); } else { for (ProductOrderItem productOrderItem : order.getProductOrderItemList()) { orderTotalPrice += productOrderItem.getProductOrderItem_price(); } } logger.info("订单总金额为:{}元", orderTotalPrice); map.put("productOrder", order); map.put("orderTotalPrice", orderTotalPrice); logger.info("转到前台天猫-订单支付页"); return "fore/productPayPage"; } //转到前台天猫-订单支付成功页 @RequestMapping(value = "order/pay/success/{order_code}", method = RequestMethod.GET) public String goToOrderPaySuccessPage(Map<String, Object> map, HttpSession session, @PathVariable("order_code") String order_code) { logger.info("检查用户是否登录"); Object userId = checkUser(session); User user; if (userId != null) { logger.info("获取用户信息"); user = userService.get(Integer.parseInt(userId.toString())); map.put("user", user); } else { return "redirect:/login"; } logger.info("------验证订单信息------"); logger.info("查询订单是否存在"); ProductOrder order = productOrderService.getByCode(order_code); if (order == null) { logger.warn("订单不存在,返回订单列表页"); return "redirect:/order/0/10"; } logger.info("验证订单状态"); if (order.getProductOrder_status() != 1) { logger.warn("订单状态不正确,返回订单列表页"); return "redirect:/order/0/10"; } logger.info("验证用户与订单是否一致"); if (order.getProductOrder_user().getUser_id() != Integer.parseInt(userId.toString())) { logger.warn("用户与订单信息不一致,返回订单列表页"); return "redirect:/order/0/10"; } order.setProductOrderItemList(productOrderItemService.getListByOrderId(order.getProductOrder_id(), null)); double orderTotalPrice = 0.00; if (order.getProductOrderItemList().size() == 1) { logger.info("获取单订单项的产品信息"); ProductOrderItem productOrderItem = order.getProductOrderItemList().get(0); orderTotalPrice = productOrderItem.getProductOrderItem_price(); } else { for (ProductOrderItem productOrderItem : order.getProductOrderItemList()) { orderTotalPrice += productOrderItem.getProductOrderItem_price(); } } logger.info("订单总金额为:{}元", orderTotalPrice); logger.info("获取订单详情-地址信息"); Address address = addressService.get(order.getProductOrder_address().getAddress_areaId()); Stack<String> addressStack = new Stack<>(); //详细地址 addressStack.push(order.getProductOrder_detail_address()); //最后一级地址 addressStack.push(address.getAddress_name() + " "); //如果不是第一级地址 while (!address.getAddress_areaId().equals(address.getAddress_regionId().getAddress_areaId())) { address = addressService.get(address.getAddress_regionId().getAddress_areaId()); addressStack.push(address.getAddress_name
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。