作者主页:夜未央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
- package com.yuanlrc.campus_market.controller.home;
-
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
-
- import com.yuanlrc.campus_market.bean.CodeMsg;
- import com.yuanlrc.campus_market.bean.Result;
- import com.yuanlrc.campus_market.constant.SessionConstant;
- import com.yuanlrc.campus_market.entity.common.Comment;
- import com.yuanlrc.campus_market.entity.common.Goods;
- import com.yuanlrc.campus_market.entity.common.ReportGoods;
- import com.yuanlrc.campus_market.entity.common.Student;
- import com.yuanlrc.campus_market.entity.common.WantedGoods;
- import com.yuanlrc.campus_market.service.common.CommentService;
- import com.yuanlrc.campus_market.service.common.GoodsCategoryService;
- import com.yuanlrc.campus_market.service.common.GoodsService;
- import com.yuanlrc.campus_market.service.common.ReportGoodsService;
- import com.yuanlrc.campus_market.service.common.StudentService;
- import com.yuanlrc.campus_market.service.common.WantedGoodsService;
- import com.yuanlrc.campus_market.util.SessionUtil;
- import com.yuanlrc.campus_market.util.ValidateEntityUtil;
-
- /**
- * 学生中心控制器
- * @author Administrator
- *
- */
- @RequestMapping("/home/student")
- @Controller
- public class HomeStudentController {
-
- @Autowired
- private GoodsCategoryService goodsCategoryService;
- @Autowired
- private StudentService studentService;
- @Autowired
- private GoodsService goodsService;
- @Autowired
- private WantedGoodsService wantedGoodsService;
- @Autowired
- private ReportGoodsService reportGoodsService;
- @Autowired
- private CommentService commentService;
- /**
- * 学生登录主页
- * @param model
- * @return
- */
- @RequestMapping(value="/index",method=RequestMethod.GET)
- public String index(Model model){
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- model.addAttribute("goodsList", goodsService.findByStudent(loginedStudent));
- model.addAttribute("wantedGoodsList", wantedGoodsService.findByStudent(loginedStudent));
- model.addAttribute("reportGoodsList", reportGoodsService.findByStudent(loginedStudent));
- return "home/student/index";
- }
-
- /**
- * 修改个人信息提交表单
- * @param student
- * @return
- */
- @RequestMapping(value="/edit_info",method=RequestMethod.POST)
- @ResponseBody
- public Result
editInfo(Student student){ - Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- loginedStudent.setAcademy(student.getAcademy());
- loginedStudent.setGrade(student.getGrade());
- loginedStudent.setMobile(student.getMobile());
- loginedStudent.setNickname(student.getNickname());
- loginedStudent.setQq(student.getQq());
- loginedStudent.setSchool(student.getSchool());
- if(studentService.save(loginedStudent) == null){
- return Result.error(CodeMsg.HOME_STUDENT_EDITINFO_ERROR);
- }
- SessionUtil.set(SessionConstant.SESSION_STUDENT_LOGIN_KEY,loginedStudent);
- return Result.success(true);
- }
-
- /**
- * 保存用户头像
- * @param headPic
- * @return
- */
- @RequestMapping(value="/update_head_pic",method=RequestMethod.POST)
- @ResponseBody
- public Result
updateHeadPic(@RequestParam(name="headPic",required=true)String headPic){ - Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- loginedStudent.setHeadPic(headPic);;
- if(studentService.save(loginedStudent) == null){
- return Result.error(CodeMsg.HOME_STUDENT_EDITINFO_ERROR);
- }
- SessionUtil.set(SessionConstant.SESSION_STUDENT_LOGIN_KEY,loginedStudent);
- return Result.success(true);
- }
-
- /**
- * 物品发布页面
- * @param model
- * @return
- */
- @RequestMapping(value="/publish",method=RequestMethod.GET)
- public String publish(Model model){
- return "home/student/publish";
- }
-
- /**
- * 商品发布表单提交
- * @param goods
- * @return
- */
- @RequestMapping(value="/publish",method=RequestMethod.POST)
- @ResponseBody
- public Result
publish(Goods goods){ - CodeMsg validate = ValidateEntityUtil.validate(goods);
- if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
- return Result.error(validate);
- }
- if(goods.getGoodsCategory() == null || goods.getGoodsCategory().getId() == null || goods.getGoodsCategory().getId().longValue() == -1){
- return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_CATEGORY_EMPTY);
- }
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- goods.setStudent(loginedStudent);
- if(goodsService.save(goods) == null){
- return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_ERROR);
- }
- return Result.success(true);
- }
-
- /**
- * 物品编辑页面
- * @param id
- * @param model
- * @return
- */
- @RequestMapping(value="/edit_goods",method=RequestMethod.GET)
- public String publish(@RequestParam(name="id",required=true)Long id,Model model){
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- Goods goods = goodsService.find(id, loginedStudent.getId());
- if(goods == null){
- model.addAttribute("msg", "物品不存在!");
- return "error/runtime_error";
- }
- model.addAttribute("goods", goods);
- return "home/student/edit_goods";
- }
-
- /**
- * 物品编辑表单提交
- * @param goods
- * @return
- */
- @RequestMapping(value="/edit_goods",method=RequestMethod.POST)
- @ResponseBody
- public Result
editGoods(Goods goods){ - CodeMsg validate = ValidateEntityUtil.validate(goods);
- if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
- return Result.error(validate);
- }
- if(goods.getGoodsCategory() == null || goods.getGoodsCategory().getId() == null || goods.getGoodsCategory().getId().longValue() == -1){
- return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_CATEGORY_EMPTY);
- }
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- Goods existGoods = goodsService.find(goods.getId(), loginedStudent.getId());
- if(existGoods == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- existGoods.setBuyPrice(goods.getBuyPrice());
- existGoods.setContent(goods.getContent());
- existGoods.setGoodsCategory(goods.getGoodsCategory());
- existGoods.setName(goods.getName());
- existGoods.setPhoto(goods.getPhoto());
- existGoods.setSellPrice(goods.getSellPrice());
- if(goodsService.save(existGoods) == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_EDIT_ERROR);
- }
- return Result.success(true);
- }
-
- /**
- * 用户设置是否擦亮物品
- * @param id
- * @param flag
- * @return
- */
- @RequestMapping(value="/update_flag",method=RequestMethod.POST)
- @ResponseBody
- public Result
updateFlag(@RequestParam(name="id",required=true)Long id, - @RequestParam(name="flag",required=true,defaultValue="0")Integer flag){
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- Goods existGoods = goodsService.find(id, loginedStudent.getId());
- if(existGoods == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- existGoods.setFlag(flag);
- if(goodsService.save(existGoods) == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_EDIT_ERROR);
- }
- return Result.success(true);
- }
-
- /**
- * 修改物品状态
- * @param id
- * @param status
- * @return
- */
- @RequestMapping(value="/update_status",method=RequestMethod.POST)
- @ResponseBody
- public Result
updateStatus(@RequestParam(name="id",required=true)Long id, - @RequestParam(name="status",required=true,defaultValue="2")Integer status){
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- Goods existGoods = goodsService.find(id, loginedStudent.getId());
- if(existGoods == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- existGoods.setStatus(status);
- if(goodsService.save(existGoods) == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_EDIT_ERROR);
- }
- return Result.success(true);
- }
-
- /**
- * 发布求购物品页面
- * @param model
- * @return
- */
- @RequestMapping(value="/publish_wanted",method=RequestMethod.GET)
- public String publishWanted(Model model){
- return "home/student/publish_wanted";
- }
-
- /**
- * 求购物品发布提交
- * @param wantedGoods
- * @return
- */
- @RequestMapping(value="/publish_wanted",method=RequestMethod.POST)
- @ResponseBody
- public Result
publishWanted(WantedGoods wantedGoods){ - CodeMsg validate = ValidateEntityUtil.validate(wantedGoods);
- if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
- return Result.error(validate);
- }
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- wantedGoods.setStudent(loginedStudent);
- if(wantedGoodsService.save(wantedGoods) == null){
- return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_ERROR);
- }
- return Result.success(true);
- }
-
- /**
- * 编辑求购物品页面
- * @param id
- * @param model
- * @return
- */
- @RequestMapping(value="/edit_wanted_goods",method=RequestMethod.GET)
- public String editWantedGoods(@RequestParam(name="id",required=true)Long id,Model model){
- WantedGoods wantedGoods = wantedGoodsService.find(id);
- if(wantedGoods == null){
- model.addAttribute("msg", "求购物品不存在!");
- return "error/runtime_error";
- }
- model.addAttribute("wantedGoods", wantedGoods);
- return "home/student/edit_wanted";
- }
-
- /**
- * 编辑求购信息表单提交
- * @param wantedGoods
- * @return
- */
- @RequestMapping(value="/edit_wanted_goods",method=RequestMethod.POST)
- @ResponseBody
- public Result
editWantedGoods(WantedGoods wantedGoods){ - CodeMsg validate = ValidateEntityUtil.validate(wantedGoods);
- if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
- return Result.error(validate);
- }
- if(wantedGoods.getId() == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- WantedGoods existWantedGoods = wantedGoodsService.find(wantedGoods.getId());
- if(existWantedGoods == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- if(existWantedGoods.getStudent().getId().longValue() != loginedStudent.getId().longValue()){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- existWantedGoods.setContent(wantedGoods.getContent());
- existWantedGoods.setName(wantedGoods.getName());
- existWantedGoods.setSellPrice(wantedGoods.getSellPrice());
- existWantedGoods.setTradePlace(wantedGoods.getTradePlace());
- if(wantedGoodsService.save(existWantedGoods) == null){
- return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_ERROR);
- }
-
- return Result.success(true);
- }
-
- /**
- * 删除求购物品
- * @param id
- * @return
- */
- @RequestMapping(value="/delete_wanted",method=RequestMethod.POST)
- @ResponseBody
- public Result
deleteWanted(@RequestParam(name="id",required=true)Long id){ - WantedGoods wantedGoods = wantedGoodsService.find(id);
- if(wantedGoods == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- if(wantedGoods.getStudent().getId().longValue() != loginedStudent.getId().longValue()){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- wantedGoodsService.delete(id);
- return Result.success(true);
- }
-
- /**
- * 举报物品
- * @param reportGoods
- * @return
- */
- @RequestMapping(value="/report_goods",method=RequestMethod.POST)
- @ResponseBody
- public Result
reportGoods(ReportGoods reportGoods){ - CodeMsg validate = ValidateEntityUtil.validate(reportGoods);
- if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
- return Result.error(validate);
- }
- if(reportGoods.getGoods() == null || reportGoods.getGoods().getId() == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- ReportGoods find = reportGoodsService.find(reportGoods.getGoods().getId(), loginedStudent.getId());
- if(find != null){
- return Result.error(CodeMsg.HOME_STUDENT_REPORTED_GOODS);
- }
- reportGoods.setStudent(loginedStudent);
- if(reportGoodsService.save(reportGoods) == null){
- return Result.error(CodeMsg.HOME_STUDENT_REPORT_GOODS_ERROR);
- }
- return Result.success(true);
- }
-
- /**
- * 删除举报信息
- * @param id
- * @return
- */
- @RequestMapping(value="/delete_report",method=RequestMethod.POST)
- @ResponseBody
- public Result
deleteReport(@RequestParam(name="id",required=true)Long id){ - ReportGoods reportGoods = reportGoodsService.find(id);
- if(reportGoods == null){
- return Result.error(CodeMsg.HOME_STUDENT_REPORTED_NO_EXIST);
- }
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- if(reportGoods.getStudent().getId().longValue() != loginedStudent.getId().longValue()){
- return Result.error(CodeMsg.HOME_STUDENT_REPORTED_NO_EXIST);
- }
- reportGoodsService.delete(id);
- return Result.success(true);
- }
-
- /**
- * 获取个人物品统计信息
- * @return
- */
- @RequestMapping(value="/get_stats",method=RequestMethod.POST)
- @ResponseBody
- public Result
- Map
ret = new HashMap(); - Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- List
findByStudent = goodsService.findByStudent(loginedStudent); - Integer goodsTotal = findByStudent.size();//已发布的商品总数
- Integer soldGoodsTotal = 0;
- Integer downGoodsTotal = 0;
- Integer upGoodsTotal = 0;
- for(Goods goods : findByStudent){
- if(goods.getStatus() == Goods.GOODS_STATUS_SOLD){
- soldGoodsTotal++;
- }
- if(goods.getStatus() == Goods.GOODS_STATUS_DOWN){
- downGoodsTotal++;
- }
- if(goods.getStatus() == Goods.GOODS_STATUS_UP){
- upGoodsTotal++;
- }
- }
- ret.put("goodsTotal", goodsTotal);
- ret.put("soldGoodsTotal", soldGoodsTotal);
- ret.put("downGoodsTotal", downGoodsTotal);
- ret.put("upGoodsTotal", upGoodsTotal);
- return Result.success(ret);
- }
-
- /**
- * 评论物品
- * @param comment
- * @return
- */
- @RequestMapping(value="/comment",method=RequestMethod.POST)
- @ResponseBody
- public Result
comment(Comment comment){ - CodeMsg validate = ValidateEntityUtil.validate(comment);
- if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
- return Result.error(validate);
- }
- if(comment.getGoods() == null || comment.getGoods().getId() == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- Goods find = goodsService.findById(comment.getGoods().getId());
- if(find == null){
- return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
- }
- comment.setStudent(loginedStudent);
- if(commentService.save(comment) == null){
- return Result.error(CodeMsg.HOME_STUDENT_COMMENT_ADD_ERROR);
- }
- return Result.success(true);
- }
-
- /**
- * 修改学生用户密码
- * @param oldPwd
- * @param newPwd
- * @return
- */
- @RequestMapping(value="/edit_pwd",method=RequestMethod.POST)
- @ResponseBody
- public Result
editPwd(@RequestParam(name="oldPwd",required=true)String oldPwd, - @RequestParam(name="newPwd",required=true)String newPwd){
- Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
- if(!loginedStudent.getPassword().equals(oldPwd)){
- return Result.error(CodeMsg.HOME_STUDENT_EDITPWD_OLD_ERROR);
- }
- loginedStudent.setPassword(newPwd);
- if(studentService.save(loginedStudent) == null){
- return Result.error(CodeMsg.HOME_STUDENT_EDITINFO_ERROR);
- }
- SessionUtil.set(SessionConstant.SESSION_STUDENT_LOGIN_KEY, loginedStudent);
- return Result.success(true);
- }
- }
如果也想学习本系统,下面领取。关注并回复:104springboot