javaweb毕设项目 - SpringCloud的分布式网上购物商城

电玩女神 2024-02-20 11:00 126阅读 0赞

开发语言:Java
Java开发工具:JDK1.8
后端:SpringCloud
前端:Vue、HTML
数据库:MySQL5.7和Navicat管理工具结合
服务器:Tomcat8.5
开发软件:IDEA / Eclipse
是否Maven项目:是



一、项目简介

首先,论文一开始便是清楚的论述了系统的研究内容。其次,剖析系统需求分析,弄明白“做什么”,分析包括业务分析和业务流程的分析以及用例分析,更进一步明确系统的需求。然后在明白了系统的需求基础上需要进一步地设计系统,主要包罗软件架构模式、整体功能模块、数据库设计。本项目软件架构选择B/S模式,总体功能模块运用自顶向下的分层思想。再然后就是实现系统并进行代码编写实现功能。论文的最后章节总结一下自己完成本论文和开发本项目的心得和总结。通过分布式架构网上商城系统将会使分布式架构商城管理各个方面的工作效率带来实质性的提升。


二、系统功能

考虑到实际生活中分布式架构网上商城在管理方面的需要以及对该平台认真的分析,将系统权限按管理员和用户涉及用户划分。

管理员;管理员使用本系统涉到的功能主要有:首页、个人中心、用户管理、商品信息管理、商品分类管理、系统管理、订单管理等功能。

管理员用例图

d2c206346e1b419b9cdadd7a1373ae3f.png

用户用例图

216f391828684cebb080caabdad3dc27.png


#

三、系统项目截图

3.1前台首页

分布式架构网上商城,在系统首页可以查看首首页、商品信息、购物资讯、个人中心、购物车等内容,并进行详细操作;

689d339fbe654c03b6fb4c4bc95ed717.png

用户注册,在用户注册页面通过填写账号、密码、确认密码、姓名、手机、邮箱等信息进行注册操作

941905743b374b72873d5821b96e1591.png

商品信息,在商品信息页面可以查看商品名称、价格、单次购买、库存、商品类型、规格、上架时间、点击次数等内容进行购买、评论或收藏等操作

5372d32faa174633bc9345b9d2b47698.png

购物车,在购物车页面可以查看购买商品、价格、数量、总价等内容,进行删除或购买等操作

41502d77330949f98f4991974dc69758.png

个人中心,在个人中心页面通过填写账号、密码、姓名、性别、手机、邮箱、图片、余额等内容进行更新信息等操作,并可以根据我的订单、我的地址或我的收藏进行相应的操作

23a0f854c1604721bd67c6c2c6121923.png

3.2后台管理

管理员进入系统前在登录页面根据要求填写用户名和密码,选择角色等信息,点击登录进行登录操作

93607cf79bf446e0ac0320dcfed528ff.png

管理员登录系统后,可以对首页、个人中心、用户管理、商品信息管理、商品分类管理、系统管理、订单管理等功能进行相应的操作管理fd7994f21bf146268ebc3c6a11d1e67d.png

用户管理,在用户管理页面可以对索引、账号、姓名、性别、手机、邮箱、头像等内容进行详情、修改或删除等操作

5526755ccde847ddb3db36cc678cb514.png

商品信息管理,在商品信息管理页面可以对索引、商品名称、商品类型、规格、上架时间、商品图片、价格、单限、库存等内容进行详情、查看评论、修改或删除等操作

703c59b51fbf441494ceef448dbe3d00.png

商品分类管理,在商品分类管理页面可以对索引、类型等内容进行修改或删除等操作

2966bca1404f4ea9994b2c6d10df5273.png

系统管理,在购物资讯页面中可以对索引、标题、图片等内容进行详情、修改或删除等操作,并可以根据轮播图管理进行相应的操作

dd5c6d2492fa4d5a807e26a81274dc63.png


四、核心代码

4.1登录相关

  1. package com.controller;
  2. import java.util.Arrays;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. import java.util.Map;
  6. import javax.servlet.http.HttpServletRequest;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import com.annotation.IgnoreAuth;
  18. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  19. import com.entity.TokenEntity;
  20. import com.entity.UserEntity;
  21. import com.service.TokenService;
  22. import com.service.UserService;
  23. import com.utils.CommonUtil;
  24. import com.utils.MD5Util;
  25. import com.utils.MPUtil;
  26. import com.utils.PageUtils;
  27. import com.utils.R;
  28. import com.utils.ValidatorUtils;
  29. /**
  30. * 登录相关
  31. */
  32. @RequestMapping("users")
  33. @RestController
  34. public class UserController{
  35. @Autowired
  36. private UserService userService;
  37. @Autowired
  38. private TokenService tokenService;
  39. /**
  40. * 登录
  41. */
  42. @IgnoreAuth
  43. @PostMapping(value = "/login")
  44. public R login(String username, String password, String captcha, HttpServletRequest request) {
  45. UserEntity user = userService.selectOne(new EntityWrapper().eq("username", username));
  46. if(user==null || !user.getPassword().equals(password)) {
  47. return R.error("账号或密码不正确");
  48. }
  49. String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
  50. return R.ok().put("token", token);
  51. }
  52. /**
  53. * 注册
  54. */
  55. @IgnoreAuth
  56. @PostMapping(value = "/register")
  57. public R register(@RequestBody UserEntity user){
  58. // ValidatorUtils.validateEntity(user);
  59. if(userService.selectOne(new EntityWrapper().eq("username", user.getUsername())) !=null) {
  60. return R.error("用户已存在");
  61. }
  62. userService.insert(user);
  63. return R.ok();
  64. }
  65. /**
  66. * 退出
  67. */
  68. @GetMapping(value = "logout")
  69. public R logout(HttpServletRequest request) {
  70. request.getSession().invalidate();
  71. return R.ok("退出成功");
  72. }
  73. /**
  74. * 密码重置
  75. */
  76. @IgnoreAuth
  77. @RequestMapping(value = "/resetPass")
  78. public R resetPass(String username, HttpServletRequest request){
  79. UserEntity user = userService.selectOne(new EntityWrapper().eq("username", username));
  80. if(user==null) {
  81. return R.error("账号不存在");
  82. }
  83. user.setPassword("123456");
  84. userService.update(user,null);
  85. return R.ok("密码已重置为:123456");
  86. }
  87. /**
  88. * 列表
  89. */
  90. @RequestMapping("/page")
  91. public R page(@RequestParam Map params,UserEntity user){
  92. EntityWrapper ew = new EntityWrapper();
  93. PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
  94. return R.ok().put("data", page);
  95. }
  96. /**
  97. * 列表
  98. */
  99. @RequestMapping("/list")
  100. public R list( UserEntity user){
  101. EntityWrapper ew = new EntityWrapper();
  102. ew.allEq(MPUtil.allEQMapPre( user, "user"));
  103. return R.ok().put("data", userService.selectListView(ew));
  104. }
  105. /**
  106. * 信息
  107. */
  108. @RequestMapping("/info/{id}")
  109. public R info(@PathVariable("id") String id){
  110. UserEntity user = userService.selectById(id);
  111. return R.ok().put("data", user);
  112. }
  113. /**
  114. * 获取用户的session用户信息
  115. */
  116. @RequestMapping("/session")
  117. public R getCurrUser(HttpServletRequest request){
  118. Long id = (Long)request.getSession().getAttribute("userId");
  119. UserEntity user = userService.selectById(id);
  120. return R.ok().put("data", user);
  121. }
  122. /**
  123. * 保存
  124. */
  125. @PostMapping("/save")
  126. public R save(@RequestBody UserEntity user){
  127. // ValidatorUtils.validateEntity(user);
  128. if(userService.selectOne(new EntityWrapper().eq("username", user.getUsername())) !=null) {
  129. return R.error("用户已存在");
  130. }
  131. userService.insert(user);
  132. return R.ok();
  133. }
  134. /**
  135. * 修改
  136. */
  137. @RequestMapping("/update")
  138. public R update(@RequestBody UserEntity user){
  139. // ValidatorUtils.validateEntity(user);
  140. userService.updateById(user);//全部更新
  141. return R.ok();
  142. }
  143. /**
  144. * 删除
  145. */
  146. @RequestMapping("/delete")
  147. public R delete(@RequestBody Long[] ids){
  148. userService.deleteBatchIds(Arrays.asList(ids));
  149. return R.ok();
  150. }
  151. }

4.2文件上传

  1. package com.controller;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.util.Arrays;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Random;
  11. import java.util.UUID;
  12. import org.apache.commons.io.FileUtils;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.http.HttpHeaders;
  16. import org.springframework.http.HttpStatus;
  17. import org.springframework.http.MediaType;
  18. import org.springframework.http.ResponseEntity;
  19. import org.springframework.util.ResourceUtils;
  20. import org.springframework.web.bind.annotation.PathVariable;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.RequestParam;
  24. import org.springframework.web.bind.annotation.RestController;
  25. import org.springframework.web.multipart.MultipartFile;
  26. import com.annotation.IgnoreAuth;
  27. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  28. import com.entity.ConfigEntity;
  29. import com.entity.EIException;
  30. import com.service.ConfigService;
  31. import com.utils.R;
  32. /**
  33. * 上传文件映射表
  34. */
  35. @RestController
  36. @RequestMapping("file")
  37. @SuppressWarnings({
  38. "unchecked","rawtypes"})
  39. public class FileController{
  40. @Autowired
  41. private ConfigService configService;
  42. /**
  43. * 上传文件
  44. */
  45. @RequestMapping("/upload")
  46. public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
  47. if (file.isEmpty()) {
  48. throw new EIException("上传文件不能为空");
  49. }
  50. String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
  51. File path = new File(ResourceUtils.getURL("classpath:static").getPath());
  52. if(!path.exists()) {
  53. path = new File("");
  54. }
  55. File upload = new File(path.getAbsolutePath(),"/upload/");
  56. if(!upload.exists()) {
  57. upload.mkdirs();
  58. }
  59. String fileName = new Date().getTime()+"."+fileExt;
  60. File dest = new File(upload.getAbsolutePath()+"/"+fileName);
  61. file.transferTo(dest);
  62. FileUtils.copyFile(dest, new File("C:\\Users\\Desktop\\jiadian\\springbootl7own\\src\\main\\resources\\static\\upload"+"/"+fileName));
  63. if(StringUtils.isNotBlank(type) && type.equals("1")) {
  64. ConfigEntity configEntity = configService.selectOne(new EntityWrapper().eq("name", "faceFile"));
  65. if(configEntity==null) {
  66. configEntity = new ConfigEntity();
  67. configEntity.setName("faceFile");
  68. configEntity.setValue(fileName);
  69. } else {
  70. configEntity.setValue(fileName);
  71. }
  72. configService.insertOrUpdate(configEntity);
  73. }
  74. return R.ok().put("file", fileName);
  75. }
  76. /**
  77. * 下载文件
  78. */
  79. @IgnoreAuth
  80. @RequestMapping("/download")
  81. public ResponseEntity download(@RequestParam String fileName) {
  82. try {
  83. File path = new File(ResourceUtils.getURL("classpath:static").getPath());
  84. if(!path.exists()) {
  85. path = new File("");
  86. }
  87. File upload = new File(path.getAbsolutePath(),"/upload/");
  88. if(!upload.exists()) {
  89. upload.mkdirs();
  90. }
  91. File file = new File(upload.getAbsolutePath()+"/"+fileName);
  92. if(file.exists()){
  93. /*if(!fileService.canRead(file, SessionManager.getSessionUser())){
  94. getResponse().sendError(403);
  95. }*/
  96. HttpHeaders headers = new HttpHeaders();
  97. headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
  98. headers.setContentDispositionFormData("attachment", fileName);
  99. return new ResponseEntity(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
  100. }
  101. } catch (IOException e) {
  102. e.printStackTrace();
  103. }
  104. return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
  105. }
  106. }

4.3封装

  1. package com.utils;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. /**
  5. * 返回数据
  6. */
  7. public class R extends HashMap {
  8. private static final long serialVersionUID = 1L;
  9. public R() {
  10. put("code", 0);
  11. }
  12. public static R error() {
  13. return error(500, "未知异常,请联系管理员");
  14. }
  15. public static R error(String msg) {
  16. return error(500, msg);
  17. }
  18. public static R error(int code, String msg) {
  19. R r = new R();
  20. r.put("code", code);
  21. r.put("msg", msg);
  22. return r;
  23. }
  24. public static R ok(String msg) {
  25. R r = new R();
  26. r.put("msg", msg);
  27. return r;
  28. }
  29. public static R ok(Map map) {
  30. R r = new R();
  31. r.putAll(map);
  32. return r;
  33. }
  34. public static R ok() {
  35. return new R();
  36. }
  37. public R put(String key, Object value) {
  38. super.put(key, value);
  39. return this;
  40. }
  41. }

项目获取:

发表评论

表情:
评论列表 (有 0 条评论,126人围观)

还没有评论,来说两句吧...

相关阅读