• Java项目:springBoot+Mysql实现的校园二手在线交易平台系统


    作者主页:夜未央5788

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

    文末获取源码

    项目介绍

    本项目分为管理员与普通用户两种角色

    后台管理员功能:

    求购管理,收购管理,学生管理,评论管理,建议管理,新闻公告,网站设置,订单管理,图书管理。
    1.求购管理实现了查看前台用户发布的求购信息和删除功能
    2.收购管理实现了学生发布的二手书籍商品的查看和收购
    3.学生管理实现了前台用户信息的查看和账号冻结功能
    4.评论管理实现了对发布的图书的留言评论信息的查看和删除功能
    5.建议管理实现了用户对发布的二手书籍的建议查看和删除
    6.新闻公告实现了新闻公告的发布的增删改查,在前台首页显示
    7.网站设置分为友情链接和站点设置
    A、友情链接实现了前台下面的友情网站的增删改查,(比如发布一个网址)
    B、站点设置实现了前台显示logo和网站名称的增删改查
    8.订单管理实现了用户购买的订单信息的查看
    9.图书管理实现了分类列表和图书列表
    A、分类列表实现书籍分类的增删改查(二级分类)

    B、图书列表实现了被收购的二手书籍在这里进行编辑,上架下架,是否进行推荐(上架后,用户可以进行购买)

    前台用户功能:

    注册登录,个人信息的管理,我发布的出售书籍,我发布的求购书籍管理,我建议的书籍,查看书籍订单,求购专区查看等等功能。
    1.个人信息实现了个人信息的管理和密码修改
    2.我发布的出售书籍实现了可以对出售的书籍进行增删改查(被官网收购后只能查看)
    3.我发布的求购书籍实现了可以对求购书籍进行增删改查
    4.我建议的书籍实现了对某个上架的书籍的建议查看
    5.查看书籍订单实现了查看购买的书籍
    6.求购专区实现了查看全部求购信息
    7.前台书籍信息的查看,新闻公告的查看等等功能

    使用人群:
    正在做毕设的学生,或者需要项目实战练习的Java学习者

    由于本程序规模不大,可供课程设计,毕业设计学习演示之用

    环境需要

    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.数据库:MySql 8.0/5.7版本;

    6.是否Maven项目:是;

    技术栈

    SpringBoot+springJpa+freemarker+CSS+JavaScript+mysql

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
    2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
    3. 将项目中application-dev.properties配置文件中的数据库配置改为自己的配置;
    4. 运行项目,前台地址:在浏览器中输入http://localhost:8081/home/index/index 访问
    管理员账号密码:admin/123456

    后台地址:http://localhost:8081/system/login

    普通用户账号密码:111/111

    运行截图

    前台界面

     

     

     

     

     

    管理员界面

     

     

     

     

     

     

     

     

    相关代码 

    HomeStudentController

    1. package com.yuanlrc.campus_market.controller.home;
    2. import java.util.HashMap;
    3. import java.util.List;
    4. import java.util.Map;
    5. import org.springframework.beans.factory.annotation.Autowired;
    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 com.yuanlrc.campus_market.bean.CodeMsg;
    13. import com.yuanlrc.campus_market.bean.Result;
    14. import com.yuanlrc.campus_market.constant.SessionConstant;
    15. import com.yuanlrc.campus_market.entity.common.Comment;
    16. import com.yuanlrc.campus_market.entity.common.Goods;
    17. import com.yuanlrc.campus_market.entity.common.ReportGoods;
    18. import com.yuanlrc.campus_market.entity.common.Student;
    19. import com.yuanlrc.campus_market.entity.common.WantedGoods;
    20. import com.yuanlrc.campus_market.service.common.CommentService;
    21. import com.yuanlrc.campus_market.service.common.GoodsCategoryService;
    22. import com.yuanlrc.campus_market.service.common.GoodsService;
    23. import com.yuanlrc.campus_market.service.common.ReportGoodsService;
    24. import com.yuanlrc.campus_market.service.common.StudentService;
    25. import com.yuanlrc.campus_market.service.common.WantedGoodsService;
    26. import com.yuanlrc.campus_market.util.SessionUtil;
    27. import com.yuanlrc.campus_market.util.ValidateEntityUtil;
    28. /**
    29. * 学生中心控制器
    30. * @author Administrator
    31. *
    32. */
    33. @RequestMapping("/home/student")
    34. @Controller
    35. public class HomeStudentController {
    36. @Autowired
    37. private GoodsCategoryService goodsCategoryService;
    38. @Autowired
    39. private StudentService studentService;
    40. @Autowired
    41. private GoodsService goodsService;
    42. @Autowired
    43. private WantedGoodsService wantedGoodsService;
    44. @Autowired
    45. private ReportGoodsService reportGoodsService;
    46. @Autowired
    47. private CommentService commentService;
    48. /**
    49. * 学生登录主页
    50. * @param model
    51. * @return
    52. */
    53. @RequestMapping(value="/index",method=RequestMethod.GET)
    54. public String index(Model model){
    55. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    56. model.addAttribute("goodsList", goodsService.findByStudent(loginedStudent));
    57. model.addAttribute("wantedGoodsList", wantedGoodsService.findByStudent(loginedStudent));
    58. model.addAttribute("reportGoodsList", reportGoodsService.findByStudent(loginedStudent));
    59. return "home/student/index";
    60. }
    61. /**
    62. * 修改个人信息提交表单
    63. * @param student
    64. * @return
    65. */
    66. @RequestMapping(value="/edit_info",method=RequestMethod.POST)
    67. @ResponseBody
    68. public Result editInfo(Student student){
    69. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    70. loginedStudent.setAcademy(student.getAcademy());
    71. loginedStudent.setGrade(student.getGrade());
    72. loginedStudent.setMobile(student.getMobile());
    73. loginedStudent.setNickname(student.getNickname());
    74. loginedStudent.setQq(student.getQq());
    75. loginedStudent.setSchool(student.getSchool());
    76. if(studentService.save(loginedStudent) == null){
    77. return Result.error(CodeMsg.HOME_STUDENT_EDITINFO_ERROR);
    78. }
    79. SessionUtil.set(SessionConstant.SESSION_STUDENT_LOGIN_KEY,loginedStudent);
    80. return Result.success(true);
    81. }
    82. /**
    83. * 保存用户头像
    84. * @param headPic
    85. * @return
    86. */
    87. @RequestMapping(value="/update_head_pic",method=RequestMethod.POST)
    88. @ResponseBody
    89. public Result updateHeadPic(@RequestParam(name="headPic",required=true)String headPic){
    90. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    91. loginedStudent.setHeadPic(headPic);;
    92. if(studentService.save(loginedStudent) == null){
    93. return Result.error(CodeMsg.HOME_STUDENT_EDITINFO_ERROR);
    94. }
    95. SessionUtil.set(SessionConstant.SESSION_STUDENT_LOGIN_KEY,loginedStudent);
    96. return Result.success(true);
    97. }
    98. /**
    99. * 物品发布页面
    100. * @param model
    101. * @return
    102. */
    103. @RequestMapping(value="/publish",method=RequestMethod.GET)
    104. public String publish(Model model){
    105. return "home/student/publish";
    106. }
    107. /**
    108. * 商品发布表单提交
    109. * @param goods
    110. * @return
    111. */
    112. @RequestMapping(value="/publish",method=RequestMethod.POST)
    113. @ResponseBody
    114. public Result publish(Goods goods){
    115. CodeMsg validate = ValidateEntityUtil.validate(goods);
    116. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
    117. return Result.error(validate);
    118. }
    119. if(goods.getGoodsCategory() == null || goods.getGoodsCategory().getId() == null || goods.getGoodsCategory().getId().longValue() == -1){
    120. return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_CATEGORY_EMPTY);
    121. }
    122. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    123. goods.setStudent(loginedStudent);
    124. if(goodsService.save(goods) == null){
    125. return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_ERROR);
    126. }
    127. return Result.success(true);
    128. }
    129. /**
    130. * 物品编辑页面
    131. * @param id
    132. * @param model
    133. * @return
    134. */
    135. @RequestMapping(value="/edit_goods",method=RequestMethod.GET)
    136. public String publish(@RequestParam(name="id",required=true)Long id,Model model){
    137. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    138. Goods goods = goodsService.find(id, loginedStudent.getId());
    139. if(goods == null){
    140. model.addAttribute("msg", "物品不存在!");
    141. return "error/runtime_error";
    142. }
    143. model.addAttribute("goods", goods);
    144. return "home/student/edit_goods";
    145. }
    146. /**
    147. * 物品编辑表单提交
    148. * @param goods
    149. * @return
    150. */
    151. @RequestMapping(value="/edit_goods",method=RequestMethod.POST)
    152. @ResponseBody
    153. public Result editGoods(Goods goods){
    154. CodeMsg validate = ValidateEntityUtil.validate(goods);
    155. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
    156. return Result.error(validate);
    157. }
    158. if(goods.getGoodsCategory() == null || goods.getGoodsCategory().getId() == null || goods.getGoodsCategory().getId().longValue() == -1){
    159. return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_CATEGORY_EMPTY);
    160. }
    161. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    162. Goods existGoods = goodsService.find(goods.getId(), loginedStudent.getId());
    163. if(existGoods == null){
    164. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    165. }
    166. existGoods.setBuyPrice(goods.getBuyPrice());
    167. existGoods.setContent(goods.getContent());
    168. existGoods.setGoodsCategory(goods.getGoodsCategory());
    169. existGoods.setName(goods.getName());
    170. existGoods.setPhoto(goods.getPhoto());
    171. existGoods.setSellPrice(goods.getSellPrice());
    172. if(goodsService.save(existGoods) == null){
    173. return Result.error(CodeMsg.HOME_STUDENT_GOODS_EDIT_ERROR);
    174. }
    175. return Result.success(true);
    176. }
    177. /**
    178. * 用户设置是否擦亮物品
    179. * @param id
    180. * @param flag
    181. * @return
    182. */
    183. @RequestMapping(value="/update_flag",method=RequestMethod.POST)
    184. @ResponseBody
    185. public Result updateFlag(@RequestParam(name="id",required=true)Long id,
    186. @RequestParam(name="flag",required=true,defaultValue="0")Integer flag){
    187. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    188. Goods existGoods = goodsService.find(id, loginedStudent.getId());
    189. if(existGoods == null){
    190. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    191. }
    192. existGoods.setFlag(flag);
    193. if(goodsService.save(existGoods) == null){
    194. return Result.error(CodeMsg.HOME_STUDENT_GOODS_EDIT_ERROR);
    195. }
    196. return Result.success(true);
    197. }
    198. /**
    199. * 修改物品状态
    200. * @param id
    201. * @param status
    202. * @return
    203. */
    204. @RequestMapping(value="/update_status",method=RequestMethod.POST)
    205. @ResponseBody
    206. public Result updateStatus(@RequestParam(name="id",required=true)Long id,
    207. @RequestParam(name="status",required=true,defaultValue="2")Integer status){
    208. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    209. Goods existGoods = goodsService.find(id, loginedStudent.getId());
    210. if(existGoods == null){
    211. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    212. }
    213. existGoods.setStatus(status);
    214. if(goodsService.save(existGoods) == null){
    215. return Result.error(CodeMsg.HOME_STUDENT_GOODS_EDIT_ERROR);
    216. }
    217. return Result.success(true);
    218. }
    219. /**
    220. * 发布求购物品页面
    221. * @param model
    222. * @return
    223. */
    224. @RequestMapping(value="/publish_wanted",method=RequestMethod.GET)
    225. public String publishWanted(Model model){
    226. return "home/student/publish_wanted";
    227. }
    228. /**
    229. * 求购物品发布提交
    230. * @param wantedGoods
    231. * @return
    232. */
    233. @RequestMapping(value="/publish_wanted",method=RequestMethod.POST)
    234. @ResponseBody
    235. public Result publishWanted(WantedGoods wantedGoods){
    236. CodeMsg validate = ValidateEntityUtil.validate(wantedGoods);
    237. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
    238. return Result.error(validate);
    239. }
    240. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    241. wantedGoods.setStudent(loginedStudent);
    242. if(wantedGoodsService.save(wantedGoods) == null){
    243. return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_ERROR);
    244. }
    245. return Result.success(true);
    246. }
    247. /**
    248. * 编辑求购物品页面
    249. * @param id
    250. * @param model
    251. * @return
    252. */
    253. @RequestMapping(value="/edit_wanted_goods",method=RequestMethod.GET)
    254. public String editWantedGoods(@RequestParam(name="id",required=true)Long id,Model model){
    255. WantedGoods wantedGoods = wantedGoodsService.find(id);
    256. if(wantedGoods == null){
    257. model.addAttribute("msg", "求购物品不存在!");
    258. return "error/runtime_error";
    259. }
    260. model.addAttribute("wantedGoods", wantedGoods);
    261. return "home/student/edit_wanted";
    262. }
    263. /**
    264. * 编辑求购信息表单提交
    265. * @param wantedGoods
    266. * @return
    267. */
    268. @RequestMapping(value="/edit_wanted_goods",method=RequestMethod.POST)
    269. @ResponseBody
    270. public Result editWantedGoods(WantedGoods wantedGoods){
    271. CodeMsg validate = ValidateEntityUtil.validate(wantedGoods);
    272. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
    273. return Result.error(validate);
    274. }
    275. if(wantedGoods.getId() == null){
    276. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    277. }
    278. WantedGoods existWantedGoods = wantedGoodsService.find(wantedGoods.getId());
    279. if(existWantedGoods == null){
    280. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    281. }
    282. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    283. if(existWantedGoods.getStudent().getId().longValue() != loginedStudent.getId().longValue()){
    284. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    285. }
    286. existWantedGoods.setContent(wantedGoods.getContent());
    287. existWantedGoods.setName(wantedGoods.getName());
    288. existWantedGoods.setSellPrice(wantedGoods.getSellPrice());
    289. existWantedGoods.setTradePlace(wantedGoods.getTradePlace());
    290. if(wantedGoodsService.save(existWantedGoods) == null){
    291. return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_ERROR);
    292. }
    293. return Result.success(true);
    294. }
    295. /**
    296. * 删除求购物品
    297. * @param id
    298. * @return
    299. */
    300. @RequestMapping(value="/delete_wanted",method=RequestMethod.POST)
    301. @ResponseBody
    302. public Result deleteWanted(@RequestParam(name="id",required=true)Long id){
    303. WantedGoods wantedGoods = wantedGoodsService.find(id);
    304. if(wantedGoods == null){
    305. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    306. }
    307. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    308. if(wantedGoods.getStudent().getId().longValue() != loginedStudent.getId().longValue()){
    309. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    310. }
    311. wantedGoodsService.delete(id);
    312. return Result.success(true);
    313. }
    314. /**
    315. * 举报物品
    316. * @param reportGoods
    317. * @return
    318. */
    319. @RequestMapping(value="/report_goods",method=RequestMethod.POST)
    320. @ResponseBody
    321. public Result reportGoods(ReportGoods reportGoods){
    322. CodeMsg validate = ValidateEntityUtil.validate(reportGoods);
    323. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
    324. return Result.error(validate);
    325. }
    326. if(reportGoods.getGoods() == null || reportGoods.getGoods().getId() == null){
    327. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    328. }
    329. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    330. ReportGoods find = reportGoodsService.find(reportGoods.getGoods().getId(), loginedStudent.getId());
    331. if(find != null){
    332. return Result.error(CodeMsg.HOME_STUDENT_REPORTED_GOODS);
    333. }
    334. reportGoods.setStudent(loginedStudent);
    335. if(reportGoodsService.save(reportGoods) == null){
    336. return Result.error(CodeMsg.HOME_STUDENT_REPORT_GOODS_ERROR);
    337. }
    338. return Result.success(true);
    339. }
    340. /**
    341. * 删除举报信息
    342. * @param id
    343. * @return
    344. */
    345. @RequestMapping(value="/delete_report",method=RequestMethod.POST)
    346. @ResponseBody
    347. public Result deleteReport(@RequestParam(name="id",required=true)Long id){
    348. ReportGoods reportGoods = reportGoodsService.find(id);
    349. if(reportGoods == null){
    350. return Result.error(CodeMsg.HOME_STUDENT_REPORTED_NO_EXIST);
    351. }
    352. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    353. if(reportGoods.getStudent().getId().longValue() != loginedStudent.getId().longValue()){
    354. return Result.error(CodeMsg.HOME_STUDENT_REPORTED_NO_EXIST);
    355. }
    356. reportGoodsService.delete(id);
    357. return Result.success(true);
    358. }
    359. /**
    360. * 获取个人物品统计信息
    361. * @return
    362. */
    363. @RequestMapping(value="/get_stats",method=RequestMethod.POST)
    364. @ResponseBody
    365. public Result> getStats(){
    366. Map ret = new HashMap();
    367. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    368. List findByStudent = goodsService.findByStudent(loginedStudent);
    369. Integer goodsTotal = findByStudent.size();//已发布的商品总数
    370. Integer soldGoodsTotal = 0;
    371. Integer downGoodsTotal = 0;
    372. Integer upGoodsTotal = 0;
    373. for(Goods goods : findByStudent){
    374. if(goods.getStatus() == Goods.GOODS_STATUS_SOLD){
    375. soldGoodsTotal++;
    376. }
    377. if(goods.getStatus() == Goods.GOODS_STATUS_DOWN){
    378. downGoodsTotal++;
    379. }
    380. if(goods.getStatus() == Goods.GOODS_STATUS_UP){
    381. upGoodsTotal++;
    382. }
    383. }
    384. ret.put("goodsTotal", goodsTotal);
    385. ret.put("soldGoodsTotal", soldGoodsTotal);
    386. ret.put("downGoodsTotal", downGoodsTotal);
    387. ret.put("upGoodsTotal", upGoodsTotal);
    388. return Result.success(ret);
    389. }
    390. /**
    391. * 评论物品
    392. * @param comment
    393. * @return
    394. */
    395. @RequestMapping(value="/comment",method=RequestMethod.POST)
    396. @ResponseBody
    397. public Result comment(Comment comment){
    398. CodeMsg validate = ValidateEntityUtil.validate(comment);
    399. if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
    400. return Result.error(validate);
    401. }
    402. if(comment.getGoods() == null || comment.getGoods().getId() == null){
    403. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    404. }
    405. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    406. Goods find = goodsService.findById(comment.getGoods().getId());
    407. if(find == null){
    408. return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
    409. }
    410. comment.setStudent(loginedStudent);
    411. if(commentService.save(comment) == null){
    412. return Result.error(CodeMsg.HOME_STUDENT_COMMENT_ADD_ERROR);
    413. }
    414. return Result.success(true);
    415. }
    416. /**
    417. * 修改学生用户密码
    418. * @param oldPwd
    419. * @param newPwd
    420. * @return
    421. */
    422. @RequestMapping(value="/edit_pwd",method=RequestMethod.POST)
    423. @ResponseBody
    424. public Result editPwd(@RequestParam(name="oldPwd",required=true)String oldPwd,
    425. @RequestParam(name="newPwd",required=true)String newPwd){
    426. Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
    427. if(!loginedStudent.getPassword().equals(oldPwd)){
    428. return Result.error(CodeMsg.HOME_STUDENT_EDITPWD_OLD_ERROR);
    429. }
    430. loginedStudent.setPassword(newPwd);
    431. if(studentService.save(loginedStudent) == null){
    432. return Result.error(CodeMsg.HOME_STUDENT_EDITINFO_ERROR);
    433. }
    434. SessionUtil.set(SessionConstant.SESSION_STUDENT_LOGIN_KEY, loginedStudent);
    435. return Result.success(true);
    436. }
    437. }

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

  • 相关阅读:
    什么是SSRF攻击?该如何防御SSRF攻击?
    Mac vsCode快捷键总结
    MySQL-约束
    从“草原牛”到“数字牛”:蒙牛的数字化转型之道
    复习C语言
    Hystrix Readed time out,看我这一篇就让你彻底解决!
    l8-d7 实现TCP通信
    【分享】“钉钉第三方“ 在集简云集成应用的常见问题与解决方案
    面了个腾讯拿28k跳槽出来的,真正见识到了跳槽天花板
    开源软件的利弊
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/127643565