package com.dn.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.dn.domain.Cart;
/*import com.dn.domain.Color;
*/import com.dn.domain.Menu;
import com.dn.domain.Num;
import com.dn.domain.Product;
/*import com.dn.domain.Size;
*/import com.dn.service.CartService;
import com.dn.service.ProductService;
/*import com.dn.util.FileUpLoadUtil;*/
//商品控制器类
@Controller
@RequestMapping(value="/product")
public class ProductController {
//自动注入ProductService
@Autowired
@Qualifier("productService")
private ProductService productService;
//自动注入ProductService
@Autowired
@Qualifier("cartService")
private CartService cartService;
/******************************用户*********************************************/
//跳转到主页,并查询所有商品
@RequestMapping(value="/shop",method=RequestMethod.GET)
public ModelAndView forwordIndex(ModelAndView mv){
//查询所有商品
List<Product>productList=productService.selectAllProduct();
//查询菜单列表
List<Menu>menuList=productService.selectMenuName();
//把List放到model中
mv.addObject("productList", productList);
mv.addObject("menu", menuList);
//转发到index页面
mv.setViewName("index");
return mv;
}
//商品展示,查询单个商品
@RequestMapping(value="/showOneProduct")
public String show(Model model,Integer id){
//查询操作,商品表,颜色表,尺寸表,库存表联合查询
List<Product> product=productService.selectOneProduct(id);
//查询菜单列表
List<Menu>menuList=productService.selectMenuName();
model.addAttribute("menu", menuList);
/*//查询商品颜色
List<Color>colorList=productService.selectAllColor();
String product_Color[]=product.getColor().split(",");//分割字符串
//迭代器
Iterator<Color> iter = colorList.iterator();
boolean flag=true;
while(iter.hasNext()){
Color color = iter.next();
//判断字符数组和颜色集合中元素是否相同,不同则移除
for(int i=0;i<product_Color.length;i++){
if(color.getId()==Integer.valueOf(product_Color[i])){
flag=false;
}
}
if(flag){
iter.remove();
}
}
//查询商品尺寸
List<Size>sizeList=productService.selectAllSize();
String product_Size[]=product.getSize().split(",");
//迭代器
Iterator<Size> iter1 = sizeList.iterator();
boolean flag1=true;
while(iter1.hasNext()){
Size size = iter1.next();
for(int i=0;i<product_Size.length;i++){
if(size.getId()==Integer.valueOf(product_Size[i])){
flag1=false;
}
}
if(flag1){
iter1.remove();
}
}*/
//推荐商品
int count=productService.selectCountFromProduct();//商品表总记录数
Random random=new Random();//随机数
List<Product>hotProductList=new ArrayList<Product>();
for(int i=0;i<3;i++){
int rid=1+random.nextInt(count);//产生3个随机ID
Product hotProduct=productService.recommendOneProduct(rid);//随机推荐3个商品
hotProductList.add(hotProduct);//添加到List中
}
/*model.addAttribute("colorList", colorList);//商品颜色
model.addAttribute("sizeList", sizeList);//商品尺寸*/
model.addAttribute("productOne", product);//单个商品
model.addAttribute("hotProductList", hotProductList);//推荐商品
return "product";
}
//显示商品库存
@RequestMapping(value="/shouProductNum")
public String shouProductNmu(@RequestBody Num num,HttpServletResponse response) throws IOException{
if(num!=null){
Integer product_num=productService.selectProductNum(num);
response.getWriter().print(product_num);
}
return null;
}
//用户添加商品到购物车
@RequestMapping(value="/addProductToCart")
public ModelAndView addCart(@RequestBody Cart cart,
HttpServletResponse response) throws IOException{
response.setContentType("text/html;charset=UTF-8");
if(cart!=null){
//判断是否选择了颜色和尺寸
if(cart.getProduct_color()=="" || cart.getProduct_size()=="" ){
response.getWriter().print("error");//未选择颜色或尺寸
}
else{
//判断该商品是否已经购买过
List<Cart> RcartList=cartService.selectOneCart(cart.getProduct_id(),cart.getUser_id());//查询购物车中是否已经存在当前购买商品
int flag = 0;
boolean mark = false;
//如果已经购买过,则另需判断商品颜色和尺寸是否一致
if(RcartList!=null){
//迭代器
Iterator<Cart> iter = RcartList.iterator();
while(iter.hasNext()){
Cart Rcart=iter.next();
//一致则更新商品数量
if(Rcart.getProduct_color().equals(cart.getProduct_color()) && Rcart.getProduct_size().equals(cart.getProduct_size())){
mark=true;//如果存在则为真
Integer product_number=Rcart.getProduct_number();//查询原商品数量
product_number+=cart.getProduct_number();//更新后商品数量
flag=cartService.updateProductNumberToCart(product_number,Rcart.getId());
}
}
//如果不存在则为假
if(mark==false){
Product product=productService.recommendOneProduct(cart.getProduct_id());//查询商品信息
cart.setProduct_image(product.getImage());//设置商品图片路径
cart.setProduct_price(product.getPrice());//设置商品价格
cart.setProduct_title(product.getTitle());//设置商品名称
flag=productService.addToCart(cart);
}
}
else{
//没有购买过,则添加到购物车中,生成新的记录
Product product=productService.recommendOneProduct(cart.getProduct_id());//查询商品信息
cart.setProduct_image(product.getImage());//设置商品图片路径
cart.setProduct_price(product.getPrice());//设置商品价格
cart.setProduct_title(product.getTitle());//设置商品名称
flag=productService.addToCart(cart);
}
//判断是否添加成功
if(flag>0){
response.getWriter().print("success");//商品添加成功
}
else{
response.getWriter().print("fail");//商品添加失败
}
}
}
else{
response.getWriter().print("fail");//购物车为空,添加失败
}
//无论成功失败都返回前台页面
return null;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
2018毕业设计,ssm版.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共402个文件
jpg:243个
java:41个
png:29个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 5 0 下载量 100 浏览量
2024-04-22
17:08:39
上传
评论
收藏 70.04MB ZIP 举报
温馨提示
2018毕业设计,ssm版
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
共 402 条
- 1
- 2
- 3
- 4
- 5
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/d7864c98224046ec9a7f43fa6207c84e_qq_51320133.jpg!1)
生瓜蛋子
- 粉丝: 3830
- 资源: 6140
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 小程序版图像分类算法对马路是否有坑洼识别-不含数据集图片-含逐行注释和说明文档.zip
- Multisim14.0带555芯片的计数器仿真
- 小程序版基于卷积神经网络识别是否是大黄蜂-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版基于深度学习对芒果成熟度识别-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版基于深度学习识别是否是水果图片-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版通过CNN卷积神经网络的水稻是否伏倒识别-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版图像分类算法对橘子成熟度识别-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版python训练识别草莓成熟度-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版基于卷积神经网络识别牙齿是否健康-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版python语言pytorch框架训练识别巧克力颜色-不含数据集图片-含逐行注释和说明文档.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)