后台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. LOJ2251 [ZJOI2017] 树状数组【线段树】【树套树】

    题目分析: 对于一个$add$操作,它的特点是与树状数组的查询相同,会给$1$到它自己产生影响,而$query$操作则会途径所有包含它的树状数组点.现在$add$操作具有前向性(不会影响之后的点).所 ...

  2. BZOJ 2049 洞穴勘测

    LCT判断联通性 没什么特别的..还是一个普通的板子题,把LCT当并查集用了,只不过LCT灵活一些,还可以断边 话说自从昨天被维修数列那题榨干之后我现在写splay都不用动脑子了,,机械式的码spla ...

  3. 【刷题】LOJ 556 「Antileaf's Round」咱们去烧菜吧

    题目描述 你有 \(m\) 种物品,第 \(i\) 种物品的大小为 \(a_i\) ​,数量为 \(b_i\)​( \(b_i=0\) 表示有无限个). 你还有 \(n\) 个背包,体积分别为 \(1 ...

  4. k短路模板(洛谷P2483 [SDOI2010]魔法猪学院)(k短路,最短路,左偏树,priority_queue)

    你谷数据够强了,以前的A*应该差不多死掉了. 所以,小伙伴们快来一起把YL顶上去把!戳这里! 俞鼎力的课件 需要掌握的内容: Dijkstra构建最短路径树. 可持久化堆(使用左偏树,因其有二叉树结构 ...

  5. The Python Challenge 谜题全解(持续更新)

    Python Challenge(0-2) The Python Challengehttp://www.pythonchallenge.com/ 是个很有意思的网站,可以磨练使用python的技巧, ...

  6. Android undefined intent constructor错误?

    本文选自StackOverflow(简称:SOF)精选问答汇总系列文章之一,本系列文章将为读者分享国外最优质的精彩问与答,供读者学习和了解国外最新技术.在Android中启动Service时出现&qu ...

  7. cf1076E Vasya and a Tree (线段树)

    我的做法: 给询问按$deep[v]+d$排序,每次做到某一深度的时候,先给这个深度所有点的值清0,然后直接改v的子树 官方做法比较妙妙: dfs,进入v的时候给$[deep[v],deep[v]+d ...

  8. 牛客练习赛43 Tachibana Kanade Loves Probability(快速幂)

    链接:https://ac.nowcoder.com/acm/contest/548/B来源:牛客网 题目描述 立华奏在学习初中数学的时候遇到了这样一道大水题: “设箱子内有 n 个球,其中给 m 个 ...

  9. Java 破解谷歌翻译api,可以实现程序自动化翻译文章

    1  原理:查看谷歌翻译网站,输入需要翻译的文字,选择语言得到翻译后的文字,发送异步请求参数返回结果.java使用httpclient发送请求,实现使用代码翻译文章的功能. 2  下载代码后,测试入口 ...

  10. nc 使用实例

    nc.exe -h即可看到各参数的使用方法.基本格式:nc [-options] hostname port[s] [ports] ...nc -l -p port [options] [hostna ...