package com.bupt.controller;
import com.bupt.config.GgeeConst;
import com.bupt.dto.AjaxResult;
import com.bupt.pojo.*;
import com.bupt.service.*;
import com.bupt.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);
ModelAndView mo
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
javaweb期末大作业课程设计二手闲置物品交易系统源码。javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码javaweb期末大作业课程设计二手闲置物品交易系统源码
资源推荐
资源详情
资源评论
收起资源包目录
javaweb期末大作业课程设计二手闲置物品交易系统源码.zip (352个子文件)
GoodsController.class 15KB
UserController.class 10KB
DruidConfig.class 6KB
UserServiceImpl.class 5KB
GoodsServiceImpl.class 5KB
Goods.class 4KB
DateUtil.class 4KB
Application.class 3KB
User.class 3KB
AjaxResult.class 3KB
CommentsController.class 3KB
Comments.class 2KB
GgeeWebError.class 2KB
GoodsMapper.class 2KB
Catelog.class 2KB
Reply.class 2KB
CatelogServiceImpl.class 2KB
MD5.class 2KB
CommentsServiceImpl.class 1KB
GoodsService.class 1KB
ImageServiceImpl.class 1KB
UserMapper.class 1KB
Image.class 1KB
GoodsExtend.class 1KB
UserService.class 1KB
CatelogServiceTest.class 948B
ImageServiceTest.class 938B
GoodsServiceTest.class 938B
UserServiceTest.class 933B
CatelogMapper.class 848B
ImageMapper.class 746B
CommentsMapper.class 713B
GgeeConst.class 664B
ApplicationTests.class 594B
CatelogController.class 505B
ReplyMapper.class 500B
CatelogService.class 461B
CommentsService.class 396B
ImageService.class 391B
mvnw.cmd 5KB
detail.css 214KB
detail.css 214KB
index.css 213KB
index.css 213KB
bootstrap.min.css 157KB
bootstrap.min.css 157KB
userhome.css 66KB
userhome.css 66KB
base.css 59KB
base.css 59KB
font-awesome.min.css 22KB
font-awesome.min.css 22KB
bootstrap-datetimepicker.min.css 11KB
bootstrap-datetimepicker.min.css 11KB
fileinput.min.css 7KB
fileinput.min.css 7KB
user.css 7KB
user.css 7KB
toastr.min.css 7KB
toastr.min.css 7KB
style.css 4KB
style.css 4KB
emoji.css 4KB
emoji.css 4KB
materialize-icon.css 569B
materialize-icon.css 569B
fontawesome-webfont.eot 162KB
fontawesome-webfont.eot 162KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
loading-sm.gif 3KB
loading-sm.gif 3KB
loading.gif 847B
loading.gif 847B
.gitignore 0B
homeGoods.html 21KB
homeGoods.html 21KB
detailGoods.html 18KB
detailGoods.html 18KB
catelogGoods.html 13KB
catelogGoods.html 13KB
searchGoods.html 13KB
searchGoods.html 13KB
pubGoods.html 11KB
pubGoods.html 11KB
editGoods.html 9KB
editGoods.html 9KB
goods.html 8KB
goods.html 8KB
home.html 7KB
home.html 7KB
basic.html 6KB
basic.html 6KB
404.html 682B
404.html 682B
index.html 0B
index.html 0B
Springboot_BigWork.iml 11KB
共 352 条
- 1
- 2
- 3
- 4
程序员张小妍
- 粉丝: 1w+
- 资源: 2604
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab实现对表面肌电信号进行归一化处理,并对归一化后的图形显示 .rar
- 基于matlab实现单级倒立摆的 T-S 模型 包括 LMI 程序源码
- 图书管理系统(struts+hibernate+spring+ext).rar
- 基于matlab实现此压缩包包含语音信号处理中的语音变声代码加音频.rar
- STM32使用PWM驱动舵机并通过OLED显示
- 基于matlab实现车辆路径规划;遗传算法;matlab代码.rar
- 图书管理系统(struts+hibernate+spring)130225.rar
- 基于matlab实现采用标量衍射理论,实现菲涅尔衍射和夫琅禾费衍射,对光波的波前传播和数字全息的应用有帮助.rar
- JavaScript版去除链表重复元素
- 微信小程序项目-功德木鱼(带设置面板-自定义文字、可选字体颜色、可选木鱼样式)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页