• Java项目:SSM的校园二手交易平台


    作者主页:夜未央5788

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

    项目介绍

    本次设计的是一个校园二手交易平台(C2C),C2C指个人与个人之间的电子商务,买家可以查看所有卖家发布的商品,并且根据分类进行商品过滤,也可以根据站内搜索引擎进行商品的查询,并且与卖家联系,达成交易的意向,也可以发布求购的信息,让卖家查看之后,与之联系,进行交易。而此次主要是针对校园用户所设计的网站,对于数据的分类应该更多的考虑校园用户的需求,例如二手书籍、二手数码等的分类应该更加细致。由于是C2C的项目,因此本项目无需后台管理。

    环境需要

    1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
    2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
    3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
    4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
    5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 

    6.数据库:MySql 5.7版本;

    技术栈

    1. 后端:Spring SpringMVC MyBatis

    2. 前端:Thymeleaf+Html+jQuery

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

    若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;

    3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;

    4. 运行项目,输入localhost:8080/xxx 登录

    运行截图

    相关代码 

    HomeController

    1. package com.wsk.controller;
    2. import com.wsk.bean.ShopInformationBean;
    3. import com.wsk.pojo.*;
    4. import com.wsk.service.*;
    5. import com.wsk.tool.StringUtils;
    6. import org.springframework.stereotype.Controller;
    7. import org.springframework.ui.Model;
    8. import org.springframework.web.bind.annotation.RequestMapping;
    9. import org.springframework.web.bind.annotation.RequestMethod;
    10. import org.springframework.web.bind.annotation.RequestParam;
    11. import org.springframework.web.bind.annotation.ResponseBody;
    12. import javax.annotation.Resource;
    13. import javax.servlet.http.HttpServletRequest;
    14. import java.util.ArrayList;
    15. import java.util.HashMap;
    16. import java.util.List;
    17. import java.util.Map;
    18. /**
    19. * Created by wsk1103 on 2017/5/11.
    20. */
    21. @Controller
    22. public class HomeController {
    23. @Resource
    24. private ShopInformationService shopInformationService;
    25. @Resource
    26. private SpecificeService specificeService;
    27. @Resource
    28. private ClassificationService classificationService;
    29. @Resource
    30. private AllKindsService allKindsService;
    31. @Resource
    32. private ShopContextService shopContextService;
    33. @RequestMapping(value = {"/", "/home.do"})
    34. public String home(HttpServletRequest request, Model model) {
    35. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    36. // if user login,the session will have the "userInformation"
    37. if (!StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    38. model.addAttribute("userInformation", userInformation);
    39. } else {
    40. userInformation = new UserInformation();
    41. model.addAttribute("userInformation", userInformation);
    42. }
    43. //一般形式进入首页
    44. try {
    45. List shopInformations = selectTen(1, 5);
    46. List list = new ArrayList<>();
    47. int counts = getShopCounts();
    48. model.addAttribute("shopInformationCounts", counts);
    49. String stringBuffer;
    50. for (ShopInformation shopInformation : shopInformations) {
    51. stringBuffer = getSortName(shopInformation.getSort());
    52. ShopInformationBean shopInformationBean = new ShopInformationBean();
    53. shopInformationBean.setId(shopInformation.getId());
    54. shopInformationBean.setName(shopInformation.getName());
    55. shopInformationBean.setLevel(shopInformation.getLevel());
    56. shopInformationBean.setPrice(shopInformation.getPrice().doubleValue());
    57. shopInformationBean.setRemark(shopInformation.getRemark());
    58. shopInformationBean.setSort(stringBuffer);
    59. shopInformationBean.setQuantity(shopInformation.getQuantity());
    60. shopInformationBean.setUid(shopInformation.getUid());
    61. shopInformationBean.setTransaction(shopInformation.getTransaction());
    62. shopInformationBean.setImage(shopInformation.getImage());
    63. list.add(shopInformationBean);
    64. }
    65. model.addAttribute("shopInformationBean", list);
    66. } catch (Exception e) {
    67. e.printStackTrace();
    68. return "page/login_page";
    69. }
    70. return "index";
    71. }
    72. //进入商城
    73. @RequestMapping(value = "/mall_page.do")
    74. public String mallPage(HttpServletRequest request, Model model) {
    75. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    76. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    77. userInformation = new UserInformation();
    78. model.addAttribute("userInformation", userInformation);
    79. } else {
    80. model.addAttribute("userInformation", userInformation);
    81. }
    82. try {
    83. List shopInformations = selectTen(1, 12);
    84. List list = new ArrayList<>();
    85. int counts = getShopCounts();
    86. model.addAttribute("shopInformationCounts", counts);
    87. String sortName;
    88. for (ShopInformation shopInformation : shopInformations) {
    89. int sort = shopInformation.getSort();
    90. sortName = getSortName(sort);
    91. ShopInformationBean shopInformationBean = new ShopInformationBean();
    92. shopInformationBean.setId(shopInformation.getId());
    93. shopInformationBean.setName(shopInformation.getName());
    94. shopInformationBean.setLevel(shopInformation.getLevel());
    95. shopInformationBean.setRemark(shopInformation.getRemark());
    96. shopInformationBean.setPrice(shopInformation.getPrice().doubleValue());
    97. shopInformationBean.setSort(sortName);
    98. shopInformationBean.setQuantity(shopInformation.getQuantity());
    99. shopInformationBean.setTransaction(shopInformation.getTransaction());
    100. shopInformationBean.setUid(shopInformation.getUid());
    101. shopInformationBean.setImage(shopInformation.getImage());
    102. list.add(shopInformationBean);
    103. }
    104. model.addAttribute("shopInformationBean", list);
    105. } catch (Exception e) {
    106. e.printStackTrace();
    107. return "page/login_page";
    108. }
    109. return "page/mall_page";
    110. }
    111. //通过分类的第三层id获取全名
    112. private String getSortName(int sort) {
    113. StringBuilder stringBuffer = new StringBuilder();
    114. Specific specific = selectSpecificBySort(sort);
    115. int cid = specific.getCid();
    116. Classification classification = selectClassificationByCid(cid);
    117. int aid = classification.getAid();
    118. AllKinds allKinds = selectAllKindsByAid(aid);
    119. stringBuffer.append(allKinds.getName());
    120. stringBuffer.append("-");
    121. stringBuffer.append(classification.getName());
    122. stringBuffer.append("-");
    123. stringBuffer.append(specific.getName());
    124. // System.out.println(sort);
    125. return stringBuffer.toString();
    126. }
    127. //获得分类中的第一层
    128. @RequestMapping(value = "/getAllKinds.do")
    129. @ResponseBody
    130. public List getAllKind() {
    131. return getAllKinds();
    132. }
    133. //获得分类中的第二层,通过第一层的id
    134. @RequestMapping(value = "/getClassification.do", method = RequestMethod.POST)
    135. @ResponseBody
    136. public List getClassificationByAid(@RequestParam int id) {
    137. return selectAllClassification(id);
    138. }
    139. //通过第二层的id获取对应的第三层
    140. @RequestMapping(value = "/getSpecific.do")
    141. @ResponseBody
    142. public List getSpecificByCid(@RequestParam int id) {
    143. return selectAllSpecific(id);
    144. }
    145. //get the shops counts
    146. @RequestMapping(value = "/getShopsCounts.do")
    147. @ResponseBody
    148. public Map getShopsCounts() {
    149. Map map = new HashMap<>();
    150. int counts = 0;
    151. try {
    152. counts = shopInformationService.getCounts();
    153. } catch (Exception e) {
    154. e.printStackTrace();
    155. map.put("counts", counts);
    156. return map;
    157. }
    158. map.put("counts", counts);
    159. return map;
    160. }
    161. @RequestMapping(value = "/getShops.do")
    162. @ResponseBody
    163. public List getShops(@RequestParam int start) {
    164. List list = new ArrayList<>();
    165. try {
    166. int end = 12;
    167. list = selectTen(start, end);
    168. } catch (Exception e) {
    169. e.printStackTrace();
    170. return list;
    171. }
    172. return list;
    173. }
    174. //获取商品,分页,一次性获取end个
    175. private List selectTen(int start, int end) {
    176. Map map = new HashMap();
    177. map.put("start", (start - 1) * end);
    178. map.put("end", end);
    179. List list = shopInformationService.selectTen(map);
    180. return list;
    181. }
    182. //获取最详细的分类,第三层
    183. private Specific selectSpecificBySort(int sort) {
    184. return specificeService.selectByPrimaryKey(sort);
    185. }
    186. //获得第二层分类
    187. private Classification selectClassificationByCid(int cid) {
    188. return classificationService.selectByPrimaryKey(cid);
    189. }
    190. //获得第一层分类
    191. private AllKinds selectAllKindsByAid(int aid) {
    192. return allKindsService.selectByPrimaryKey(aid);
    193. }
    194. //获得第一层所有
    195. private List getAllKinds() {
    196. return allKindsService.selectAll();
    197. }
    198. //根据第一层的id获取该层下的第二层
    199. private List selectAllClassification(int aid) {
    200. return classificationService.selectByAid(aid);
    201. }
    202. //根据第二层的id获取其对应的第三层所有id
    203. private List selectAllSpecific(int cid) {
    204. return specificeService.selectByCid(cid);
    205. }
    206. //获得商品总页数
    207. private int getShopCounts() {
    208. return shopInformationService.getCounts();
    209. }
    210. //获得商品留言总页数
    211. private int getShopContextCounts(int sid) {
    212. return shopContextService.getCounts(sid);
    213. }
    214. //获得商品留言,10条
    215. private List selectShopContextBySid(int sid, int start) {
    216. return shopContextService.findById(sid, (start - 1) * 10);
    217. }
    218. }

    UserController

    1. package com.wsk.controller;
    2. import com.wsk.bean.GoodsCarBean;
    3. import com.wsk.bean.ShopInformationBean;
    4. import com.wsk.bean.UserWantBean;
    5. import com.wsk.pojo.*;
    6. import com.wsk.response.BaseResponse;
    7. import com.wsk.service.*;
    8. import com.wsk.token.TokenProccessor;
    9. import com.wsk.tool.SaveSession;
    10. import com.wsk.tool.StringUtils;
    11. import lombok.extern.slf4j.Slf4j;
    12. import org.slf4j.Logger;
    13. import org.slf4j.LoggerFactory;
    14. import org.springframework.stereotype.Controller;
    15. import org.springframework.ui.Model;
    16. import org.springframework.web.bind.annotation.RequestMapping;
    17. import org.springframework.web.bind.annotation.RequestMethod;
    18. import org.springframework.web.bind.annotation.RequestParam;
    19. import org.springframework.web.bind.annotation.ResponseBody;
    20. import org.springframework.web.multipart.MultipartFile;
    21. import javax.annotation.Resource;
    22. import javax.servlet.http.HttpServletRequest;
    23. import java.io.File;
    24. import java.math.BigDecimal;
    25. import java.util.*;
    26. /*import com.wsk.tool.OCR;
    27. import com.wsk.tool.Pornographic;*/
    28. /**
    29. * Created by wsk1103 on 2017/5/9.
    30. */
    31. @Controller
    32. @Slf4j
    33. public class UserController {
    34. @Resource
    35. private UserInformationService userInformationService;
    36. @Resource
    37. private UserPasswordService userPasswordService;
    38. @Resource
    39. private UserCollectionService userCollectionService;
    40. @Resource
    41. private UserReleaseService userReleaseService;
    42. @Resource
    43. private BoughtShopService boughtShopService;
    44. @Resource
    45. private UserWantService userWantService;
    46. @Resource
    47. private ShopCarService shopCarService;
    48. @Resource
    49. private OrderFormService orderFormService;
    50. @Resource
    51. private GoodsOfOrderFormService goodsOfOrderFormService;
    52. @Resource
    53. private UserStateService userStateService;
    54. @Resource
    55. private ShopInformationService shopInformationService;
    56. @Resource
    57. private GoodsCarService goodsCarService;
    58. @Resource
    59. private SpecificeService specificeService;
    60. @Resource
    61. private ClassificationService classificationService;
    62. @Resource
    63. private AllKindsService allKindsService;
    64. @Resource
    65. private ShopContextService shopContextService;
    66. //进入登录界面
    67. @RequestMapping(value = "/login.do", method = RequestMethod.GET)
    68. public String login(HttpServletRequest request, Model model) {
    69. String token = TokenProccessor.getInstance().makeToken();
    70. log.info("进入登录界面,token为:" + token);
    71. request.getSession().setAttribute("token", token);
    72. model.addAttribute("token", token);
    73. return "page/login_page";
    74. }
    75. //退出
    76. @RequestMapping(value = "/logout.do")
    77. public String logout(HttpServletRequest request) {
    78. try {
    79. request.getSession().removeAttribute("userInformation");
    80. request.getSession().removeAttribute("uid");
    81. System.out.println("logout");
    82. } catch (Exception e) {
    83. e.printStackTrace();
    84. return "redirect:/home.do";
    85. }
    86. return "redirect:/";
    87. }
    88. //用户注册,拥有插入数据而已,没什么用的
    89. @RequestMapping(value = "/registered.do", method = RequestMethod.POST)
    90. public String registered(Model model,
    91. @RequestParam String name, @RequestParam String phone, @RequestParam String password) {
    92. UserInformation userInformation = new UserInformation();
    93. userInformation.setUsername(name);
    94. userInformation.setPhone(phone);
    95. userInformation.setModified(new Date());
    96. userInformation.setCreatetime(new Date());
    97. if (userInformationService.insertSelective(userInformation) == 1) {
    98. int uid = userInformationService.selectIdByPhone(phone);
    99. UserPassword userPassword = new UserPassword();
    100. userPassword.setModified(new Date());
    101. password = StringUtils.getInstance().getMD5(password);
    102. userPassword.setPassword(password);
    103. userPassword.setUid(uid);
    104. int result = userPasswordService.insertSelective(userPassword);
    105. if (result != 1) {
    106. model.addAttribute("result", "fail");
    107. return "success";
    108. }
    109. model.addAttribute("result", "success");
    110. return "success";
    111. }
    112. model.addAttribute("result", "fail");
    113. return "success";
    114. }
    115. //用户注册
    116. // @RequestMapping(value = "/registered", method = RequestMethod.GET)
    117. // public String registered() {
    118. // return "registered";
    119. // }
    120. //验证登录
    121. @RequestMapping(value = "/login.do", method = RequestMethod.POST)
    122. public String login(HttpServletRequest request,
    123. @RequestParam String phone, @RequestParam String password, @RequestParam String token) {
    124. String loginToken = (String) request.getSession().getAttribute("token");
    125. if (StringUtils.getInstance().isNullOrEmpty(phone) || StringUtils.getInstance().isNullOrEmpty(password)) {
    126. return "redirect:/login.do";
    127. }
    128. //防止重复提交
    129. if (StringUtils.getInstance().isNullOrEmpty(token) || !token.equals(loginToken)) {
    130. return "redirect:/login.do";
    131. }
    132. boolean b = getId(phone, password, request);
    133. //失败,不存在该手机号码
    134. if (!b) {
    135. return "redirect:/login.do?msg=不存在该手机号码";
    136. }
    137. return "redirect:/";
    138. }
    139. //查看用户基本信息
    140. @RequestMapping(value = "/personal_info.do")
    141. public String personalInfo(HttpServletRequest request, Model model) {
    142. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    143. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    144. return "redirect:/login.do";
    145. }
    146. String personalInfoToken = TokenProccessor.getInstance().makeToken();
    147. request.getSession().setAttribute("personalInfoToken", personalInfoToken);
    148. model.addAttribute("token", personalInfoToken);
    149. model.addAttribute("userInformation", userInformation);
    150. return "page/personal/personal_info";
    151. }
    152. //完善用户基本信息,认证
    153. @RequestMapping(value = "/certification.do", method = RequestMethod.POST)
    154. @ResponseBody
    155. public Map certification(HttpServletRequest request,
    156. @RequestParam(required = false) String userName,
    157. @RequestParam(required = false) String realName,
    158. @RequestParam(required = false) String clazz, @RequestParam String token,
    159. @RequestParam(required = false) String sno, @RequestParam(required = false) String dormitory,
    160. @RequestParam(required = false) String gender) {
    161. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    162. Map map = new HashMap<>();
    163. map.put("result", 0);
    164. //该用户还没有登录
    165. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    166. return map;
    167. }
    168. String certificationToken = (String) request.getSession().getAttribute("personalInfoToken");
    169. //防止重复提交
    170. // boolean b = token.equals(certificationToken);
    171. if (StringUtils.getInstance().isNullOrEmpty(certificationToken)) {
    172. return map;
    173. } else {
    174. request.getSession().removeAttribute("certificationToken");
    175. }
    176. if (userName != null && userName.length() < 25) {
    177. userName = StringUtils.getInstance().replaceBlank(userName);
    178. userInformation.setUsername(userName);
    179. } else if (userName != null && userName.length() >= 25) {
    180. return map;
    181. }
    182. if (realName != null && realName.length() < 25) {
    183. realName = StringUtils.getInstance().replaceBlank(realName);
    184. userInformation.setRealname(realName);
    185. } else if (realName != null && realName.length() >= 25) {
    186. return map;
    187. }
    188. if (clazz != null && clazz.length() < 25) {
    189. clazz = StringUtils.getInstance().replaceBlank(clazz);
    190. userInformation.setClazz(clazz);
    191. } else if (clazz != null && clazz.length() >= 25) {
    192. return map;
    193. }
    194. if (sno != null && sno.length() < 25) {
    195. sno = StringUtils.getInstance().replaceBlank(sno);
    196. userInformation.setSno(sno);
    197. } else if (sno != null && sno.length() >= 25) {
    198. return map;
    199. }
    200. if (dormitory != null && dormitory.length() < 25) {
    201. dormitory = StringUtils.getInstance().replaceBlank(dormitory);
    202. userInformation.setDormitory(dormitory);
    203. } else if (dormitory != null && dormitory.length() >= 25) {
    204. return map;
    205. }
    206. if (gender != null && gender.length() <= 2) {
    207. gender = StringUtils.getInstance().replaceBlank(gender);
    208. userInformation.setGender(gender);
    209. } else if (gender != null && gender.length() > 2) {
    210. return map;
    211. }
    212. int result = userInformationService.updateByPrimaryKeySelective(userInformation);
    213. if (result != 1) {
    214. //更新失败,认证失败
    215. return map;
    216. }
    217. //认证成功
    218. request.getSession().setAttribute("userInformation", userInformation);
    219. map.put("result", 1);
    220. return map;
    221. }
    222. //enter the publishUserWant.do.html,进入求购页面
    223. @RequestMapping(value = "/require_product.do")
    224. public String enterPublishUserWant(HttpServletRequest request, Model model) {
    225. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    226. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    227. return "redirect:/login.do";
    228. }
    229. String error = request.getParameter("error");
    230. if (!StringUtils.getInstance().isNullOrEmpty(error)) {
    231. model.addAttribute("error", "error");
    232. }
    233. String publishUserWantToken = TokenProccessor.getInstance().makeToken();
    234. request.getSession().setAttribute("publishUserWantToken", publishUserWantToken);
    235. model.addAttribute("token", publishUserWantToken);
    236. model.addAttribute("userInformation", userInformation);
    237. return "page/require_product";
    238. }
    239. //修改求购商品
    240. @RequestMapping(value = "/modified_require_product.do")
    241. public String modifiedRequireProduct(HttpServletRequest request, Model model,
    242. @RequestParam int id) {
    243. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    244. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    245. return "redirect:/login.do";
    246. }
    247. String publishUserWantToken = TokenProccessor.getInstance().makeToken();
    248. request.getSession().setAttribute("publishUserWantToken", publishUserWantToken);
    249. model.addAttribute("token", publishUserWantToken);
    250. model.addAttribute("userInformation", userInformation);
    251. UserWant userWant = userWantService.selectByPrimaryKey(id);
    252. model.addAttribute("userWant", userWant);
    253. String sort = getSort(userWant.getSort());
    254. model.addAttribute("sort", sort);
    255. return "page/modified_require_product";
    256. }
    257. //publish userWant,发布求购
    258. @RequestMapping(value = "/publishUserWant.do")
    259. // @ResponseBody
    260. public String publishUserWant(HttpServletRequest request, Model model,
    261. @RequestParam String name,
    262. @RequestParam int sort, @RequestParam int quantity,
    263. @RequestParam double price, @RequestParam String remark,
    264. @RequestParam String token) {
    265. // Map map = new HashMap<>();
    266. //determine whether the user exits
    267. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    268. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    269. //if the user no exits in the session,
    270. // map.put("result", 2);
    271. return "redirect:/login.do";
    272. }
    273. String publishUserWantToke = (String) request.getSession().getAttribute("publishUserWantToken");
    274. if (StringUtils.getInstance().isNullOrEmpty(publishUserWantToke) || !publishUserWantToke.equals(token)) {
    275. // map.put("result", 2);
    276. return "redirect:require_product.do?error=3";
    277. } else {
    278. request.getSession().removeAttribute("publishUserWantToken");
    279. }
    280. // name = StringUtils.replaceBlank(name);
    281. // remark = StringUtils.replaceBlank(remark);
    282. // name = StringUtils.getInstance().txtReplace(name);
    283. // remark = StringUtils.getInstance().txtReplace(remark);
    284. try {
    285. if (name.length() < 1 || remark.length() < 1 || name.length() > 25 || remark.length() > 25) {
    286. return "redirect:require_product.do";
    287. }
    288. } catch (Exception e) {
    289. e.printStackTrace();
    290. return "redirect:require_product.do?error=1";
    291. }
    292. UserWant userWant = new UserWant();
    293. userWant.setModified(new Date());
    294. userWant.setName(name);
    295. userWant.setPrice(new BigDecimal(price));
    296. userWant.setQuantity(quantity);
    297. userWant.setRemark(remark);
    298. userWant.setUid((Integer) request.getSession().getAttribute("uid"));
    299. userWant.setSort(sort);
    300. int result;
    301. try {
    302. result = userWantService.insertSelective(userWant);
    303. if (result != 1) {
    304. // map.put("result", result);
    305. return "redirect:/require_product.do?error=2";
    306. }
    307. } catch (Exception e) {
    308. e.printStackTrace();
    309. // map.put("result", result);
    310. return "redirect:/require_product.do?error=2";
    311. }
    312. // map.put("result", result);
    313. return "redirect:/my_require_product.do";
    314. }
    315. //getUserWant,查看我的求购
    316. @RequestMapping(value = {"/my_require_product.do", "/my_require_product_page.do"})
    317. public String getUserWant(HttpServletRequest request, Model model) {
    318. List list;
    319. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    320. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    321. return "redirect:/login.do";
    322. }
    323. try {
    324. int uid = (int) request.getSession().getAttribute("uid");
    325. // list = selectUserWantByUid(4);
    326. list = selectUserWantByUid(uid);
    327. List userWantBeans = new ArrayList<>();
    328. for (UserWant userWant : list) {
    329. UserWantBean userWantBean = new UserWantBean();
    330. userWantBean.setId(userWant.getId());
    331. userWantBean.setModified(userWant.getModified());
    332. userWantBean.setName(userWant.getName());
    333. userWantBean.setPrice(userWant.getPrice().doubleValue());
    334. userWantBean.setUid(uid);
    335. userWantBean.setQuantity(userWant.getQuantity());
    336. userWantBean.setRemark(userWant.getRemark());
    337. userWantBean.setSort(getSort(userWant.getSort()));
    338. userWantBeans.add(userWantBean);
    339. }
    340. model.addAttribute("userWant", userWantBeans);
    341. } catch (Exception e) {
    342. e.printStackTrace();
    343. return "redirect:/";
    344. }
    345. model.addAttribute("userInformation", userInformation);
    346. return "page/personal/my_require_product_page";
    347. }
    348. //getUserWantCounts.do,查看求购总数
    349. @RequestMapping(value = "/getUserWantCounts.do")
    350. @ResponseBody
    351. public Map getUserWantCounts(HttpServletRequest request, Model model) {
    352. Map map = new HashMap<>();
    353. if (StringUtils.getInstance().isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
    354. map.put("counts", -1);
    355. return map;
    356. }
    357. try {
    358. int counts = getUserWantCounts((Integer) request.getSession().getAttribute("uid"));
    359. map.put("counts", counts);
    360. } catch (Exception e) {
    361. e.printStackTrace();
    362. map.put("counts", -1);
    363. }
    364. return map;
    365. }
    366. //删除求购
    367. @RequestMapping(value = "/deleteUserWant.do")
    368. public String deleteUserWant(HttpServletRequest request, @RequestParam int id) {
    369. // Map map = new HashMap<>();
    370. if (StringUtils.getInstance().isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
    371. return "redirect:/login.do";
    372. }
    373. UserWant userWant = new UserWant();
    374. userWant.setId(id);
    375. userWant.setDisplay(0);
    376. try {
    377. int result = userWantService.updateByPrimaryKeySelective(userWant);
    378. if (result != 1) {
    379. return "redirect:my_require_product.do";
    380. }
    381. } catch (Exception e) {
    382. e.printStackTrace();
    383. }
    384. return "redirect:my_require_product.do";
    385. }
    386. //收藏
    387. //add the userCollection
    388. @RequestMapping(value = "/addUserCollection.do")
    389. @ResponseBody
    390. public BaseResponse addUserCollection(HttpServletRequest request, @RequestParam int sid) {
    391. //determine whether the user exits
    392. if (StringUtils.getInstance().isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
    393. //if the user no exits in the session,
    394. return BaseResponse.fail();
    395. }
    396. UserCollection userCollection = new UserCollection();
    397. userCollection.setModified(new Date());
    398. userCollection.setSid(sid);
    399. userCollection.setUid((Integer) request.getSession().getAttribute("uid"));
    400. //begin insert the userCollection
    401. int result = userCollectionService.insertSelective(userCollection);
    402. if (result != 1) {
    403. return BaseResponse.fail();
    404. }
    405. return BaseResponse.success();
    406. }
    407. // delete the userCollection
    408. @RequestMapping(value = "/deleteUserCollection.do")
    409. @ResponseBody
    410. public BaseResponse deleteUserCollection(HttpServletRequest request, @RequestParam int ucid) {
    411. if (StringUtils.getInstance().isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
    412. return BaseResponse.fail();
    413. }
    414. UserCollection userCollection = new UserCollection();
    415. // userCollection.setUid((Integer) request.getSession().getAttribute("uid"));
    416. // userCollection.setSid(sid);
    417. userCollection.setId(ucid);
    418. userCollection.setModified(new Date());
    419. userCollection.setDisplay(0);
    420. int result;
    421. result = userCollectionService.updateByPrimaryKeySelective(userCollection);
    422. if (result != 1) {
    423. return BaseResponse.fail();
    424. }
    425. return BaseResponse.success();
    426. }
    427. //购物车开始。。。。。。。。。。。
    428. //getShopCarCounts.do
    429. @RequestMapping(value = "/getShopCarCounts.do")
    430. @ResponseBody
    431. public BaseResponse getShopCarCounts(HttpServletRequest request) {
    432. if (StringUtils.getInstance().isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
    433. return BaseResponse.fail();
    434. }
    435. int uid = (int) request.getSession().getAttribute("uid");
    436. int counts = getShopCarCounts(uid);
    437. return BaseResponse.success();
    438. }
    439. //check the shopping cart,查看购物车
    440. @RequestMapping(value = "/shopping_cart.do")
    441. public String selectShopCar(HttpServletRequest request, Model model) {
    442. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    443. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    444. userInformation = new UserInformation();
    445. model.addAttribute("userInformation", userInformation);
    446. // list.add(shopCar);
    447. return "redirect:/login.do";
    448. } else {
    449. model.addAttribute("userInformation", userInformation);
    450. }
    451. int uid = userInformation.getId();
    452. List goodsCars = goodsCarService.selectByUid(uid);
    453. List goodsCarBeans = new ArrayList<>();
    454. for (GoodsCar goodsCar : goodsCars) {
    455. GoodsCarBean goodsCarBean = new GoodsCarBean();
    456. goodsCarBean.setUid(goodsCar.getUid());
    457. goodsCarBean.setSid(goodsCar.getSid());
    458. goodsCarBean.setModified(goodsCar.getModified());
    459. goodsCarBean.setId(goodsCar.getId());
    460. goodsCarBean.setQuantity(goodsCar.getQuantity());
    461. ShopInformation shopInformation = shopInformationService.selectByPrimaryKey(goodsCar.getSid());
    462. goodsCarBean.setName(shopInformation.getName());
    463. goodsCarBean.setRemark(shopInformation.getRemark());
    464. goodsCarBean.setImage(shopInformation.getImage());
    465. goodsCarBean.setPrice(shopInformation.getPrice().doubleValue());
    466. goodsCarBean.setSort(getSort(shopInformation.getSort()));
    467. goodsCarBeans.add(goodsCarBean);
    468. }
    469. model.addAttribute("list", goodsCarBeans);
    470. return "page/shopping_cart";
    471. }
    472. // //通过购物车的id获取购物车里面的商品
    473. // @RequestMapping(value = "/selectGoodsOfShopCar")
    474. // @ResponseBody
    475. // public List selectGoodsCar(HttpServletRequest request) {
    476. // List list = new ArrayList<>();
    477. // GoodsCar goodsCar = new GoodsCar();
    478. // if (Empty.isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
    479. // list.add(goodsCar);
    480. // return list;
    481. // }
    482. // try {
    483. // int scid = shopCarService.selectByUid((Integer) request.getSession().getAttribute("uid")).getId();
    484. // list = goodsCarService.selectByUid(scid);
    485. // return list;
    486. // } catch (Exception e) {
    487. // e.printStackTrace();
    488. // return list;
    489. // }
    490. // }
    491. //添加到购物车
    492. @RequestMapping(value = "/insertGoodsCar.do")
    493. @ResponseBody
    494. public BaseResponse insertGoodsCar(HttpServletRequest request, @RequestParam int id) {
    495. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    496. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    497. return BaseResponse.fail();
    498. }
    499. int uid = userInformation.getId();
    500. GoodsCar goodsCar = new GoodsCar();
    501. goodsCar.setDisplay(1);
    502. goodsCar.setModified(new Date());
    503. goodsCar.setQuantity(1);
    504. goodsCar.setUid(uid);
    505. goodsCar.setSid(id);
    506. int result = goodsCarService.insertSelective(goodsCar);
    507. return BaseResponse.success();
    508. }
    509. //删除购物车的商品
    510. @RequestMapping(value = "/deleteShopCar.do")
    511. @ResponseBody
    512. public BaseResponse deleteShopCar(HttpServletRequest request, @RequestParam int id, @RequestParam int sid) {
    513. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    514. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    515. return BaseResponse.fail();
    516. }
    517. int uid = userInformation.getId();
    518. GoodsCar goodsCar = new GoodsCar();
    519. goodsCar.setDisplay(0);
    520. goodsCar.setId(id);
    521. goodsCar.setSid(sid);
    522. goodsCar.setUid(uid);
    523. int result = goodsCarService.updateByPrimaryKeySelective(goodsCar);
    524. if (result != 1) {
    525. return BaseResponse.fail();
    526. }
    527. return BaseResponse.success();
    528. }
    529. //发布商品
    530. @RequestMapping(value = "/insertGoods.do", method = RequestMethod.POST)
    531. public String insertGoods(@RequestParam String name, @RequestParam int level,
    532. @RequestParam String remark, @RequestParam double price,
    533. @RequestParam int sort, @RequestParam int quantity,
    534. @RequestParam String token, @RequestParam(required = false) MultipartFile image,
    535. @RequestParam int action, @RequestParam(required = false) int id,
    536. HttpServletRequest request, Model model) {
    537. String goodsToken = (String) request.getSession().getAttribute("goodsToken");
    538. // String publishProductToken = TokenProccessor.getInstance().makeToken();
    539. // request.getSession().setAttribute("token",publishProductToken);
    540. //防止重复提交
    541. if (StringUtils.getInstance().isNullOrEmpty(goodsToken) || !goodsToken.equals(token)) {
    542. return "redirect:publish_product.do?error=1";
    543. } else {
    544. request.getSession().removeAttribute("goodsToken");
    545. }
    546. // //从session中获得用户的基本信息
    547. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    548. model.addAttribute("userInformation", userInformation);
    549. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    550. //如果用户不存在,
    551. return "redirect:/login.do";
    552. }
    553. name = StringUtils.getInstance().replaceBlank(name);
    554. remark = StringUtils.getInstance().replaceBlank(remark);
    555. //judge the data`s format
    556. if (StringUtils.getInstance().isNullOrEmpty(name) || StringUtils.getInstance().isNullOrEmpty(level) || StringUtils.getInstance().isNullOrEmpty(remark) || StringUtils.getInstance().isNullOrEmpty(price)
    557. || StringUtils.getInstance().isNullOrEmpty(sort) || StringUtils.getInstance().isNullOrEmpty(quantity) || name.length() > 25 || remark.length() > 122) {
    558. model.addAttribute("message", "请输入正确的格式!!!!!");
    559. model.addAttribute("token", goodsToken);
    560. request.getSession().setAttribute("goodsToken", goodsToken);
    561. return "page/publish_product";
    562. }
    563. //插入
    564. if (action == 1) {
    565. if (StringUtils.getInstance().isNullOrEmpty(image)) {
    566. model.addAttribute("message", "请选择图片!!!");
    567. model.addAttribute("token", goodsToken);
    568. request.getSession().setAttribute("goodsToken", goodsToken);
    569. return "redirect:publish_product.do?error=请插入图片";
    570. }
    571. String random;
    572. String path = "D:\\", save = "";
    573. random = "image\\" + StringUtils.getInstance().getRandomChar() + System.currentTimeMillis() + ".jpg";
    574. StringBuilder thumbnails = new StringBuilder();
    575. thumbnails.append(path);
    576. thumbnails.append("image/thumbnails/");
    577. StringBuilder wsk = new StringBuilder();
    578. wsk.append(StringUtils.getInstance().getRandomChar()).append(System.currentTimeMillis()).append(".jpg");
    579. thumbnails.append(wsk);
    580. // String fileName = "\\" + random + ".jpg";
    581. File file = new File(path, random);
    582. if (!file.exists()) {
    583. file.mkdir();
    584. }
    585. try {
    586. image.transferTo(file);
    587. } catch (Exception e) {
    588. e.printStackTrace();
    589. }
    590. /* String pornograp = Pornographic.CheckPornograp("D:\\" + random);
    591. if (pornograp.equals("色情图片")) {
    592. return "redirect:publish_product?error=不能使用色情图片";
    593. }
    594. if (!OCR.isOk2(pornograp)) {
    595. return "redirect:publish_product?error=图片不能含有敏感文字";
    596. }*/
    597. //创建缩略图文件夹
    598. File thumbnailsFile = new File(thumbnails.toString());
    599. if (!thumbnailsFile.exists()) {
    600. thumbnailsFile.mkdir();
    601. }
    602. if (StringUtils.getInstance().thumbnails(path + random, thumbnails.toString())) {
    603. save = "/images/thumbnails/" + wsk.toString();
    604. } else {
    605. return "redirect:publish_product.do?error=生成缩略图失败";
    606. }
    607. //begin insert the shopInformation to the MySQL
    608. ShopInformation shopInformation = new ShopInformation();
    609. shopInformation.setName(name);
    610. shopInformation.setLevel(level);
    611. shopInformation.setRemark(remark);
    612. shopInformation.setPrice(new BigDecimal(price));
    613. shopInformation.setSort(sort);
    614. shopInformation.setQuantity(quantity);
    615. shopInformation.setModified(new Date());
    616. shopInformation.setImage(random);//This is the other uniquely identifies
    617. shopInformation.setThumbnails(save);
    618. // shopInformation.setUid(4);
    619. int uid = (int) request.getSession().getAttribute("uid");
    620. shopInformation.setUid(uid);
    621. try {
    622. int result = shopInformationService.insertSelective(shopInformation);
    623. //插入失败???
    624. if (result != 1) {
    625. model.addAttribute("message", "请输入正确的格式!!!!!");
    626. model.addAttribute("token", goodsToken);
    627. request.getSession().setAttribute("goodsToken", goodsToken);
    628. return "page/publish_product";
    629. }
    630. } catch (Exception e) {
    631. e.printStackTrace();
    632. model.addAttribute("token", goodsToken);
    633. model.addAttribute("message", "请输入正确的格式!!!!!");
    634. request.getSession().setAttribute("goodsToken", goodsToken);
    635. return "page/publish_product";
    636. }
    637. int sid = shopInformationService.selectIdByImage(random);// get the id which is belongs shopInformation
    638. //将发布的商品的编号插入到用户的发布中
    639. UserRelease userRelease = new UserRelease();
    640. userRelease.setModified(new Date());
    641. userRelease.setSid(sid);
    642. userRelease.setUid(uid);
    643. try {
    644. int result = userReleaseService.insertSelective(userRelease);
    645. //如果关联失败,删除对应的商品和商品图片
    646. if (result != 1) {
    647. //if insert failure,transaction rollback.
    648. shopInformationService.deleteByPrimaryKey(sid);
    649. // shopPictureService.deleteByPrimaryKey(spid);
    650. model.addAttribute("token", goodsToken);
    651. model.addAttribute("message", "请输入正确的格式!!!!!");
    652. request.getSession().setAttribute("goodsToken", goodsToken);
    653. return "page/publish_product";
    654. }
    655. } catch (Exception e) {
    656. //if insert failure,transaction rollback.
    657. shopInformationService.deleteByPrimaryKey(sid);
    658. e.printStackTrace();
    659. model.addAttribute("token", goodsToken);
    660. model.addAttribute("message", "请输入正确的格式!!!!!");
    661. request.getSession().setAttribute("goodsToken", goodsToken);
    662. return "page/publish_product";
    663. }
    664. shopInformation.setId(sid);
    665. goodsToken = TokenProccessor.getInstance().makeToken();
    666. request.getSession().setAttribute("goodsToken", goodsToken);
    667. model.addAttribute("token", goodsToken);
    668. model.addAttribute("shopInformation", shopInformation);
    669. model.addAttribute("userInformation", userInformation);
    670. String sb = getSort(sort);
    671. model.addAttribute("sort", sb);
    672. model.addAttribute("action", 2);
    673. return "redirect:/my_publish_product_page.do";
    674. } else if (action == 2) {//更新商品
    675. ShopInformation shopInformation = new ShopInformation();
    676. shopInformation.setModified(new Date());
    677. shopInformation.setQuantity(quantity);
    678. shopInformation.setSort(sort);
    679. shopInformation.setPrice(new BigDecimal(price));
    680. shopInformation.setRemark(remark);
    681. shopInformation.setLevel(level);
    682. shopInformation.setName(name);
    683. shopInformation.setId(id);
    684. try {
    685. int result = shopInformationService.updateByPrimaryKeySelective(shopInformation);
    686. if (result != 1) {
    687. return "redirect:publish_product.do";
    688. }
    689. } catch (Exception e) {
    690. e.printStackTrace();
    691. return "redirect:publish_product.do";
    692. }
    693. goodsToken = TokenProccessor.getInstance().makeToken();
    694. request.getSession().setAttribute("goodsToken", goodsToken);
    695. model.addAttribute("token", goodsToken);
    696. shopInformation = shopInformationService.selectByPrimaryKey(id);
    697. model.addAttribute("userInformation", userInformation);
    698. model.addAttribute("shopInformation", shopInformation);
    699. model.addAttribute("action", 2);
    700. model.addAttribute("sort", getSort(sort));
    701. }
    702. return "redirect:/my_publish_product_page.do";
    703. }
    704. //从发布的商品直接跳转到修改商品
    705. @RequestMapping(value = "/modifiedMyPublishProduct.do")
    706. public String modifiedMyPublishProduct(HttpServletRequest request, Model model,
    707. @RequestParam int id) {
    708. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    709. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    710. return "redirect:/login.do";
    711. }
    712. String goodsToken = TokenProccessor.getInstance().makeToken();
    713. request.getSession().setAttribute("goodsToken", goodsToken);
    714. model.addAttribute("token", goodsToken);
    715. ShopInformation shopInformation = shopInformationService.selectByPrimaryKey(id);
    716. model.addAttribute("userInformation", userInformation);
    717. model.addAttribute("shopInformation", shopInformation);
    718. model.addAttribute("action", 2);
    719. model.addAttribute("sort", getSort(shopInformation.getSort()));
    720. return "page/publish_product";
    721. }
    722. //发表留言
    723. @RequestMapping(value = "/insertShopContext.do")
    724. @ResponseBody
    725. public Map insertShopContext(@RequestParam int id, @RequestParam String context, @RequestParam String token,
    726. HttpServletRequest request) {
    727. String goodsToken = (String) request.getSession().getAttribute("goodsToken");
    728. Map map = new HashMap<>();
    729. map.put("result", "1");
    730. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    731. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    732. map.put("result", "2");
    733. return map;
    734. }
    735. if (StringUtils.getInstance().isNullOrEmpty(goodsToken) || !token.equals(goodsToken)) {
    736. return map;
    737. }
    738. ShopContext shopContext = new ShopContext();
    739. shopContext.setContext(context);
    740. Date date = new Date();
    741. shopContext.setModified(date);
    742. shopContext.setSid(id);
    743. int uid = (int) request.getSession().getAttribute("uid");
    744. shopContext.setUid(uid);
    745. try {
    746. int result = shopContextService.insertSelective(shopContext);
    747. if (result != 1) {
    748. return map;
    749. }
    750. } catch (Exception e) {
    751. e.printStackTrace();
    752. return map;
    753. }
    754. map.put("result", "1");
    755. map.put("username", userInformation.getUsername());
    756. map.put("context", context);
    757. map.put("time", StringUtils.getInstance().DateToString(date));
    758. return map;
    759. }
    760. //下架商品
    761. @RequestMapping(value = "/deleteShop.do")
    762. public String deleteShop(HttpServletRequest request, Model model, @RequestParam int id) {
    763. // Map map = new HashMap<>();
    764. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    765. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    766. return "redirect:/login.do";
    767. } else {
    768. model.addAttribute("userInformation", userInformation);
    769. }
    770. ShopInformation shopInformation = new ShopInformation();
    771. shopInformation.setModified(new Date());
    772. shopInformation.setDisplay(0);
    773. shopInformation.setId(id);
    774. try {
    775. int result = shopInformationService.updateByPrimaryKeySelective(shopInformation);
    776. if (result != 1) {
    777. return "redirect:my_publish_product_page.do";
    778. }
    779. return "redirect:my_publish_product_page.do";
    780. } catch (Exception e) {
    781. e.printStackTrace();
    782. return "redirect:my_publish_product_page.do";
    783. }
    784. }
    785. //查看发布的所有商品总数
    786. @RequestMapping(value = "/getReleaseShopCounts.do")
    787. @ResponseBody
    788. public Map getReleaseShopCounts(HttpServletRequest request) {
    789. Map map = new HashMap<>();
    790. if (StringUtils.getInstance().isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
    791. map.put("counts", -1);
    792. return map;
    793. }
    794. int counts = getReleaseCounts((Integer) request.getSession().getAttribute("uid"));
    795. map.put("counts", counts);
    796. return map;
    797. }
    798. //查看我的发布的商品
    799. @RequestMapping(value = "/my_publish_product_page.do")
    800. public String getReleaseShop(HttpServletRequest request, Model model) {
    801. UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
    802. if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
    803. return "redirect:/login.do";
    804. } else {
    805. model.addAttribute("userInformation", userInformation);
    806. }
    807. int uid = (int) request.getSession().getAttribute("uid");
    808. List shopInformations = shopInformationService.selectUserReleaseByUid(uid);
    809. List list = new ArrayList<>();
    810. String stringBuffer;
    811. // int i=0;
    812. for (ShopInformation shopInformation : shopInformations) {
    813. // if (i>=5){
    814. // break;
    815. // }
    816. // i++;
    817. stringBuffer = getSort(shopInformation.getSort());
    818. ShopInformationBean shopInformationBean = new ShopInformationBean();
    819. shopInformationBean.setId(shopInformation.getId());
    820. shopInformationBean.setName(shopInformation.getName());
    821. shopInformationBean.setLevel(shopInformation.getLevel());
    822. shopInformationBean.setPrice(shopInformation.getPrice().doubleValue());
    823. shopInformationBean.setRemark(shopInformation.getRemark());
    824. shopInformationBean.setSort(stringBuffer);
    825. shopInformationBean.setQuantity(shopInformation.getQuantity());
    826. shopInformationBean.setTransaction(shopInformation.getTransaction());
    827. shopInformationBean.setUid(shopInformation.getUid());
    828. shopInformationBean.setImage(shopInformation.getImage());
    829. list.add(shopInformationBean);
    830. }
    831. model.addAttribute("shopInformationBean", list);
    832. return "page/personal/my_publish_product_page";
    833. }
    834. //更新商品信息
    835. private String getSort(int sort) {
    836. StringBuilder sb = new StringBuilder();
    837. Specific specific = selectSpecificBySort(sort);
    838. int cid = specific.getCid();
    839. Classification classification = selectClassificationByCid(cid);
    840. int aid = classification.getAid();
    841. AllKinds allKinds = selectAllKindsByAid(aid);
    842. sb.append(allKinds.getName());
    843. sb.append("-");
    844. sb.append(classification.getName());
    845. sb.append("-");
    846. sb.append(specific.getName());
    847. return sb.toString();
    848. }
    849. //查看用户收藏的货物的总数
    850. private int getCollectionCounts(int uid) {
    851. int counts;
    852. try {
    853. counts = userCollectionService.getCounts(uid);
    854. } catch (Exception e) {
    855. e.printStackTrace();
    856. return -1;
    857. }
    858. return counts;
    859. }
    860. //查看收藏,一次10个
    861. private List selectContectionByUid(int uid, int start) {
    862. try {
    863. return userCollectionService.selectByUid(uid, (start - 1) * 10);
    864. } catch (Exception e) {
    865. e.printStackTrace();
    866. List list = new ArrayList<>();
    867. list.add(new UserCollection());
    868. return list;
    869. }
    870. }
    871. //查看用户发布的货物的总数
    872. private int getReleaseCounts(int uid) {
    873. try {
    874. return userReleaseService.getCounts(uid);
    875. } catch (Exception e) {
    876. e.printStackTrace();
    877. return -1;
    878. }
    879. }
    880. //查看发布的货物,一次10个
    881. private List selectReleaseByUid(int uid, int start) {
    882. try {
    883. return userReleaseService.selectByUid(uid, (start - 1) * 10);
    884. } catch (Exception e) {
    885. e.printStackTrace();
    886. List list = new ArrayList<>();
    887. list.add(new UserRelease());
    888. return list;
    889. }
    890. }
    891. //查看用户购买到的物品的总数
    892. private int getBoughtShopCounts(int uid) {
    893. try {
    894. return boughtShopService.getCounts(uid);
    895. } catch (Exception e) {
    896. e.printStackTrace();
    897. return -1;
    898. }
    899. }
    900. //查看用户的购买,10个
    901. private List selectBoughtShopByUid(int uid, int start) {
    902. try {
    903. return boughtShopService.selectByUid(uid, (start - 1) * 10);
    904. } catch (Exception e) {
    905. e.printStackTrace();
    906. List list = new ArrayList<>();
    907. list.add(new BoughtShop());
    908. return list;
    909. }
    910. }
    911. //查看用户的求购总个数
    912. private int getUserWantCounts(int uid) {
    913. try {
    914. return userWantService.getCounts(uid);
    915. } catch (Exception e) {
    916. return -1;
    917. }
    918. }
    919. //求购列表10
    920. private List selectUserWantByUid(int uid) {
    921. try {
    922. return userWantService.selectMineByUid(uid);
    923. } catch (Exception e) {
    924. e.printStackTrace();
    925. List list = new ArrayList<>();
    926. list.add(new UserWant());
    927. return list;
    928. }
    929. }
    930. //我的购物车总数
    931. private int getShopCarCounts(int uid) {
    932. try {
    933. return shopCarService.getCounts(uid);
    934. } catch (Exception e) {
    935. e.printStackTrace();
    936. return -1;
    937. }
    938. }
    939. //购物车列表 10
    940. private ShopCar selectShopCarByUid(int uid) {
    941. try {
    942. return shopCarService.selectByUid(uid);
    943. } catch (Exception e) {
    944. e.printStackTrace();
    945. // List list
    946. return new ShopCar();
    947. }
    948. }
    949. //查看订单总数
    950. private int getOrderFormCounts(int uid) {
    951. try {
    952. return orderFormService.getCounts(uid);
    953. } catch (Exception e) {
    954. e.printStackTrace();
    955. return -1;
    956. }
    957. }
    958. //订单列表 10个
    959. private List selectOrderFormByUid(int uid, int start) {
    960. try {
    961. return orderFormService.selectByUid(uid, (start - 1) * 10);
    962. } catch (Exception e) {
    963. e.printStackTrace();
    964. List list = new ArrayList<>();
    965. list.add(new OrderForm());
    966. return list;
    967. }
    968. }
    969. //订单中的商品
    970. private List selectGoodsOfOrderFormByOFid(int ofid) {
    971. try {
    972. return goodsOfOrderFormService.selectByOFid(ofid);
    973. } catch (Exception e) {
    974. e.printStackTrace();
    975. List list = new ArrayList<>();
    976. list.add(new GoodsOfOrderForm());
    977. return list;
    978. }
    979. }
    980. //查看用户的状态
    981. private UserState selectUserStateByUid(int uid) {
    982. try {
    983. return userStateService.selectByUid(uid);
    984. } catch (Exception e) {
    985. e.printStackTrace();
    986. return new UserState();
    987. }
    988. }
    989. //判断该手机号码及其密码是否一一对应
    990. private boolean getId(String phone, String password, HttpServletRequest request) {
    991. int uid = userInformationService.selectIdByPhone(phone);
    992. if (uid == 0 || StringUtils.getInstance().isNullOrEmpty(uid)) {
    993. return false;
    994. }
    995. UserInformation userInformation = userInformationService.selectByPrimaryKey(uid);
    996. if (null == userInformation) {
    997. return false;
    998. }
    999. password = StringUtils.getInstance().getMD5(password);
    1000. String password2 = userPasswordService.selectByUid(userInformation.getId()).getPassword();
    1001. if (!password.equals(password2)) {
    1002. return false;
    1003. }
    1004. //如果密码账号对应正确,将userInformation存储到session中
    1005. request.getSession().setAttribute("userInformation", userInformation);
    1006. request.getSession().setAttribute("uid", uid);
    1007. SaveSession.getInstance().save(phone, System.currentTimeMillis());
    1008. return true;
    1009. }
    1010. //获取最详细的分类,第三层
    1011. private Specific selectSpecificBySort(int sort) {
    1012. return specificeService.selectByPrimaryKey(sort);
    1013. }
    1014. //获得第二层分类
    1015. private Classification selectClassificationByCid(int cid) {
    1016. return classificationService.selectByPrimaryKey(cid);
    1017. }
    1018. //获得第一层分类
    1019. private AllKinds selectAllKindsByAid(int aid) {
    1020. return allKindsService.selectByPrimaryKey(aid);
    1021. }
    1022. public void save(ShopInformation shopInformation, UserRelease userRelease) {
    1023. shopInformationService.insertSelective(shopInformation);
    1024. userReleaseService.insertSelective(userRelease);
    1025. }
    1026. //循环插入商品
    1027. //发布商品
    1028. @RequestMapping(value = "/test")
    1029. public String insertGoods() {
    1030. //begin insert the shopInformation to the MySQL
    1031. // ShopInformation shopInformation = new ShopInformation();
    1032. // shopInformation.setName(name);
    1033. // shopInformation.setLevel(level);
    1034. // shopInformation.setRemark(remark);
    1035. // shopInformation.setPrice(new BigDecimal(price));
    1036. // shopInformation.setSort(sort);
    1037. // shopInformation.setQuantity(quantity);
    1038. // shopInformation.setModified(new Date());
    1039. // shopInformation.setImage(image);//This is the other uniquely identifies
    1040. // shopInformation.setUid(uid);
    1041. // //将发布的商品的编号插入到用户的发布中
    1042. // UserRelease userRelease = new UserRelease();
    1043. // userRelease.setModified(new Date());
    1044. // userRelease.setSid(sid);
    1045. // userRelease.setUid(uid);
    1046. // shopInformation.setId(sid);
    1047. Random random = new Random();
    1048. ShopInformation shopInformation;
    1049. UserRelease userRelease;
    1050. int level, uid, quantity;
    1051. double price;
    1052. for (int i = 1, k = 1, j = 189; i < 1000; i++, j++, k++) {
    1053. if (k > 94) {
    1054. k = 1;
    1055. }
    1056. level = random.nextInt(10) + 1;
    1057. price = Math.random() * 1000 + 1;
    1058. quantity = random.nextInt(10) + 1;
    1059. uid = random.nextInt(100) + 1;
    1060. shopInformation = new ShopInformation();
    1061. shopInformation.setId(j);
    1062. shopInformation.setName("百年孤独");
    1063. shopInformation.setModified(new Date());
    1064. shopInformation.setLevel(level);
    1065. shopInformation.setRemark("看上的请联系我,QQ:test,微信:test");
    1066. // double price = Math.random()*1000.00+1;
    1067. shopInformation.setPrice(new BigDecimal(price));
    1068. shopInformation.setSort(k);
    1069. shopInformation.setQuantity(quantity);
    1070. shopInformation.setImage("/image/QyBHYiMfYQ4XZFCqxEv0.jpg");
    1071. // int uid = random.nextInt(100)+1;
    1072. shopInformation.setUid(uid);
    1073. // userRelease = new UserRelease();
    1074. // userRelease.setUid(uid);
    1075. // userRelease.setSid(j);
    1076. // userRelease.setModified(new Date());
    1077. // userRelease.setDisplay(1);
    1078. shopInformationService.updateByPrimaryKeySelective(shopInformation);
    1079. // userReleaseService.insertSelective(userRelease);
    1080. }
    1081. System.out.println("success");
    1082. return "page/publish_product";
    1083. }
    1084. }

    如果也想学习本系统,下面领取。关注并回复:063ssm 

  • 相关阅读:
    SCOUT MINI Pro松灵机器人j建图定点步骤
    React笔记(六)React路由
    DP1.4接口换新显示器开机无Logo、进主板BIOS黑屏解决方案
    MongoDB(一):CentOS7离线安装MongoDB单机版与简单使用
    JAVA解析Excel工具EasyExcel
    Jupyter常用的实战操作总结(强烈建议收藏,持续更新中... ... )
    【华为OD机试真题 python】 水仙花数【2022 Q4 | 100分】
    【趣学算法】Day1 算法简介+斐波那契数列
    分布式事务
    avalanche 少量tcp长连接持续构建HTTP请求测试
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126717126