后台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. LOJ2269 [SDOI2017] 切树游戏 【FWT】【动态DP】【树链剖分】【线段树】

    题目分析: 好题.本来是一道好的非套路题,但是不凑巧的是当年有一位国家集训队员正好介绍了这个算法. 首先考虑静态的情况.这个的DP方程非常容易写出来. 接着可以注意到对于异或结果的计数可以看成一个FW ...

  2. neutron相关知识

    Neutron 对虚拟三层网络的实现是通过其 L3 Agent (neutron-l3-agent).该 Agent 利用 Linux IP 栈.route 和 iptables 来实现内网内不同网络 ...

  3. 每天一个Linux命令(05):tail命令

    tail命令用于输入文件中的尾部内容.tail命令默认在屏幕上显示指定文件的末尾10行.如果给定的文件不止一个,则在显示的每个文件前面加一个文件名标题.如果没有指定文件或者文件名为"-&qu ...

  4. bandwagon host

    104.20.6.63 bandwagonhost.com 104.20.6.63 bwh1.net

  5. FZU 2150 Fire Game (bfs+dfs)

    Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board ...

  6. 20165223 week4测试补交与总结

    JDB调试程序 调试代码 public class SumofRecur1{ public static void main(String[] args) { int i = 0; for(Strin ...

  7. Git错误汇总

    Git提示rejected To github.com:zhuxiaoxi/Web-Demo.git ! [rejected] master -> master (fetch first) er ...

  8. [luogu4860][Roy&October之取石子II]

    题目链接 思路 这个题和上个题类似,仔细推一下就知道这个题是判断是否是4的倍数 代码 #include<cstdio> #include<iostream> #define f ...

  9. c 结构体 & 函数指针模拟实现一个java class(类) 和方法

    闲来无事,纯粹练习. student.h #ifndef STUDENT_H_INCLUDED #define STUDENT_H_INCLUDED #include <memory.h> ...

  10. C++11并发——多线程条件变量std::condition_variable(四)

    https://www.jianshu.com/p/a31d4fb5594f https://blog.csdn.net/y396397735/article/details/81272752 htt ...