• Springboot+Vue实现前后端分离校园二手交易平台


    作者主页:编程指南针

    作者简介:Java领域优质创作者、CSDN博客专家 、掘金特邀作者、多年架构师设计经验、腾讯课堂常驻讲师

    主要内容:Java项目、毕业设计、简历模板、学习资料、面试题库、技术互助

    文末获取源码 

    项目编号:BS-PT-066

    一,项目简介

    本项目基于springboot+vue实现了一个前后端分离模式的校园二手交易平台。校内师生可以在此平台上注册自己的账户,然后发布自己想要处理的二手物品,平台本身不实现在线交易功能,发布的二手物品由买卖双方自行联系进行线下交易。主要实现的功能有用户注册、登陆、发布商品、收藏商品、统计浏览量和收藏量、在线留言、全文检索、管理个人发布的商品和留言等功能。系统功能完整,业务模式清晰,开发结构简单,比较符合目前后端分离模式开发的主流诉求,可以用作毕业设计或课程设计以及期未作业使用。

    二,环境介绍

    语言环境:Java:  jdk1.8

    数据库:Mysql: mysql5.7   REDIS缓存数据库

    应用服务器:Tomcat:  tomcat8.5.31

    开发工具:IDEA或eclipse

    后台开发技术:springboot+mybatisplus+jdk8+mysql5.6

    前后台开发技术:VUE+ElementsUI

    三,系统展示

     

    用户登陆注册

    发布二手物品

    查看详情

    查看我的收藏

    查看我发布的商品:可以进行商品上下架 和删除操作

    管理我发布的留言

    四,核心代码展示

    1. package cn.fleamarket.controller;
    2. import cn.fleamarket.common.R;
    3. import cn.fleamarket.domain.Favorites;
    4. import cn.fleamarket.domain.User;
    5. import cn.fleamarket.service.FavoritesService;
    6. import cn.fleamarket.service.UserService;
    7. import cn.fleamarket.utils.StringTool;
    8. import com.alibaba.fastjson.JSONObject;
    9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    10. import io.swagger.annotations.ApiOperation;
    11. import org.springframework.beans.factory.annotation.Autowired;
    12. import org.springframework.web.bind.annotation.PostMapping;
    13. import org.springframework.web.bind.annotation.RequestBody;
    14. import org.springframework.web.bind.annotation.RequestMapping;
    15. import org.springframework.web.bind.annotation.RestController;
    16. import javax.servlet.http.HttpServletRequest;
    17. import javax.servlet.http.HttpServletResponse;
    18. import java.util.*;
    19. import java.util.concurrent.ConcurrentHashMap;
    20. import java.util.function.Function;
    21. import java.util.function.Predicate;
    22. import java.util.stream.Collectors;
    23. /**
    24. * 产品收藏表
    25. *
    26. * @author znz
    27. * @date 2022-09-12 10:46:22
    28. */
    29. @RestController
    30. @RequestMapping("/favorites")
    31. public class FavoritesController {
    32. @Autowired
    33. private FavoritesService favoritesService;
    34. @Autowired
    35. UserService userService;
    36. @PostMapping(value = "/favoriteList", produces = "application/json")
    37. @ApiOperation("收藏分页查询列表,入参是page:第几页,number:每页几条")
    38. public R> favoritesList(@RequestBody Map params) {
    39. if (Objects.isNull(params)) {
    40. return R.error("参数错误!");
    41. }
    42. User nowUser = userService.qureyByUserName(params.getOrDefault("username","").toString());
    43. if (Objects.isNull(nowUser)) {
    44. return R.error("用户未登录!");
    45. }
    46. params.put("userId",nowUser.getId());
    47. Page favoritesPage = favoritesService.selectListPage(params);
    48. List data = favoritesPage
    49. .getRecords().stream()
    50. .filter(distinctByKey(Favorites::getProductId))
    51. .collect(Collectors.toList());
    52. return R.pageBuild(favoritesPage.getTotal(),
    53. favoritesPage.hasNext(),
    54. favoritesPage.hasPrevious(), data);
    55. }
    56. @PostMapping(value = "/addFavorites", produces = "application/json")
    57. @ApiOperation("添加收藏,pid:商品id")
    58. public JSONObject addFavorites(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) {
    59. JSONObject ret = new JSONObject();
    60. User user = null;
    61. try {
    62. user = userService.qureyByUserName(jsonObject.getString("username"));
    63. } catch (Exception e) {
    64. e.printStackTrace();
    65. }
    66. try {
    67. List list = favoritesService.selectByUid(user.getId());
    68. if (list.size() != 0) {
    69. for (int i = 0; i < list.size(); i++) {
    70. if (list.get(i).getProductId().equals(jsonObject.getString("pid"))) {
    71. ret.put("code", -1);
    72. ret.put("data", false);
    73. ret.put("msg", "添加失败");
    74. return ret;
    75. }
    76. }
    77. }
    78. if (user != null) {
    79. String productId = jsonObject.getString("pid");
    80. Integer state = jsonObject.getInteger("state");
    81. Favorites favorites = new Favorites();
    82. favorites.setId(StringTool.getUUID());
    83. favorites.setUserId(user.getId());
    84. favorites.setProductId(productId);
    85. favorites.setCreateTime(new Date());
    86. favorites.setState(state);
    87. Integer isS = favoritesService.addFavorites(favorites);
    88. if (isS > 0) {
    89. ret.put("data", true);
    90. ret.put("code", 0);
    91. ret.put("msg", "添加成功");
    92. } else {
    93. ret.put("code", -1);
    94. ret.put("data", false);
    95. ret.put("msg", "添加失败");
    96. }
    97. } else {
    98. ret.put("msg", "用户未登录");
    99. }
    100. } catch (Exception e) {
    101. e.printStackTrace();
    102. ret.put("code", -1);
    103. ret.put("data", false);
    104. ret.put("msg", "未知错误");
    105. }
    106. return ret;
    107. }
    108. @PostMapping(value = "/deleteFavorites", produces = "application/json")
    109. @ApiOperation("删除收藏,fid:收藏id")
    110. public JSONObject deleteFavorites(@RequestBody JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) {
    111. JSONObject ret = new JSONObject();
    112. User user = null;
    113. try {
    114. user = userService.qureyByUserName(jsonObject.getString("username"));
    115. } catch (Exception e) {
    116. e.printStackTrace();
    117. }
    118. try {
    119. if (user != null) {
    120. String fid = jsonObject.getString("fid");
    121. Integer isS = favoritesService.deleteFavorites(fid);
    122. if (isS > 0) {
    123. ret.put("code", 0);
    124. ret.put("data", true);
    125. ret.put("msg", "删除成功");
    126. }
    127. } else {
    128. ret.put("msg", "用户未登录");
    129. }
    130. } catch (Exception e) {
    131. e.printStackTrace();
    132. ret.put("code", -1);
    133. ret.put("data", false);
    134. ret.put("msg", "删除失败");
    135. }
    136. return ret;
    137. }
    138. private static Predicate distinctByKey(Functionsuper T, ?> keyExtractor) {
    139. Map seen = new ConcurrentHashMap<>();
    140. return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    141. }
    142. }

    1. package cn.fleamarket.controller;
    2. import cn.fleamarket.common.R;
    3. import cn.fleamarket.config.PathConfig;
    4. import cn.fleamarket.domain.Image;
    5. import cn.fleamarket.service.ImageService;
    6. import cn.fleamarket.utils.StringTool;
    7. import com.alibaba.fastjson.JSONObject;
    8. import io.swagger.annotations.Api;
    9. import io.swagger.annotations.ApiOperation;
    10. import lombok.SneakyThrows;
    11. import org.springframework.beans.factory.annotation.Autowired;
    12. import org.springframework.web.bind.annotation.CrossOrigin;
    13. import org.springframework.web.bind.annotation.PostMapping;
    14. import org.springframework.web.bind.annotation.RequestMapping;
    15. import org.springframework.web.bind.annotation.RestController;
    16. import org.springframework.web.multipart.MultipartFile;
    17. import java.io.File;
    18. import java.util.Objects;
    19. /**
    20. * 图片表
    21. *
    22. * @author znz
    23. * @date 2022-09-12 10:46:22
    24. */
    25. @RestController
    26. @RequestMapping("/image")
    27. @Api("图片接口")
    28. @CrossOrigin
    29. public class ImageController {
    30. @Autowired
    31. ImageService imageService;
    32. @Autowired
    33. private PathConfig pathConfig;
    34. /**
    35. * 上传img
    36. *
    37. * @param file 文件
    38. * @return {@link JSONObject}
    39. */
    40. @SneakyThrows
    41. @PostMapping("/uploadImg")
    42. @ApiOperation("图片上传")
    43. public R uploadImg(MultipartFile file) {
    44. JSONObject ret = new JSONObject();
    45. String fileName = file.getOriginalFilename();
    46. String newFileName = StringTool.getUUID() + Objects.requireNonNull(fileName).substring(fileName.indexOf("."));
    47. Image image = new Image();
    48. File file1;
    49. String os = System.getProperty("os.name");
    50. if (os.toLowerCase().startsWith("win")) {
    51. file1 = new File(pathConfig.getWinPath(), newFileName);
    52. } else {
    53. file1 = new File(pathConfig.getWinPath(), newFileName);
    54. }
    55. if (!file1.exists()) {
    56. System.out.println(file1.mkdir());
    57. }
    58. file.transferTo(file1);
    59. image.setId(StringTool.getUUID());
    60. image.setImgUrl(newFileName);
    61. imageService.insert(image);
    62. return R.ok(0,"图片上传成功",File.separator + "static" + File.separator + "img" + File.separator + image.getImgUrl());
    63. }
    64. }

    1. package cn.fleamarket.controller;
    2. import cn.fleamarket.domain.Message;
    3. import cn.fleamarket.domain.User;
    4. import cn.fleamarket.service.MessageService;
    5. import cn.fleamarket.service.UserService;
    6. import cn.fleamarket.utils.StringTool;
    7. import com.alibaba.fastjson.JSONObject;
    8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    9. import io.swagger.annotations.Api;
    10. import io.swagger.annotations.ApiOperation;
    11. import org.springframework.beans.factory.annotation.Autowired;
    12. import org.springframework.web.bind.annotation.*;
    13. import javax.servlet.http.HttpServletRequest;
    14. import java.util.Date;
    15. import java.util.HashMap;
    16. import java.util.List;
    17. import java.util.Map;
    18. /**
    19. * 留言接口
    20. */
    21. @RestController
    22. @RequestMapping("/message")
    23. @Api("留言接口")
    24. public class MessageController {
    25. @Autowired
    26. MessageService messageService;
    27. @Autowired
    28. UserService userService;
    29. @PostMapping(value = "/messageList", produces = "application/json")
    30. @ApiOperation("分页查询留言列表,入参是page:第几页,number:每页几条,pId:属于哪个商品的id")
    31. public JSONObject messageList(@RequestBody JSONObject jsonObject) {
    32. JSONObject ret = new JSONObject();
    33. try {
    34. Long page = jsonObject.getLong("page");
    35. Long number = jsonObject.getLong("number");
    36. String pId = jsonObject.getString("pId");
    37. Map map = new HashMap<>();
    38. map.put("page", page);
    39. map.put("number", number);
    40. map.put("pId", pId);
    41. if (page != null && number != null) {
    42. Page messagePage = messageService.selectListPage(map);
    43. List messagesList = messagePage.getRecords();
    44. ret.put("code", 0);
    45. ret.put("data", StringTool.ListToJsonArray(messagesList));
    46. ret.put("total", messagePage.getTotal());//总数
    47. ret.put("next", messagePage.hasNext());//下一页
    48. ret.put("previous", messagePage.hasPrevious());//上一页
    49. ret.put("msg", "查询成功");
    50. }
    51. } catch (Exception e) {
    52. e.printStackTrace();
    53. ret.put("code", -1);
    54. ret.put("data", null);
    55. ret.put("msg", "查询失败");
    56. }
    57. return ret;
    58. }
    59. @PostMapping("/addMessage")
    60. @ApiOperation("新增留言接口,text:留言内容,tid:发送人(不用填),fid:接受人(填商品id)")
    61. public JSONObject addMessage(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
    62. JSONObject ret = new JSONObject();
    63. Message message = new Message();
    64. try {
    65. User user = userService.qureyByUserName(jsonObject.getString("username"));
    66. message.setTid(user.getId());
    67. message.setTime(new Date());
    68. message.setId(StringTool.getUUID());
    69. message.setFid(jsonObject.getString("fid"));
    70. message.setText(jsonObject.getString("text"));
    71. if (messageService.addMessage(message) > 0) {
    72. ret.put("code", 0);
    73. ret.put("data", true);
    74. ret.put("msg", "新增留言成功");
    75. } else {
    76. ret.put("code", -1);
    77. ret.put("data", false);
    78. ret.put("msg", "新增留言失败");
    79. }
    80. } catch (Exception e) {
    81. e.printStackTrace();
    82. ret.put("code", -1);
    83. ret.put("data", false);
    84. ret.put("msg", "新增留言失败");
    85. }
    86. return ret;
    87. }
    88. @PostMapping(value = "/messageListByUser", produces = "application/json")
    89. @ApiOperation("分页查询我的留言,入参是page:第几页,number:每页几条")
    90. public JSONObject productListByUser(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
    91. JSONObject ret = new JSONObject();
    92. try {
    93. Long page = jsonObject.getLong("page");
    94. Long number = jsonObject.getLong("number");
    95. Map map = new HashMap<>();
    96. User user = userService.qureyByUserName(jsonObject.getString("username"));
    97. map.put("page", page);
    98. map.put("number", number);
    99. map.put("userId", user.getId());
    100. if (page != null && number != null) {
    101. Page messagePage = messageService.selectListPageByUser(map);
    102. List messageList = messagePage.getRecords();
    103. ret.put("code", 0);
    104. ret.put("data", StringTool.ListToJsonArray(messageList));
    105. ret.put("total", messagePage.getTotal());//总数
    106. ret.put("next", messagePage.hasNext());//下一页
    107. ret.put("previous", messagePage.hasPrevious());//上一页
    108. ret.put("msg", "查询成功");
    109. }
    110. } catch (Exception e) {
    111. ret.put("code", -1);
    112. ret.put("data", null);
    113. ret.put("msg", "查询失败");
    114. e.printStackTrace();
    115. }
    116. return ret;
    117. }
    118. @PostMapping("/delete")
    119. @ApiOperation("删除留言接口,主要传留言id即可")
    120. public JSONObject delete(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
    121. JSONObject ret = new JSONObject();
    122. String pId = jsonObject.getString("id");
    123. User user = null;
    124. try {
    125. user = userService.qureyByUserName(jsonObject.getString("username"));
    126. } catch (Exception e) {
    127. e.printStackTrace();
    128. }
    129. try {
    130. int i = messageService.delete(user.getId(), pId);
    131. if (i > 0) {
    132. ret.put("code", "0");
    133. ret.put("data", true);
    134. ret.put("msg", "删除留言成功");
    135. } else {
    136. ret.put("code", "-1");
    137. ret.put("data", false) ;
    138. ret.put("msg", "删除留言失败");
    139. }
    140. } catch (Exception e) {
    141. ret.put("code", "-1");
    142. ret.put("data", false);
    143. ret.put("msg", "删除留言失败");
    144. e.printStackTrace();
    145. }
    146. return ret;
    147. }
    148. }

    1. package cn.fleamarket.controller;
    2. import java.util.*;
    3. import cn.fleamarket.domain.Product;
    4. import cn.fleamarket.domain.User;
    5. import cn.fleamarket.service.MessageService;
    6. import cn.fleamarket.service.ProductService;
    7. import cn.fleamarket.service.UserService;
    8. import cn.fleamarket.utils.StringTool;
    9. import com.alibaba.fastjson.JSONArray;
    10. import com.alibaba.fastjson.JSONObject;
    11. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    12. import io.swagger.annotations.Api;
    13. import io.swagger.annotations.ApiOperation;
    14. import org.springframework.beans.factory.annotation.Autowired;
    15. import org.springframework.web.bind.annotation.*;
    16. import javax.servlet.http.HttpServletRequest;
    17. /**
    18. * 商品表
    19. *
    20. * @author znz
    21. * @email ${email}
    22. * @date 2022-09-12 10:46:22
    23. */
    24. @RestController
    25. @RequestMapping("/product")
    26. @Api("商品接口")
    27. public class ProductController {
    28. @Autowired
    29. ProductService productService;
    30. @Autowired
    31. UserService userService;
    32. @Autowired
    33. MessageService messageService;
    34. @PostMapping(value = "/productList", produces = "application/json")
    35. @ApiOperation("分页查询列表,入参是page:第几页,number:每页几条,key:查询条件(可选)")
    36. public JSONObject productList(@RequestBody JSONObject jsonObject) {
    37. JSONObject ret = new JSONObject();
    38. try {
    39. Long page = jsonObject.getLong("page");
    40. Long number = jsonObject.getLong("number");
    41. String key = jsonObject.getString("key");
    42. JSONArray jsonArray = jsonObject.getJSONArray("pId");
    43. Map map = new HashMap<>();
    44. map.put("page", page);
    45. map.put("number", number);
    46. map.put("key", key);
    47. if (page != null && number != null) {
    48. Page productPage = productService.selectListPage(map);
    49. List productList = productPage.getRecords();
    50. ret.put("code", 0);
    51. ret.put("data", StringTool.ListToJsonArray(productList));
    52. ret.put("total", productPage.getTotal());//总数
    53. ret.put("next", productPage.hasNext());//下一页
    54. ret.put("previous", productPage.hasPrevious());//上一页
    55. ret.put("msg", "查询成功");
    56. return ret;
    57. }
    58. if (jsonArray.size() != 0 && jsonArray != null) {
    59. List list = new ArrayList<>();
    60. for (int i = 0; i < jsonArray.size(); i++) {
    61. Product product = productService.selectById(jsonArray.get(i).toString());
    62. list.add(product);
    63. }
    64. ret.put("code", 0);
    65. ret.put("data", StringTool.ListToJsonArray(list));
    66. ret.put("msg", "查询成功");
    67. return ret;
    68. }
    69. } catch (Exception e) {
    70. ret.put("code", -1);
    71. ret.put("data", null);
    72. ret.put("msg", "查询失败");
    73. }
    74. return ret;
    75. }
    76. @PostMapping(value = "/productListByUser", produces = "application/json")
    77. @ApiOperation("分页查询属于某个用户的商品列表,就是我发布的商品,入参是page:第几页,number:每页几条")
    78. public JSONObject productListByUser(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
    79. JSONObject ret = new JSONObject();
    80. try {
    81. Long page = jsonObject.getLong("page");
    82. Long number = jsonObject.getLong("number");
    83. Map map = new HashMap<>();
    84. User user = userService.qureyByUserName(jsonObject.getString("username"));
    85. map.put("page", page);
    86. map.put("number", number);
    87. map.put("userId", user.getId());
    88. if (page != null && number != null) {
    89. Page productPage = productService.selectListPageByUser(map);
    90. List productList = productPage.getRecords();
    91. ret.put("code", 0);
    92. ret.put("data", StringTool.ListToJsonArray(productList));
    93. ret.put("total", productPage.getTotal());//总数
    94. ret.put("next", productPage.hasNext());//下一页
    95. ret.put("previous", productPage.hasPrevious());//上一页
    96. ret.put("msg", "查询成功");
    97. }
    98. } catch (Exception e) {
    99. ret.put("code", -1);
    100. ret.put("data", null);
    101. ret.put("msg", "查询失败");
    102. }
    103. return ret;
    104. }
    105. @PostMapping(value = "/productListById", produces = "application/json")
    106. @ApiOperation("分页查询属于某个用户的商品列表,就是我发布的商品,入参是page:第几页,number:每页几条")
    107. public JSONObject productListById(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
    108. JSONObject ret = new JSONObject();
    109. try {
    110. Long page = jsonObject.getLong("page");
    111. Long number = jsonObject.getLong("number");
    112. Object[] pIds = jsonObject.getJSONArray("pId").toArray();
    113. List list = new ArrayList();
    114. for (int i = 0; i < pIds.length; i++) {
    115. if (!list.contains(pIds[i])) {
    116. list.add(pIds[i]);
    117. }
    118. }
    119. Object[] pIdss = list.toArray();
    120. Map map = new HashMap<>();
    121. map.put("page", page);
    122. map.put("number", number);
    123. map.put("pId", pIdss);
    124. if (page != null && number != null && pIds != null) {
    125. Page productPage = productService.selectListsPageById(map);
    126. List productList = productPage.getRecords();
    127. ret.put("code", 0);
    128. ret.put("data", StringTool.ListToJsonArray(productList));
    129. ret.put("total", productPage.getTotal());//总数
    130. ret.put("next", productPage.hasNext());//下一页
    131. ret.put("previous", productPage.hasPrevious());//上一页
    132. ret.put("msg", "查询成功");
    133. }
    134. } catch (Exception e) {
    135. ret.put("code", -1);
    136. ret.put("data", null);
    137. ret.put("msg", "查询失败");
    138. }
    139. return ret;
    140. }
    141. @PostMapping(value = "/productListByIds", produces = "application/json")
    142. @ApiOperation("分页查询属于某个用户的商品列表,就是我发布的商品,入参是page:第几页,number:每页几条")
    143. public JSONObject productListByIds(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
    144. JSONObject ret = new JSONObject();
    145. try {
    146. Object[] pIds = jsonObject.getJSONArray("pId").toArray();
    147. List productList = new ArrayList<>();
    148. for (int i = 0; i < pIds.length; i++) {
    149. Product product = productService.selectById(pIds[i].toString());
    150. productList.add(product);
    151. }
    152. ret.put("code", 0);
    153. ret.put("data", StringTool.ListToJsonArray(productList));
    154. ret.put("msg", "查询成功");
    155. } catch (Exception e) {
    156. ret.put("code", -1);
    157. ret.put("data", null);
    158. ret.put("msg", "查询失败");
    159. }
    160. return ret;
    161. }
    162. @PutMapping("/addProduct")
    163. @ApiOperation("增加商品,入参是要增加的商品信息,记得带上上传图片接口返回的url")
    164. public JSONObject addProduct(@RequestBody JSONObject par, HttpServletRequest request) {
    165. JSONObject ret = new JSONObject();
    166. try {
    167. Product product = new Product();
    168. product.setId(StringTool.getUUID());
    169. product.setCreateTime(new Date());
    170. product.setBprice(par.getDouble("bprice"));
    171. product.setTitle(par.getString("title"));
    172. product.setImgUrl(par.getString("imgUrl"));
    173. product.setPrice(par.getDouble("price"));
    174. product.setContent(par.getString("content"));
    175. User user = userService.qureyByUserName(par.getString("username"));
    176. product.setUserId(user.getId());
    177. int i = productService.insert(product);
    178. if (i > 0) {
    179. ret.put("code", 0);
    180. ret.put("data", true);
    181. ret.put("msg", "增加成功");
    182. } else {
    183. ret.put("code", -1);
    184. ret.put("data", false);
    185. ret.put("msg", "增加失败");
    186. }
    187. } catch (Exception e) {
    188. ret.put("code", -1);
    189. ret.put("data", false);
    190. ret.put("msg", "增加失败");
    191. }
    192. return ret;
    193. }
    194. @PutMapping("/update")
    195. @ApiOperation("修改商品信息,传入要修改的信息,主要是商品id")
    196. public JSONObject update(Product product) {
    197. JSONObject ret = new JSONObject();
    198. product.setCreateTime(new Date());
    199. try {
    200. if (product.getId() != null && productService.update(product) > 0) {
    201. ret.put("code", "0");
    202. ret.put("data", true);
    203. ret.put("msg", "修改成功");
    204. } else {
    205. ret.put("code", "-1");
    206. ret.put("data", false);
    207. ret.put("msg", "修改失败");
    208. }
    209. } catch (Exception e) {
    210. ret.put("code", "-1");
    211. ret.put("data", false);
    212. ret.put("msg", "修改失败");
    213. e.printStackTrace();
    214. }
    215. return ret;
    216. }
    217. @PutMapping("/obtained")
    218. @ApiOperation("上架下架接口,主要传id即可")
    219. public JSONObject Obtained(@RequestBody JSONObject id) {
    220. JSONObject ret = new JSONObject();
    221. try {
    222. String dbId = id.getString("id");
    223. Product product = productService.selectById(dbId);
    224. if (product != null && product.getIsShow() == 1) {
    225. productService.updateById(dbId, true);
    226. ret.put("code", "0");
    227. ret.put("data", true);
    228. ret.put("msg", "下架成功");
    229. } else if (product != null && product.getIsShow() == 0) {
    230. productService.updateById(dbId, false);
    231. ret.put("code", "0");
    232. ret.put("data", true);
    233. ret.put("msg", "上架成功");
    234. } else {
    235. ret.put("code", "-1");
    236. ret.put("data", false);
    237. ret.put("msg", "修改失败");
    238. }
    239. } catch (Exception e) {
    240. ret.put("code", "-1");
    241. ret.put("data", false);
    242. ret.put("msg", "修改失败");
    243. e.printStackTrace();
    244. }
    245. return ret;
    246. }
    247. @GetMapping("/selectById")
    248. @ApiOperation("查询商品详情,传id即可,id是个字符串")
    249. public JSONObject selectById(String id) {
    250. JSONObject ret = new JSONObject();
    251. try {
    252. Product product = productService.selectById(id);
    253. if (product != null) {
    254. ret.put("code", "0");
    255. ret.put("data", StringTool.ObjectToJSONObject(product));
    256. ret.put("msg", "查询商品详情成功");
    257. } else {
    258. ret.put("code", "-1");
    259. ret.put("data", false);
    260. ret.put("msg", "查询商品详情失败");
    261. }
    262. } catch (Exception e) {
    263. ret.put("code", "-1");
    264. ret.put("data", false);
    265. ret.put("msg", "查询商品详情失败");
    266. e.printStackTrace();
    267. }
    268. return ret;
    269. }
    270. @PutMapping("/addCount")
    271. @ApiOperation("增加浏览次数接口,主要传id即可,当用户打开商品页的时候发这个请求")
    272. public JSONObject Increase(@RequestBody JSONObject id) {
    273. JSONObject ret = new JSONObject();
    274. try {
    275. String dbId = id.getString("id");
    276. Product product = productService.selectById(dbId);
    277. if (product != null) {
    278. productService.updateIncrease(product);
    279. ret.put("code", "0");
    280. ret.put("data", true);
    281. ret.put("msg", "增加浏览次数成功");
    282. } else {
    283. ret.put("code", "-1");
    284. ret.put("data", false);
    285. ret.put("msg", "增加浏览次数失败");
    286. }
    287. } catch (Exception e) {
    288. ret.put("code", "-1");
    289. ret.put("data", false);
    290. ret.put("msg", "增加浏览次数失败");
    291. e.printStackTrace();
    292. }
    293. return ret;
    294. }
    295. @PostMapping("/delete")
    296. @ApiOperation("删除商品接口,主要传商品id即可")
    297. public JSONObject delete(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
    298. JSONObject ret = new JSONObject();
    299. String pId = jsonObject.getString("id");
    300. User user = null;
    301. try {
    302. user = userService.qureyByUserName(jsonObject.getString("username"));
    303. } catch (Exception e) {
    304. e.printStackTrace();
    305. }
    306. try {
    307. int i = productService.delete(user.getId(), pId);
    308. if (i > 0) {
    309. if(messageService.deletebyFid(pId)>0) {
    310. ret.put("code", "0");
    311. ret.put("data", true);
    312. ret.put("msg", "删除商品成功");
    313. }
    314. } else {
    315. ret.put("code", "-1");
    316. ret.put("data", false);
    317. ret.put("msg", "删除商品失败");
    318. }
    319. } catch (Exception e) {
    320. ret.put("code", "-1");
    321. ret.put("data", false);
    322. ret.put("msg", "删除商品失败");
    323. e.printStackTrace();
    324. }
    325. return ret;
    326. }
    327. }
    328. 五,项目总结

    329. 相关阅读:
      linux中好玩的数据流定向和管道命令一
      多御安全浏览器更新,这3个设置让你体验感提升
      【面试题精讲】finally 中的代码一定会执行吗?
      如何将代码写的更加优雅?
      【完美世界】石昊挑逗云曦,斩杀神级猿魔,吃血魂草开新挂,团灭战族追兵
      Android 实现 Alexa App-to-App Account Linking
      一图汇总项目管理工具与技术
      【面试】class文件里面是什么?
      【Axure高保真原型】多图表动态切换
      Apache Doris以Routine Load方式流式的导入Kafka数据
    330. 原文地址:https://blog.csdn.net/whirlwind526/article/details/127094094