当前位置:   article > 正文

基于java springboot宠物交易商城微信小程序源码和论文_宠物交易微信小程序

宠物交易微信小程序

安装教程

1.  先部署shop_db内数据库到MySQL
2.  启动shop_back后端服务器代码,在IDEA开发工具内使用,JDK1.8,需要MAVEN3.5环境
3.  在WebStorm(前端开发工具均可)内启动shop_front后台管理系统
4   小程序开发工具内使用shop_wx

 演示视频:

基于java springboot宠物交易商城微信小程序源码和论文

 

 

 

 

 

  1. package com.ndky.shop_back.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.ndky.shop_back.entity.User;
  4. import com.ndky.shop_back.service.LoginService;
  5. import org.apache.ibatis.annotations.Param;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import java.util.HashMap;
  11. @RestController
  12. public class LoginController {
  13. @Autowired
  14. LoginService loginService;
  15. @RequestMapping("/userLogin")
  16. public String userLogin(@RequestBody User user){
  17. String flag="error";
  18. User us=loginService.userLogin(user.getUser_name(),user.getUser_password());
  19. if(us!=null){
  20. flag="ok";
  21. }
  22. HashMap<String,Object> res=new HashMap<>();
  23. res.put("flag",flag);
  24. res.put("user",user);
  25. String res_json = JSON.toJSONString(res);
  26. return res_json;
  27. }
  28. @RequestMapping("/wxLogin")
  29. public String wxLogin(@Param("user_name") String user_name,@Param("user_password") String user_password){
  30. User user=loginService.wxLogin(user_name,user_password);
  31. String flag="error";
  32. if(user!=null){
  33. flag="ok";
  34. }
  35. HashMap<String,Object> res=new HashMap<>();
  36. res.put("flag",flag);
  37. res.put("user",user);
  38. String res_json = JSON.toJSONString(res);
  39. return res_json;
  40. }
  41. }

 

 

  1. package com.ndky.shop_back.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.ndky.shop_back.dao.GoodDao;
  5. import com.ndky.shop_back.entity.Good;
  6. import com.ndky.shop_back.entity.QueryInfo;
  7. import com.ndky.shop_back.service.GoodService;
  8. import com.ndky.shop_back.util.Consts;
  9. import org.apache.ibatis.annotations.Param;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestParam;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import org.springframework.web.multipart.MultipartFile;
  16. import java.io.File;
  17. import java.io.IOException;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. @RestController
  21. public class GoodController {
  22. @Autowired
  23. GoodService goodService;
  24. @RequestMapping("/allGood")
  25. public String getGoodList(QueryInfo queryInfo) {
  26. // 获取最大列表数和当前编号
  27. int number = goodService.getGoodCounts("%" + queryInfo.getQuery() + "%");
  28. int pageState = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
  29. List<Good> good = goodService.getAllGood("%" + queryInfo.getQuery() + "%", pageState, queryInfo.getPageSize());
  30. HashMap<String, Object> res = new HashMap<>();
  31. res.put("number", number);
  32. res.put("data", good);
  33. String res_string = JSON.toJSONString(res);
  34. return res_string;
  35. }
  36. @RequestMapping("/goodState")
  37. public String updateGoodState(@RequestParam("good_id") Integer good_id,
  38. @RequestParam("good_state") Boolean good_state) {
  39. int i = goodService.updateState(good_id, good_state);
  40. return i > 0 ? "success" : "error";
  41. }
  42. @RequestMapping("/addGood")
  43. public String addGood(@RequestBody Good good) {
  44. int i = goodService.addGood(good);
  45. return i > 0 ? "success" : "error";
  46. }
  47. @RequestMapping("/deleteGood")
  48. public String deleteGood(int good_id) {
  49. int i = goodService.deleteGood(good_id);
  50. return i > 0 ? "success" : "error";
  51. }
  52. @RequestMapping("/getUpdateGood")
  53. public String getUpdateGood(int good_id) {
  54. Good good=goodService.getUpdateGood(good_id);
  55. String string = JSON.toJSONString(good);//注意这里也可以直接返回对象,springboot会把对象直接转换成字符串
  56. return string;
  57. }
  58. @RequestMapping("/editGood")
  59. public String editUser(@RequestBody Good good) {
  60. int i = goodService.editGood(good);
  61. return i > 0 ? "success" : "error";
  62. }
  63. //查询所有商品,返回到微信小程序
  64. @RequestMapping("/selectAllGood")
  65. public String selectAllGood(){
  66. List<Good> list=goodService.selectAllGood();
  67. String string = JSON.toJSONString(list);//注意这里也可以直接返回对象,springboot会把对象直接转换成字符串
  68. return string;
  69. }
  70. //按照class_name查询商品,填充商品分类右边栏目
  71. @RequestMapping("/selectGoodByClass")
  72. public String selectGoodByClass(@Param("class_name") String class_name){
  73. List<Good> list=goodService.selectGoodByClass(class_name);
  74. String string = JSON.toJSONString(list);
  75. return string;
  76. }
  77. @RequestMapping("/selectGoodById")
  78. public String selectGoodById(@Param("good_id") Integer good_id){
  79. Good good=goodService.selectGoodById(good_id);
  80. String string = JSON.toJSONString(good);
  81. return string;
  82. }
  83. @RequestMapping("/searchGood")
  84. public String searchGood(@Param("query") String query){
  85. List<Good> list=goodService.searchGood(query);
  86. String string = JSON.toJSONString(list);
  87. return string;
  88. }
  89. @RequestMapping("/setGoodStar")
  90. public String setGoodStar(@Param("good_id") Integer good_id,@Param("good_star")Integer good_star){
  91. int i = goodService.setGoodStar(good_id, good_star);
  92. return i > 0 ? "success" : "error";
  93. }
  94. @RequestMapping("/getGoodByStar")
  95. public String getGoodByStar(QueryInfo queryInfo){
  96. // 获取最大列表数和当前编号
  97. int number = goodService.getGoodCounts("%" + queryInfo.getQuery() + "%");
  98. int pageState = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
  99. List<Good> good = goodService.getGoodByStar("%" + queryInfo.getQuery() + "%", pageState, queryInfo.getPageSize());
  100. HashMap<String, Object> res = new HashMap<>();
  101. res.put("number", number);
  102. res.put("data", good);
  103. String res_string = JSON.toJSONString(res);
  104. return res_string;
  105. }
  106. @RequestMapping("/getStarByGoodId")
  107. public Integer getStarByGoodId(@Param("good_id") Integer good_id){
  108. return goodService.getStarByGoodId(good_id);
  109. }
  110. //更新商品图片
  111. @RequestMapping("/updateGoodImage")
  112. public Object updateGoodImage(@RequestParam("file") MultipartFile avatorFile, @RequestParam("good_id")int id){
  113. JSONObject jsonObject = new JSONObject();
  114. if(avatorFile.isEmpty()){
  115. jsonObject.put(Consts.CODE,0);
  116. jsonObject.put(Consts.MSG,"文件上传失败");
  117. return jsonObject;
  118. }
  119. //文件名=当前时间到毫秒+原来的文件名
  120. String fileName = System.currentTimeMillis()+avatorFile.getOriginalFilename();
  121. //文件路径
  122. String filePath = System.getProperty("user.dir")+System.getProperty("file.separator")+"img"
  123. +System.getProperty("file.separator")+"goodImage";
  124. //如果文件路径不存在,新增该路径
  125. File file1 = new File(filePath);
  126. if(!file1.exists()){
  127. file1.mkdir();
  128. }
  129. //实际的文件地址
  130. File dest = new File(filePath+System.getProperty("file.separator")+fileName);
  131. //存储到数据库里的相对文件地址
  132. String storeAvatorPath = Consts.URL+"/img/goodImage/"+fileName;
  133. try {
  134. avatorFile.transferTo(dest);
  135. Good good=new Good();
  136. good.setGood_id(id);
  137. good.setGood_image(storeAvatorPath);
  138. int flag = goodService.editGood(good);
  139. if(flag>0){
  140. jsonObject.put(Consts.CODE,1);
  141. jsonObject.put(Consts.MSG,"上传成功");
  142. jsonObject.put("pic",storeAvatorPath);
  143. return jsonObject;
  144. }
  145. jsonObject.put(Consts.CODE,0);
  146. jsonObject.put(Consts.MSG,"上传失败");
  147. return jsonObject;
  148. } catch (IOException e) {
  149. jsonObject.put(Consts.CODE,0);
  150. jsonObject.put(Consts.MSG,"上传失败"+e.getMessage());
  151. }finally {
  152. return jsonObject;
  153. }
  154. }
  155. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/812903
推荐阅读
相关标签
  

闽ICP备14008679号