后台shop++购物车请求的数据是一个Map结构的数据,业务需要要在类似的购物车中加一个套餐。

那么套餐里面就包含商品信息了,觉得不用他的Map了于是封装了两个类:

套餐信息显示类,商品信息显示类

请求返回数据都正常,但是js就是解析不了后台返回来的数据。也不报错。
主要原因是SetMealView 类的setMeal原来是一个SetMeal对象,后来改成了String就可以了。
/**
* @Auther: lanhaifeng
* @Date: 2018/12/3 0003 09:10
* @Description:套餐信息显示类
*/
public class SetMealView { private String setMeal;//套餐名称 private List<ProductDateilView> viewList=new ArrayList<ProductDateilView>();//套餐商品信息 public SetMealView() {
} public SetMealView(String setMeal, List<ProductDateilView> viewList) {
this.setMeal = setMeal;
this.viewList = viewList;
} public String getSetMeal() {
return setMeal;
} public void setSetMeal(String setMeal) {
this.setMeal = setMeal;
} public List<ProductDateilView> getViewList() {
return viewList;
} public void setViewList(List<ProductDateilView> viewList) {
this.viewList = viewList;
}
}
/**
* @Auther: lanhaifeng
* @Date: 2018/12/3 0003 08:58
* @Description:商品信息显示类,不想搞那么多Map
* 所以封装一下
*/
public class ProductDateilView {
private long skuId;//商品详细编号
private String skuName;//商品详细名称
private String skuPath;//连接地址
private int stock;//库存数量
private String specificationValues;////型号
private String brand;//品牌名称
private long productCategory_id;//商品类别编号
private String skuThumbnail;//商品图标
private BigDecimal price;//价格
private int quantity;//数量
private BigDecimal subtotal;//价格小计 public long getSkuId() {
return skuId;
} public void setSkuId(long skuId) {
this.skuId = skuId;
} public String getSkuName() {
return skuName;
} public void setSkuName(String skuName) {
this.skuName = skuName;
} public String getSkuPath() {
return skuPath;
} public void setSkuPath(String skuPath) {
this.skuPath = skuPath;
} public int getStock() {
return stock;
} public void setStock(int stock) {
this.stock = stock;
} public String getSpecificationValues() {
return specificationValues;
} public void setSpecificationValues(String specificationValues) {
this.specificationValues = specificationValues;
} public String getBrand() {
return brand;
} public void setBrand(String brand) {
this.brand = brand;
} public long getProductCategory_id() {
return productCategory_id;
} public void setProductCategory_id(long productCategory_id) {
this.productCategory_id = productCategory_id;
} public String getSkuThumbnail() {
return skuThumbnail;
} public void setSkuThumbnail(String skuThumbnail) {
this.skuThumbnail = skuThumbnail;
} public BigDecimal getPrice() {
return price;
} public void setPrice(BigDecimal price) {
this.price = price;
} public int getQuantity() {
return quantity;
} public void setQuantity(int quantity) {
this.quantity = quantity;
} public BigDecimal getSubtotal() {
return subtotal;
} public void setSubtotal(BigDecimal subtotal) {
this.subtotal = subtotal;
}
} 那么请求数据的时候在原来获取购物车的基础上进行了改造。
/**
* 查询详细的购物清单
* @param currentCart
* @return
*/
public Map<String, Object> getSkuDetail( @CurrentCart Cart currentCart){
Map<String, Object> data = new HashMap<>();
//查询购物车所有数据信息
Setting setting = SystemUtils.getSetting();
if (currentCart != null && !currentCart.isEmpty()) {
data.put("quantity", currentCart.getQuantity(false));
data.put("rewardPoint", currentCart.getRewardPoint());
data.put("effectivePrice", currentCart.getEffectivePrice());
data.put("discount", currentCart.getDiscount());
//List<Map<String, Object>> cartItems = new ArrayList<>();//存套餐外的商品
List<ProductDateilView> cartItems = new ArrayList<>();//存套餐外的商品
List<SetMealView> setmealist = new ArrayList<>();//setmealist保存套餐内的商品
//这里做一个小小的改动,要对套餐进行一个分组
for (CartItem cartItem : currentCart) {
ProductDateilView productDateilView=new ProductDateilView();
//Map<String, Object> item = new HashMap<>();
Sku sku = cartItem.getSku();
Product product=sku.getProduct();
//item.put("skuId", sku.getId());
productDateilView.setSkuId(sku.getId());
//item.put("skuName", sku.getName());
productDateilView.setSkuName(sku.getName());
//item.put("skuPath", sku.getPath());
productDateilView.setSkuPath(sku.getPath());
//item.put("stock",sku.getStock());//库存
productDateilView.setStock(sku.getStock());
//item.put("specificationValues",sku.getSpecificationValues().get(0).getValue());//型号
productDateilView.setSpecificationValues(sku.getSpecificationValues().get(0).getValue());
if(null!=product.getBrand()){
String brand=(product.getBrand().getName()!=null ||product.getBrand().getName().equals(""))?product.getBrand().getName():"自营";
//item.put("brand",brand);//品牌
productDateilView.setBrand(brand);
}else {
//item.put("brand","自营");//品牌
productDateilView.setBrand("自营");
}
//item.put("productCategory_id",product.getProductCategory().getId());//产品类别
productDateilView.setProductCategory_id(product.getProductCategory().getId());
//item.put("skuThumbnail", sku.getThumbnail() != null ? sku.getThumbnail() : setting.getDefaultThumbnailProductImage());
productDateilView.setSkuThumbnail(sku.getThumbnail() != null ? sku.getThumbnail() : setting.getDefaultThumbnailProductImage());
//item.put("price", cartItem.getPrice());
productDateilView.setPrice(cartItem.getPrice());
//item.put("quantity", cartItem.getQuantity());
productDateilView.setQuantity(cartItem.getQuantity());
//item.put("subtotal", cartItem.getSubtotal());
productDateilView.setSubtotal(cartItem.getSubtotal());
if(cartItem.getSetmeal_id()>0){ //判断如果是套餐
//cartItems.add(item);
SetMeal setMeal=setMealService.find(cartItem.getSetmeal_id());
//item.put("setMeal", setMeal);
boolean isExits=false;
for (SetMealView se: setmealist) {
if(se.getSetMeal().equals(setMeal.getsName())){
se.getViewList().add(productDateilView);
isExits=true;
break;
}
}
if(isExits==false){
List<ProductDateilView> list=new ArrayList<>();
list.add(productDateilView);
setmealist.add(new SetMealView(setMeal.getsName(),list));
}
}else {
cartItems.add(productDateilView);
}
}
data.put("cartItems", cartItems);
data.put("setmealist", setmealist);
}
return data;
}

shop++改造之ResponseEntity的坑的更多相关文章

  1. shop++改造之Filter类

    基于shop++源码进行商城改造.本来想大展手脚,结果一入手.发觉瞬间淹没了我的才华,sql语句也得贼溜没啥用. 不得不说这个商城源码价值很高,封装的很精屁. 下面是我第一天入手的坑. 数据库建好了表 ...

  2. springMvc改造springboot2.0踩坑

    1. 支持jsp applicaiton.proerties添加配置 #指定视图解析路径前缀 spring.mvc.view.prefix=/WEB-INF/jsp/ #指定视图解析后缀 spring ...

  3. DotNetOpenAuth 服务端搭建

    新建项目: 安装DotNetOpenAuth: 新增OAuthController: 代码如下: public class OAuthController : Controller { private ...

  4. Kubernetes集群

    Kubernetes已经成为当下最火热的一门技术,未来一定也会有更好的发展,围绕着云原生的周边产物也越来越多,使得上云更加便利更加有意义,本文主要讲解一些蔚来汽车从传统应用落地到Kubernetes集 ...

  5. SpringCloud学习之大纲总略(大纲篇)

    微服务架构的概念,现在对于大家应该都不陌生,无论使用 Apache Dubbo.还是 Spring Cloud,都可以去尝试微服务,把复杂而庞大的业务系统拆分成一些更小粒度且独立部署的 Rest 服务 ...

  6. 分布式改造剧集之Redis缓存采坑记

    Redis缓存采坑记 ​ 前言 ​ 这个其实应该属于分布式改造剧集中的一集(第一集见前面博客:http://www.cnblogs.com/Kidezyq/p/8748961.html),本来按照顺序 ...

  7. 海豚调度5月Meetup:6个月重构大数据平台,帮你避开调度升级改造/集群迁移踩过的坑

    当今许多企业都有着技术架构的DataOps程度不够.二次开发成本高.迁移成本高.集群部署混乱等情况,团队在技术选型之后发现并不适合自己的需求,但是迁移成本和难度又比较大,甚至前团队还留下了不少坑,企业 ...

  8. H5嵌入原生开发小结----兼容安卓与ios的填坑之路

    一开始听说开发H5,以为就是做适配现代浏览器的移动网页,心想不用管IE了,欧也.到今天,发现当初too young too simple,兼容IE和兼容安卓与IOS,后者让你更抓狂.接下来数一下踩过的 ...

  9. ReactJS webpack实现JS模块化使用的坑

    从一个原生HTML/CSS/JS模式的网页改造到ReactJS模块化的结构,需要以下步骤: (1)引用ReactJS框架 ->(2)使用webpack 工具 -> (3)配置webpack ...

随机推荐

  1. ☆ [HDU2157] How many ways?? 「矩阵乘法求路径方案数」

    传送门:>Here< 题意:给出一张有向图,问从点A到点B恰好经过k个点(包括终点)的路径方案数 解题思路 一道矩阵乘法的好题!妙哉~ 话说把矩阵乘法放在图上好神奇,那么跟矩阵唯一有关的就 ...

  2. [HDU5536] Chip Factory

    传送门:>Here< 题意:给出一个长度为N的序列,求$Max\{ (a_i + a_j) ⊕ a_k \}$ (i,j,k均不相同)  ($N \leq 1000$) 解题思路 既然$O ...

  3. Codeforces734 E. Anton and Tree

    传送门:>Here< 题意:给出一颗树,节点不是黑色就是白色,每次可以将一个颜色相同的块变颜色,问最少变几次才能让其变为同色 解题思路: 我们考虑由于每一次都是把同样颜色的色块进行变色,因 ...

  4. 【XSY2691】中关村 卢卡斯定理 数位DP

    题目描述 在一个\(k\)维空间中,每个整点被黑白染色.对于一个坐标为\((x_1,x_2,\ldots,x_k)\)的点,他的颜色我们通过如下方式计算: 如果存在一维坐标是\(0\),则颜色是黑色. ...

  5. 爬虫_中国天气网_文字天气预报(xpath)

    import requests from lxml import etree headers = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/5 ...

  6. Codeforces 346D Robot Control(01BFS)

    题意 有一个 \(N\) 个点, \(M\) 条边的有向图, 初始有一个机器人在 \(1\) 号点. 每个时刻, 这个机器人会随机选择一条从该点出发地边并通过.当机器人到达点 \(N\) 时, 它就会 ...

  7. Linux下启动,停止,重启Nginx、Mysql、PHP

    LINUX启动Nginx的命令: 一.查询是否启动 [root@jiang php-fpm.d]# ps -ef | grep nginx root 25225 1 0 19:26 ? 00:00:0 ...

  8. GNOME 3.28 启用桌面图标

    原由 GNOME 3.28合并了移除桌面图标支持 Nautilus从此不在支持桌面图标,直到找到新的解决方案 Issues地址:https://gitlab.gnome.org/GNOME/nauti ...

  9. A1034. Head of a Gang

    One way that the police finds the head of a gang is to check people's phone calls. If there is a pho ...

  10. jenkins系列之添加全局配置(一)

    第一步: 第二步:执行以下命令: 第三步:找到/c/Users/Administrator/.ssh 目录,里面有两个文件:id_rsa和id_rsa.pub 第四步:配置ssh[这里是id_rsa. ...