package com.squirrel.controller;
import com.squirrel.common.GgeeConst;
import com.squirrel.dto.AjaxResult;
import com.squirrel.pojo.*;
import com.squirrel.service.*;
import com.squirrel.util.DateUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping(value = "/goods")
public class GoodsController {
private static Log LOG = LogFactory.getLog(GoodsController.class);
@Autowired
private GoodsService goodsService;
@Autowired
private ImageService imageService;
@Autowired
private CatelogService catelogService;
@Autowired
private UserService userService;
@Autowired
private CommentsService commentsService;
/**
* 首页显示商品,每一类商品查询6件,根据最新上架排序 key的命名为catelogGoods1、catelogGoods2....
*
* @return
* @throws Exception
*/
@RequestMapping(value = "/homeGoods")
public ModelAndView homeGoods(HttpServletRequest request) throws Exception {
ModelAndView modelAndView = new ModelAndView();
User cur_user = (User) request.getSession().getAttribute("cur_user");
modelAndView.addObject("cur_user", cur_user);
//商品种类数量
int catelogSize = 7;
//每个种类显示商品数量
int goodsSize = 6;
for (int i = 1; i <= catelogSize; i++) {
List<Goods> goodsList = null;
List<GoodsExtend> goodsAndImage = null;
goodsList = goodsService.getGoodsByCatelogOrderByDate(i, goodsSize);
goodsAndImage = new ArrayList<GoodsExtend>();
for (int j = 0; j < goodsList.size() ; j++) {
//将用户信息和image信息封装到GoodsExtend类中,传给前台
GoodsExtend goodsExtend = new GoodsExtend();
Goods goods = goodsList.get(j);
List<Image> images = imageService.getImagesByGoodsPrimaryKey(goods.getId());
goodsExtend.setGoods(goods);
goodsExtend.setImages(images);
goodsAndImage.add(j, goodsExtend);
}
String key = "catelog" + "Goods" + i;
modelAndView.addObject(key, goodsAndImage);
}
modelAndView.setViewName("/goods/homeGoods");
return modelAndView;
}
@RequestMapping(value = "/search")
public ModelAndView searchGoods(HttpServletRequest request, @RequestParam(value = "str",required = false) String str)throws Exception {
List<Goods> goodsList = goodsService.searchGoods(str,str);
List<GoodsExtend> goodsExtendList = new ArrayList<GoodsExtend>();
for(int i = 0;i<goodsList.size();i++) {
GoodsExtend goodsExtend = new GoodsExtend();
Goods goods = goodsList.get(i);
List<Image> imageList = imageService.getImagesByGoodsPrimaryKey(goods.getId());
goodsExtend.setGoods(goods);
goodsExtend.setImages(imageList);
goodsExtendList.add(i,goodsExtend);
}
ModelAndView modelAndView = new ModelAndView();
User cur_user = (User) request.getSession().getAttribute("cur_user");
modelAndView.addObject("cur_user", cur_user);
modelAndView.addObject("goodsExtendList", goodsExtendList);
modelAndView.addObject("search",str);
modelAndView.setViewName("/goods/searchGoods");
return modelAndView;
}
/**
* 查询该类商品
* @param id
* 要求该参数不为空
* @return
* @throws Exception
*/
@RequestMapping(value = "/catelog/{id}")
public ModelAndView catelogGoods(HttpServletRequest request, @PathVariable("id") Integer id,
@RequestParam(value = "str",required = false) String str) throws Exception {
List<Goods> goodsList = goodsService.getGoodsByCatelog(id,str,str);
Catelog catelog = catelogService.selectByPrimaryKey(id);
List<GoodsExtend> goodsExtendList = new ArrayList<GoodsExtend>();
for(int i = 0;i<goodsList.size();i++) {
GoodsExtend goodsExtend = new GoodsExtend();
Goods goods = goodsList.get(i);
List<Image> imageList = imageService.getImagesByGoodsPrimaryKey(goods.getId());
goodsExtend.setGoods(goods);
goodsExtend.setImages(imageList);
goodsExtendList.add(i,goodsExtend);
}
ModelAndView modelAndView = new ModelAndView();
User cur_user = (User) request.getSession().getAttribute("cur_user");
modelAndView.addObject("cur_user", cur_user);
modelAndView.addObject("goodsExtendList", goodsExtendList);
modelAndView.addObject("catelog", catelog);
modelAndView.addObject("search",str);
modelAndView.setViewName("/goods/catelogGoods");
return modelAndView;
}
/**
* 根据商品id查询该商品详细信息
* @param id
* @return
* @throws Exception
*/
@RequestMapping(value = "/goodsId/{id}")
public ModelAndView getGoodsById(HttpServletRequest request, @PathVariable("id") Integer id,@RequestParam(value = "str",required = false) String str) throws Exception {
Goods goods = goodsService.getGoodsByPrimaryKey(id);
User seller = userService.selectByPrimaryKey(goods.getUserId());
Catelog catelog = catelogService.selectByPrimaryKey(goods.getCatelogId());
GoodsExtend goodsExtend = new GoodsExtend();
List<Image> imageList = imageService.getImagesByGoodsPrimaryKey(id);
goodsExtend.setGoods(goods);
goodsExtend.setImages(imageList);
ModelAndView modelAndView = new ModelAndView();
User cur_user = (User) request.getSession().getAttribute("cur_user");
List<Comments> commentsList = commentsService.getCommentsByGoodsId(id);
Set<Integer> userIds = new HashSet<>();
for (Comments comments : commentsList) {
userIds.add(comments.getUserId());
if (comments.getAtuserId() != 0){
userIds.add(comments.getAtuserId());
}
}
List<User> users = userService.getUsersByIds(userIds);
Map<Integer, User> id2user = users.stream().
collect(Collectors.toMap(User::getId, user -> user));
for (Comments comments : commentsList) {
comments.setUser(id2user.get(comments.getUserId()));
if (comments.getAtuserId() != 0){
comments.setAtuser(id2user.get(comments.getAtuserId()));
}
}
modelAndView.addObject("cur_user", cur_user);
modelAndView.addObject("goodsExtend", goodsExtend);
modelAndView.addObject("seller", seller);
modelAndView.addObject("search",str);
modelAndView.addObject("catelog", catelog);
modelAndView.addObject("commentsList", commentsList);
modelAndView.setViewName("/goods/detailGoods");
return modelAndView;
}
/**
* 修改商品信息
*
* @return
* @throws Exception
*/
@RequestMapping(value = "/editGoods/{id}")
public ModelAndView editGoods(HttpServletRequest request, @PathVariable("id") Integer id) throws Exception {
Goods goods = goodsService.getGoodsByPrimaryKey(id);
List<Image> imageList = imageService.getImagesByGoodsPrimaryKey(id);
GoodsExtend goodsExtend = new GoodsExtend();
goodsExtend.setGoods(goods);
goodsExtend.setImages(imageList);
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于springboot + vue的校园二手交易平台源码+数据库(毕业设计).zip 主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者。也可作为课程设计、期末大作业。包含全部项目源码、该项目可以直接作为毕设使用。项目都经过严格调试,下载即用确保可以运行! 基于springboot + vue的校园二手交易平台源码+数据库(毕业设计).zip 主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者。也可作为课程设计、期末大作业。包含全部项目源码、该项目可以直接作为毕设使用。项目都经过严格调试,下载即用确保可以运行!基于springboot + vue的校园二手交易平台源码+数据库(毕业设计).zip 主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者。也可作为课程设计、期末大作业。包含全部项目源码、该项目可以直接作为毕设使用。项目都经过严格调试,下载即用确保可以运行!基于springboot + vue的校园二手交易平台源码+数据库(毕业设计).zip 主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者。也可作为课
资源推荐
资源详情
资源评论
收起资源包目录
基于springboot + vue的校园二手交易平台源码+数据库(毕业设计).zip (194个子文件)
mvnw.cmd 5KB
detail.css 214KB
index.css 213KB
bootstrap.min.css 118KB
base.css 59KB
userhome.css 54KB
font-awesome.min.css 28KB
bootstrap-datetimepicker.min.css 11KB
fileinput.min.css 7KB
user.css 7KB
toastr.min.css 7KB
style.css 4KB
emoji.css 4KB
manage-app.css 2KB
manage-login.css 828B
materialize-icon.css 569B
fontawesome-webfont.eot 162KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
loading-sm.gif 3KB
loading.gif 847B
homeGoods.html 24KB
detailGoods.html 19KB
catelogGoods.html 14KB
searchGoods.html 13KB
manage-userList.html 12KB
pubGoods.html 12KB
manage-goodsList.html 11KB
goods.html 11KB
editGoods.html 10KB
home.html 7KB
basic.html 7KB
manage-login.html 3KB
404.html 682B
404.html 682B
index.html 0B
GoodsController.java 14KB
UserController.java 10KB
WriteExcel.java 8KB
DateUtil.java 7KB
DruidConfig.java 6KB
UserServiceImpl.java 5KB
ManageController.java 4KB
GoodsServiceImpl.java 4KB
Goods.java 3KB
GoodsServiceTest.java 3KB
UserServiceTest.java 3KB
Application.java 2KB
User.java 2KB
GoodsMapper.java 2KB
AjaxResult.java 2KB
GoodsService.java 2KB
CommentsController.java 2KB
CatelogServiceTest.java 2KB
Comments.java 1KB
ImageServiceTest.java 1KB
MainController.java 1KB
Reply.java 1KB
MD5.java 1KB
CatelogServiceImpl.java 1KB
MyWebMvcConfigurerAdapter.java 1KB
UserMapper.java 978B
Catelog.java 970B
Notice.java 959B
CommentsServiceImpl.java 948B
UserService.java 822B
UserGrid.java 814B
GgeeConst.java 794B
ImageServiceImpl.java 782B
GgeeWebError.java 745B
CatelogMapper.java 726B
ImageMapper.java 647B
CommentsMapper.java 609B
Image.java 576B
GoodsExtend.java 474B
ImageService.java 463B
NoticeMapper.java 455B
ReplyMapper.java 447B
CatelogService.java 356B
ApplicationTests.java 323B
CommentsService.java 317B
CatelogController.java 269B
GgeeWebException.java 218B
e9562bb5-6196-438e-a40d-8133f33cfaff.jpg 1.11MB
gdufe_bg.jpg 117KB
2952fe1e-0633-4f9d-9249-f999603235f5.jpg 64KB
26c2c89b-9312-4759-88a0-7f73f86c549d.jpg 64KB
01974fb4-da95-4191-8c80-e89db4a4e7a3.jpg 63KB
f2857094-1642-4d22-88b8-d06c290944fe.jpg 53KB
3c95fa0d-d5e3-40f7-826f-cafe6e6af740.jpg 48KB
612b5f9a-1017-49e3-ab39-878199a8b63c.jpg 39KB
file-1493726053986.JPG 38KB
e26183d0-244c-4da4-86dd-387d0ef8dfeb.jpg 36KB
dee36400-df6a-46ac-96df-d71a7c42f328.jpg 34KB
27c63995-9ff9-453d-b24f-d9aa95dcc138.jpg 34KB
68bac661-f69f-4ec5-8f21-f92ec1970547.jpg 34KB
0a281a3b-f4e1-445b-b7a0-3f7a829849bc.jpg 33KB
4859432c-5955-411b-bdaa-d65275a9a61a.jpg 32KB
e80e60a1-859c-4277-9a6a-c6bfe95dcf7a.jpg 31KB
d8ca0740-bdf3-416b-8557-8384e7299924.jpg 30KB
共 194 条
- 1
- 2
资源评论
程序员张小妍
- 粉丝: 1w+
- 资源: 3691
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 【年度调薪】年度薪酬预算执行情况报告.xls
- 【年度调薪】调薪考核表.xls
- 【年度调薪】调薪矩阵表(HR总监绝密).xls
- 【年度调薪】度员工调薪登记表.xlsx
- 【年度调薪】薪资等级结构表.xls
- 【年度调薪】调薪调岗流程表格.xls
- 【年度调薪】部门年度薪资调整套级审批表.xlsx
- 【年度调薪】调薪流程.xlsx
- 【年度调薪】年度员工调薪登记表.xlsx
- 【年度调薪】员工调薪评估.xlsx
- 【年度调薪】员工加薪明细表.xlsx
- 【年度调薪】员工调薪记录表.xlsx
- 【年度调薪】HR疑难操作之调岗调薪(实务篇).doc
- 【年度调薪】工资评定调薪方案.doc
- 【年度调薪】年度调薪方案.doc
- 【年度调薪】调岗调薪操作技巧.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功