赞
踩
基于javaweb+springboot的化妆品商城系统(java+Springboot+ssm+mysql+jsp+maven)
一、项目简述
本系统主要实现的功能有: 网上商城系统,前台+后台管理,用户注册,登录,上架展示,分组展示,搜索,收货地址管理,购物车管理,添加,购买,个人信息修改。订单查询等等,后台商品管理,分类管理,库存管理,订单管理,评论管理,用户管理,信息修改等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: Springboot+ SpringMVC + MyBatis + Jsp + Html+ JavaScript + JQuery + Ajax + maven等等。
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
if (yn) { object.put("success", true); } else { object.put("success", false); } return object.toJSONString(); } } logger.info("封装订单项对象"); 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()))); boolean yn = productOrderItemService.add(productOrderItem); if (yn) { object.put("success", true); } else { object.put("success", false);
return jsonObject.toJSONString(); } //更新产品类型信息-ajax @ResponseBody @RequestMapping(value = "admin/category/{category_id}", method = RequestMethod.PUT, produces = "application/json;charset=utf-8") public String updateCategory(@RequestParam String category_name/* 分类名称 */, @RequestParam String category_image_src/* 分类图片路径 */, @PathVariable("category_id") Integer category_id/* 分类ID */) { JSONObject jsonObject = new JSONObject(); logger.info("整合分类信息"); Category category = new Category() .setCategory_id(category_id) .setCategory_name(category_name) .setCategory_image_src(category_image_src.substring(category_image_src.lastIndexOf("/") + 1)); logger.info("更新分类信息,分类ID值为:{}", category_id); boolean yn = categoryService.update(category); if (yn) { logger.info("更新成功!"); jsonObject.put("success", true); jsonObject.put("category_id", category_id); } else { jsonObject.put("success", false); logger.info("更新失败!事务回滚");
return jsonObject.toJSONString();
}
//更新产品类型信息-ajax
@ResponseBody
@RequestMapping(value = "admin/category/{category_id}", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
public String updateCategory(@RequestParam String category_name/* 分类名称 */,
@RequestParam String category_image_src/* 分类图片路径 */,
@PathVariable("category_id") Integer category_id/* 分类ID */) {
JSONObject jsonObject = new JSONObject();
logger.info("整合分类信息");
Category category = new Category()
.setCategory_id(category_id)
.setCategory_name(category_name)
object.put("success", false); object.put("url", "/login"); return object.toJSONString(); } logger.info("------验证订单信息------"); logger.info("查询订单是否存在"); ProductOrder order = productOrderService.getByCode(order_code); if (order == null) { logger.warn("订单不存在,返回订单列表页"); object.put("success", false); object.put("url", "/order/0/10"); return object.toJSONString(); } logger.info("验证订单状态"); if (order.getProductOrder_status() != 2) { logger.warn("订单状态不正确,返回订单列表页"); object.put("success", false);
object.put("url", "/order/0/10");
return object.toJSONString();
}
logger.info("验证订单状态");
if (order.getProductOrder_status() != 0) {
logger.warn("订单状态不正确,返回订单列表页");
object.put("success", false);
object.put("url", "/order/0/10");
return object.toJSONString();
}
logger.info("验证用户与订单是否一致");
if (order.getProductOrder_user().getUser_id() != Integer.parseInt(userId.toString())) {
logger.warn("用户与订单信息不一致,返回订单列表页");
object.put("success", false);
object.put("url", "/order/0/10");
}
boolean yn = productOrderItemService.update(new ProductOrderItem().setProductOrderItem_id(Integer.valueOf(id)).setProductOrderItem_userMessage(orderItemMap.getString(id)));
if (!yn) {
throw new RuntimeException();
}
orderItem.setProductOrderItem_product(productService.get(orderItem.getProductOrderItem_product().getProduct_id()));
productOrderItemList.add(orderItem);
}
} else {
object.put("success", false);
object.put("url", "/cart");
return object.toJSONString();
}
logger.info("将收货地址等相关信息存入Cookie中,便于下次使用");
Cookie[] cookies = new Cookie[]{
//前台天猫-用户更换头像 @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 "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);
logger.info("检查用户是否登录");
Object userId = checkUser(session);
if (userId == null) {
object.put("success", false);
object.put("url", "/login");
return object.toJSONString();
}
logger.info("------验证订单信息------");
logger.info("查询订单是否存在");
ProductOrder order = productOrderService.getByCode(order_code);
if (order == null) {
logger.warn("订单不存在,返回订单列表页");
for (ProductOrderItem orderItem : orderItemList) { logger.info("找到匹配的购物车项"); if (orderItem.getProductOrderItem_id().equals(orderItem_id)) { isMine = true; break; } } if (isMine) { logger.info("删除订单项信息"); boolean yn = productOrderItemService.deleteList(new Integer[]{orderItem_id}); if (yn) { object.put("success", true); } else { object.put("success", false); } } else { object.put("success", false); } return object.toJSONString();
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)));
new Cookie("order_post", URLEncoder.encode(productOrder_post, "UTF-8")), new Cookie("order_receiver", URLEncoder.encode(productOrder_receiver, "UTF-8")), new Cookie("order_phone", URLEncoder.encode(productOrder_mobile, "UTF-8")), new Cookie("detailsAddress", URLEncoder.encode(productOrder_detail_address, "UTF-8")) }; int maxAge = 60 * 60 * 24 * 365; for(Cookie cookie : cookies){ //设置过期时间为一年 cookie.setMaxAge(maxAge); //存储Cookie response.addCookie(cookie); } StringBuffer productOrder_code = new StringBuffer() .append(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())) .append(0) .append(userId); logger.info("生成的订单号为:{}", productOrder_code);
object.put("success", false);
object.put("url", "/not");
return object.toJSONString();
}
logger.info("将收货地址等相关信息存入Cookie中,便于下次使用");
Cookie[] cookies = new Cookie[]{
new Cookie("addressId", addressId),
new Cookie("cityAddressId", cityAddressId),
new Cookie("districtAddressId", districtAddressId),
new Cookie("order_post", URLEncoder.encode(productOrder_post, "UTF-8")),
new Cookie("order_receiver", URLEncoder.encode(productOrder_receiver, "UTF-8")),
//前台天猫-用户详情更新 @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;
logger.warn("用户与订单信息不一致,返回订单列表页"); return "redirect:/order/0/10"; } logger.info("更新订单信息"); ProductOrder productOrder = new ProductOrder() .setProductOrder_id(order.getProductOrder_id()) .setProductOrder_delivery_date(new Date()) .setProductOrder_status((byte) 2); productOrderService.update(productOrder); return "redirect:/order/0/10"; } //更新订单信息为交易成功-ajax @ResponseBody @RequestMapping(value = "order/success/{order_code}", method = RequestMethod.PUT, produces = "application/json;charset=utf-8") public String orderSuccess(HttpSession session, @PathVariable("order_code") String order_code) { JSONObject object = new JSONObject(); logger.info("检查用户是否登录"); Object userId = checkUser(session);
if (number <= 0 || number > 500) { logger.warn("订单项产品数量不合法!"); object.put("success", false); return object.toJSONString(); } double price = productOrderItem.getProductOrderItem_price() / productOrderItem.getProductOrderItem_number(); Boolean yn = productOrderItemService.update(new ProductOrderItem().setProductOrderItem_id(Integer.valueOf(key)).setProductOrderItem_number(number).setProductOrderItem_price(number * price)); if (!yn) { throw new RuntimeException(); } } Object[] orderItemIDArray = orderItemIDSet.toArray(); object.put("success", true); object.put("orderItemIDArray", orderItemIDArray); return object.toJSONString(); } else { logger.warn("无订单项可以处理"); object.put("success", false); return object.toJSONString(); } } //创建新订单-单订单项-ajax
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);
orderTotalPrice = productOrderItem.getProductOrderItem_price();
} else {
logger.info("获取多订单项的产品信息");
for (ProductOrderItem productOrderItem : order.getProductOrderItemList()) {
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 (number <= 0 || number > 500) { logger.warn("订单项产品数量不合法!"); object.put("success", false); return object.toJSONString(); } double price = productOrderItem.getProductOrderItem_price() / productOrderItem.getProductOrderItem_number(); Boolean yn = productOrderItemService.update(new ProductOrderItem().setProductOrderItem_id(Integer.valueOf(key)).setProductOrderItem_number(number).setProductOrderItem_price(number * price)); if (!yn) { throw new RuntimeException(); } } Object[] orderItemIDArray = orderItemIDSet.toArray(); object.put("success", true); object.put("orderItemIDArray", orderItemIDArray); return object.toJSONString(); } else {
@RequestParam String category_image_src/* 分类图片路径 */,
@PathVariable("category_id") Integer category_id/* 分类ID */) {
JSONObject jsonObject = new JSONObject();
logger.info("整合分类信息");
Category category = new Category()
.setCategory_id(category_id)
.setCategory_name(category_name)
.setCategory_image_src(category_image_src.substring(category_image_src.lastIndexOf("/") + 1));
logger.info("更新分类信息,分类ID值为:{}", category_id);
boolean yn = categoryService.update(category);
logger.info("按条件获取第{}页的{}条分类", index + 1, count);
PageUtil pageUtil = new PageUtil(index, count);
List<Category> categoryList = categoryService.getList(category_name, pageUtil);
object.put("categoryList", JSONArray.parseArray(JSON.toJSONString(categoryList)));
logger.info("按条件获取分类总数量");
Integer categoryCount = categoryService.getTotal(category_name);
object.put("categoryCount", categoryCount);
logger.info("获取分页信息");
pageUtil.setTotal(categoryCount);
object.put("totalPage", pageUtil.getTotalPage());
object.put("pageUtil", pageUtil);
return object.toJSONString();
}
// 上传产品类型图片-ajax
@ResponseBody
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));
} else { logger.warn("无订单项可以处理"); object.put("success", false); return object.toJSONString(); } } //创建新订单-单订单项-ajax @ResponseBody @RequestMapping(value = "order", method = RequestMethod.POST, produces = "application/json;charset=utf-8") public String createOrderByOne(HttpSession session, Map<String, Object> map, HttpServletResponse response, @RequestParam String addressId, @RequestParam String cityAddressId, @RequestParam String districtAddressId, @RequestParam String productOrder_detail_address, @RequestParam String productOrder_post, @RequestParam String productOrder_receiver, @RequestParam String productOrder_mobile, @RequestParam String userMessage, @RequestParam Integer orderItem_product_id, @RequestParam Short orderItem_number) throws UnsupportedEncodingException { JSONObject object = new JSONObject();
.setProductOrder_id(order.getProductOrder_id()) .setProductOrder_delivery_date(new Date()) .setProductOrder_status((byte) 2); productOrderService.update(productOrder); return "redirect:/order/0/10"; } //更新订单信息为交易成功-ajax @ResponseBody @RequestMapping(value = "order/success/{order_code}", method = RequestMethod.PUT, produces = "application/json;charset=utf-8") public String orderSuccess(HttpSession session, @PathVariable("order_code") String order_code) { JSONObject object = new JSONObject(); logger.info("检查用户是否登录"); Object userId = checkUser(session); if (userId == null) { object.put("success", false); object.put("url", "/login");
logger.info("订单总金额为:{}元", orderTotalPrice); map.put("productOrder", order); map.put("orderTotalPrice", orderTotalPrice); logger.info("转到前台天猫-订单确认页"); return "fore/orderConfirmPage"; } //转到前台天猫-订单完成页 @RequestMapping(value = "order/success/{order_code}", method = RequestMethod.GET) public String goToOrderSuccessPage(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);
logger.info("按条件获取分类总数量");
Integer categoryCount = categoryService.getTotal(category_name);
object.put("categoryCount", categoryCount);
logger.info("获取分页信息");
pageUtil.setTotal(categoryCount);
object.put("totalPage", pageUtil.getTotalPage());
object.put("pageUtil", pageUtil);
return object.toJSONString();
}
// 上传产品类型图片-ajax
logger.info("整合订单对象"); ProductOrder productOrder = new ProductOrder() .setProductOrder_status((byte) 0) .setProductOrder_address(new Address().setAddress_areaId(districtAddressId)) .setProductOrder_post(productOrder_post) .setProductOrder_user(new User().setUser_id(Integer.valueOf(userId.toString()))) .setProductOrder_mobile(productOrder_mobile) .setProductOrder_receiver(productOrder_receiver) .setProductOrder_detail_address(productOrder_detail_address) .setProductOrder_pay_date(new Date()) .setProductOrder_code(productOrder_code.toString()); Boolean yn = productOrderService.add(productOrder); if (!yn) { throw new RuntimeException(); } Integer order_id = lastIDService.selectLastID(); logger.info("整合订单项对象"); ProductOrderItem productOrderItem = new ProductOrderItem()
} ProductOrderItem productOrderItem = new ProductOrderItem(); logger.info("检查用户的购物车项"); List<ProductOrderItem> orderItemList = productOrderItemService.getListByUserId(Integer.valueOf(userId.toString()), null); for (ProductOrderItem orderItem : orderItemList) { if (orderItem.getProductOrderItem_product().getProduct_id().equals(product_id)) { logger.info("找到已有的产品,进行数量追加"); int number = orderItem.getProductOrderItem_number(); number += 1; productOrderItem.setProductOrderItem_id(orderItem.getProductOrderItem_id()); productOrderItem.setProductOrderItem_number((short) number); productOrderItem.setProductOrderItem_price(number * product.getProduct_sale_price()); boolean yn = productOrderItemService.update(productOrderItem); if (yn) { object.put("success", true); } else { object.put("success", false); }
} } } 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);
logger.info("文件上传中..."); file.transferTo(new File(filePath)); logger.info("文件上传完成"); object.put("success", true); object.put("fileName", fileName); } catch (IOException e) { logger.warn("文件上传失败!"); e.printStackTrace(); object.put("success", false); } return object.toJSONString(); } } 用户信息管理: /** * 用户信息管理 */ @Controller
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。