Java项目:网上商城项目(java+SSM+jsp+mysql+maven)

作者 : admin 本文共12212个字,预计阅读时间需要31分钟 发布时间: 共23人阅读

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)

一、项目简述

功能:网上商城系统,前台+后台管理,用户注册,登录, 上哦展示,分组展示,搜索,收货地址管理,购物车管 理,添加,购买,个人信息修改。订单查询等等,后台商 品管理,分类管理,库存管理,订单管理,用户管理,信 息、修改等等。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)插图

 

 

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)插图(1)

 

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)插图(2)

 

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)插图(3)

 

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)插图(4)

 

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)插图(5)

 

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)插图(6)

 

权限控制代码:

  1. /**
  2. * 产品详情页
  3. */
  4. @Controller
  5. public class ForeProductDetailsController extends BaseController {
  6. @Resource(name = “productService”)
  7. private ProductService productService;
  8. @Resource(name = “userService”)
  9. private UserService userService;
  10. @Resource(name = “productImageService”)
  11. private ProductImageService productImageService;
  12. @Resource(name = “categoryService”)
  13. private CategoryService categoryService;
  14. @Resource(name = “propertyValueService”)
  15. private PropertyValueService propertyValueService;
  16. @Resource(name = “propertyService”)
  17. private PropertyService propertyService;
  18. @Resource(name = “reviewService”)
  19. private ReviewService reviewService;
  20. @Resource(name = “productOrderItemService”)
  21. private ProductOrderItemService productOrderItemService;
  22. //转到前台天猫-产品详情页
  23. @RequestMapping(value = “product/{pid}”, method = RequestMethod.GET)
  24. public String goToPage(HttpSession session, Map<String, Object> map,
  25. @PathVariable(“pid”) String pid /*产品ID*/) {
  26. logger.info(“检查用户是否登录”);
  27. Object userId = checkUser(session);
  28. if (userId != null) {
  29. logger.info(“获取用户信息”);
  30. User user = userService.get(Integer.parseInt(userId.toString()));
  31. map.put(“user”, user);
  32. }
  33. logger.info(“获取产品ID”);
  34. Integer product_id = Integer.parseInt(pid);
  35. logger.info(“获取产品信息”);
  36. Product product = productService.get(product_id);
  37. if (product == null || product.getProduct_isEnabled() == 1) {
  38. return “redirect:/404”;
  39. }
  40. logger.info(“获取产品子信息-分类信息”);
  41. product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id()));
  42. logger.info(“获取产品子信息-预览图片信息”);
  43. List<ProductImage> singleProductImageList = productImageService.getList(product_id, (byte) 0, null);
  44. product.setSingleProductImageList(singleProductImageList);
  45. logger.info(“获取产品子信息-详情图片信息”);
  46. List<ProductImage> detailsProductImageList = productImageService.getList(product_id, (byte) 1, null);
  47. product.setDetailProductImageList(detailsProductImageList);
  48. logger.info(“获取产品子信息-产品属性值信息”);
  49. List<PropertyValue> propertyValueList = propertyValueService.getList(new PropertyValue().setPropertyValue_product(product), null);
  50. logger.info(“获取产品子信息-分类信息对应的属性列表”);
  51. List<Property> propertyList = propertyService.getList(new Property().setProperty_category(product.getProduct_category()), null);
  52. logger.info(“属性列表和属性值列表合并”);
  53. for (Property property : propertyList) {
  54. for (PropertyValue propertyValue : propertyValueList) {
  55. if (property.getProperty_id().equals(propertyValue.getPropertyValue_property().getProperty_id())) {
  56. List<PropertyValue> property_value_item = new ArrayList<>(1);
  57. property_value_item.add(propertyValue);
  58. property.setPropertyValueList(property_value_item);
  59. break;
  60. }
  61. }
  62. }
  63. logger.info(“获取产品子信息-产品评论信息”);
  64. product.setReviewList(reviewService.getListByProductId(product_id, null));
  65. if (product.getReviewList() != null) {
  66. for (Review review : product.getReviewList()) {
  67. review.setReview_user(userService.get(review.getReview_user().getUser_id()));
  68. }
  69. }
  70. logger.info(“获取猜你喜欢列表”);
  71. Integer category_id = product.getProduct_category().getCategory_id();
  72. Integer total = productService.getTotal(new Product().setProduct_category(new Category().setCategory_id(category_id)), new Byte[]{0, 2});
  73. logger.info(“分类ID为{}的产品总数为{}条”, category_id, total);
  74. //生成随机数
  75. int i = new Random().nextInt(total);
  76. if (i + 2 >= total) {
  77. i = total – 3;
  78. }
  79. if (i < 0) {
  80. i = 0;
  81. }
  82. List<Product> loveProductList = productService.getList(new Product().setProduct_category(
  83. new Category().setCategory_id(category_id)),
  84. new Byte[]{0, 2},
  85. null,
  86. new PageUtil().setCount(3).setPageStart(i)
  87. );
  88. if (loveProductList != null) {
  89. logger.info(“获取产品列表的相应的一张预览图片”);
  90. for (Product loveProduct : loveProductList) {
  91. loveProduct.setSingleProductImageList(productImageService.getList(loveProduct.getProduct_id(), (byte) 0, new PageUtil(0, 1)));
  92. }
  93. }
  94. logger.info(“获取分类列表”);
  95. List<Category> categoryList = categoryService.getList(null, new PageUtil(0, 3));
  96. map.put(“loveProductList”, loveProductList);
  97. map.put(“categoryList”, categoryList);
  98. map.put(“propertyList”, propertyList);
  99. map.put(“product”, product);
  100. map.put(“guessNumber”, i);
  101. map.put(“pageUtil”, new PageUtil(0, 10).setTotal(product.getProduct_review_count()));
  102. logger.info(“转到前台-产品详情页”);
  103. return “fore/productDetailsPage”;
  104. }
  105. //按产品ID加载产品评论列表-ajax
  106. @Deprecated
  107. @ResponseBody
  108. @RequestMapping(value = “review/{pid}”, method = RequestMethod.GET, produces = “application/json;charset=utf-8”)
  109. public String loadProductReviewList(@PathVariable(“pid”) String pid/*产品ID*/,
  110. @RequestParam Integer index/* 页数 */,
  111. @RequestParam Integer count/* 行数 */) {
  112. logger.info(“获取产品ID”);
  113. Integer product_id = Integer.parseInt(pid);
  114. logger.info(“获取产品评论列表”);
  115. List<Review> reviewList = reviewService.getListByProductId(product_id, new PageUtil(index, count));
  116. JSONObject jsonObject = new JSONObject();
  117. jsonObject.put(“reviewList”, JSONArray.parseArray(JSON.toJSONString(reviewList)));
  118. return jsonObject.toJSONString();
  119. }
  120. //按产品ID加载产品属性列表-ajax
  121. @Deprecated
  122. @ResponseBody
  123. @RequestMapping(value = “property/{pid}”, method = RequestMethod.GET, produces = “application/json;charset=utf-8”)
  124. public String loadProductPropertyList(@PathVariable(“pid”) String pid/*产品ID*/) {
  125. logger.info(“获取产品ID”);
  126. Integer product_id = Integer.parseInt(pid);
  127. logger.info(“获取产品详情-属性值信息”);
  128. Product product = new Product();
  129. product.setProduct_id(product_id);
  130. List<PropertyValue> propertyValueList = propertyValueService.getList(new PropertyValue().setPropertyValue_product(product), null);
  131. logger.info(“获取产品详情-分类信息对应的属性列表”);
  132. List<Property> propertyList = propertyService.getList(new Property().setProperty_category(product.getProduct_category()), null);
  133. logger.info(“属性列表和属性值列表合并”);
  134. for (Property property : propertyList) {
  135. for (PropertyValue propertyValue : propertyValueList) {
  136. if (property.getProperty_id().equals(propertyValue.getPropertyValue_property().getProperty_id())) {
  137. List<PropertyValue> property_value_item = new ArrayList<>(1);
  138. property_value_item.add(propertyValue);
  139. property.setPropertyValueList(property_value_item);
  140. break;
  141. }
  142. }
  143. }
  144. JSONObject jsonObject = new JSONObject();
  145. jsonObject.put(“propertyList”, JSONArray.parseArray(JSON.toJSONString(propertyList)));
  146. return jsonObject.toJSONString();
  147. }
  148. //加载猜你喜欢列表-ajax
  149. @ResponseBody
  150. @RequestMapping(value = “guess/{cid}”, method = RequestMethod.GET, produces = “application/json;charset=utf-8”)
  151. public String guessYouLike(@PathVariable(“cid”) Integer cid, @RequestParam Integer guessNumber) {
  152. logger.info(“获取猜你喜欢列表”);
  153. Integer total = productService.getTotal(new Product().setProduct_category(new Category().setCategory_id(cid)), new Byte[]{0, 2});
  154. logger.info(“分类ID为{}的产品总数为{}条”, cid, total);
  155. //生成随机数
  156. int i = new Random().nextInt(total);
  157. if (i + 2 >= total) {
  158. i = total – 3;
  159. }
  160. if (i < 0) {
  161. i = 0;
  162. }
  163. while (i == guessNumber) {
  164. i = new Random().nextInt(total);
  165. if (i + 2 >= total) {
  166. i = total – 3;
  167. }
  168. if (i < 0) {
  169. i = 0;
  170. break;
  171. }
  172. }
  173. logger.info(“guessNumber值为{},新guessNumber值为{}”, guessNumber, i);
  174. List<Product> loveProductList = productService.getList(new Product().setProduct_category(
  175. new Category().setCategory_id(cid)),
  176. new Byte[]{0, 2},
  177. null,
  178. new PageUtil().setCount(3).setPageStart(i)
  179. );
  180. if (loveProductList != null) {
  181. logger.info(“获取产品列表的相应的一张预览图片”);
  182. for (Product loveProduct : loveProductList) {
  183. loveProduct.setSingleProductImageList(productImageService.getList(loveProduct.getProduct_id(), (byte) 0, new PageUtil(0, 1)));
  184. }
  185. }
  186. JSONObject jsonObject = new JSONObject();
  187. logger.info(“获取数据成功!”);
  188. jsonObject.put(“success”, true);
  189. jsonObject.put(“loveProductList”, JSONArray.parseArray(JSON.toJSONString(loveProductList)));
  190. jsonObject.put(“guessNumber”, i);
  191. return jsonObject.toJSONString();
  192. }
  193. }

用户信息管理控制层:

  1. /**
  2. * 用户信息管理
  3. */
  4. @Controller
  5. public class ForeUserController extends BaseController{
  6. @Resource(name = “addressService”)
  7. private AddressService addressService;
  8. @Resource(name=“userService”)
  9. private UserService userService;
  10. //转到前台天猫-用户详情页
  11. @RequestMapping(value = “userDetails”, method = RequestMethod.GET)
  12. public String goToUserDetail(HttpSession session, Map<String,Object> map){
  13. logger.info(“检查用户是否登录”);
  14. Object userId = checkUser(session);
  15. if (userId != null) {
  16. logger.info(“获取用户信息”);
  17. User user = userService.get(Integer.parseInt(userId.toString()));
  18. map.put(“user”, user);
  19. logger.info(“获取用户所在地区级地址”);
  20. String districtAddressId = user.getUser_address().getAddress_areaId();
  21. Address districtAddress = addressService.get(districtAddressId);
  22. logger.info(“获取市级地址信息”);
  23. Address cityAddress = addressService.get(districtAddress.getAddress_regionId().getAddress_areaId());
  24. logger.info(“获取其他地址信息”);
  25. List<Address> addressList = addressService.getRoot();
  26. List<Address> cityList = addressService.getList(
  27. null,cityAddress.getAddress_regionId().getAddress_areaId()
  28. );
  29. List<Address> districtList = addressService.getList(null,cityAddress.getAddress_areaId());
  30. map.put(“addressList”, addressList);
  31. map.put(“cityList”, cityList);
  32. map.put(“districtList”, districtList);
  33. map.put(“addressId”, cityAddress.getAddress_regionId().getAddress_areaId());
  34. map.put(“cityAddressId”, cityAddress.getAddress_areaId());
  35. map.put(“districtAddressId”, districtAddressId);
  36. return “fore/userDetails”;
  37. } else {
  38. return “redirect:/login”;
  39. }
  40. }
  41. //前台天猫-用户更换头像
  42. @ResponseBody
  43. @RequestMapping(value = “user/uploadUserHeadImage”, method = RequestMethod.POST, produces = “application/json;charset=utf-8”)
  44. public String uploadUserHeadImage(@RequestParam MultipartFile file, HttpSession session
  45. ){
  46. String originalFileName = file.getOriginalFilename();
  47. logger.info(“获取图片原始文件名:{}”, originalFileName);
  48. String extension = originalFileName.substring(originalFileName.lastIndexOf(‘.’));
  49. String fileName = UUID.randomUUID() + extension;
  50. String filePath = session.getServletContext().getRealPath(“/”) + “res/images/item/userProfilePicture/” + fileName;
  51. logger.info(“文件上传路径:{}”, filePath);
  52. JSONObject jsonObject = new JSONObject();
  53. try {
  54. logger.info(“文件上传中…”);
  55. file.transferTo(new File(filePath));
  56. logger.info(“文件上传成功!”);
  57. jsonObject.put(“success”, true);
  58. jsonObject.put(“fileName”, fileName);
  59. } catch (IOException e) {
  60. logger.warn(“文件上传失败!”);
  61. e.printStackTrace();
  62. jsonObject.put(“success”, false);
  63. }
  64. return jsonObject.toJSONString();
  65. }
  66. //前台天猫-用户详情更新
  67. @RequestMapping(value=“user/update”,method=RequestMethod.POST,produces =“application/json;charset=utf-8”)
  68. public String userUpdate(HttpSession session, Map<String,Object> map,
  69. @RequestParam(value = “user_nickname”) String user_nickname /*用户昵称 */,
  70. @RequestParam(value = “user_realname”) String user_realname /*真实姓名*/,
  71. @RequestParam(value = “user_gender”) String user_gender /*用户性别*/,
  72. @RequestParam(value = “user_birthday”) String user_birthday /*用户生日*/,
  73. @RequestParam(value = “user_address”) String user_address /*用户所在地 */,
  74. @RequestParam(value = “user_profile_picture_src”, required = false)
  75. String user_profile_picture_src /* 用户头像*/,
  76. @RequestParam(value = “user_password”) String user_password/* 用户密码 */
  77. ) throws ParseException, UnsupportedEncodingException {
  78. logger.info(“检查用户是否登录”);
  79. Object userId = checkUser(session);
  80. if (userId != null) {
  81. logger.info(“获取用户信息”);
  82. User user = userService.get(Integer.parseInt(userId.toString()));
  83. map.put(“user”, user);
  84. } else {
  85. return “redirect:/login”;
  86. }
  87. logger.info(“创建用户对象”);
  88. if (user_profile_picture_src != null && “”.equals(user_profile_picture_src)) {
  89. user_profile_picture_src = null;
  90. }
  91. User userUpdate = new User()
  92. .setUser_id(Integer.parseInt(userId.toString()))
  93. .setUser_nickname(user_nickname)
  94. .setUser_realname(user_realname)
  95. .setUser_gender(Byte.valueOf(user_gender))
  96. .setUser_birthday(new SimpleDateFormat(“yyyy-MM-dd”).parse(user_birthday))
  97. .setUser_address(new Address().setAddress_areaId(user_address))
  98. .setUser_profile_picture_src(user_profile_picture_src)
  99. .setUser_password(user_password);
  100. logger.info(“执行修改”);
  101. if (userService.update(userUpdate)){
  102. logger.info(“修改成功!跳转到用户详情页面”);
  103. return “redirect:/userDetails”;
  104. }
  105. throw new RuntimeException();
  106. }
  107. }

 

地址信息管理控制层:

  1. /**
  2. * 地址信息管理
  3. */
  4. @RestController
  5. public class ForeAddressController extends BaseController{
  6. @Resource(name = “addressService”)
  7. private AddressService addressService;
  8. //根据address_areaId获取地址信息-ajax
  9. @RequestMapping(value = “address/{areaId}”, method = RequestMethod.GET, produces = “application/json;charset=utf-8”)
  10. protected String getAddressByAreaId(@PathVariable String areaId) {
  11. JSONObject object= new JSONObject();
  12. logger.info(“获取AreaId为{}的地址信息”);
  13. List<Address> addressList = addressService.getList(null, areaId);
  14. if (addressList == null || addressList.size() <= 0) {
  15. object.put(“success”, false);
  16. return object.toJSONString();
  17. }
  18. logger.info(“获取该地址可能的子地址信息”);
  19. List<Address> childAddressList = addressService.getList(null, addressList.get(0).getAddress_areaId());
  20. object.put(“success”, true);
  21. object.put(“addressList”, addressList);
  22. object.put(“childAddressList”, childAddressList);
  23. return object.toJSONString();
  24. }
  25. }

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)

Java项目:网上商城项目(java+SSM+jsp+mysql+maven)


滴石it网-Java学习中高级和架构师教程_Java企业级开发项目实战下载 » Java项目:网上商城项目(java+SSM+jsp+mysql+maven)

常见问题FAQ

发表回复

开通VIP 享更多特权,建议使用QQ登录