shop++改造之ResponseEntity的坑
后台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的坑的更多相关文章
- shop++改造之Filter类
基于shop++源码进行商城改造.本来想大展手脚,结果一入手.发觉瞬间淹没了我的才华,sql语句也得贼溜没啥用. 不得不说这个商城源码价值很高,封装的很精屁. 下面是我第一天入手的坑. 数据库建好了表 ...
- springMvc改造springboot2.0踩坑
1. 支持jsp applicaiton.proerties添加配置 #指定视图解析路径前缀 spring.mvc.view.prefix=/WEB-INF/jsp/ #指定视图解析后缀 spring ...
- DotNetOpenAuth 服务端搭建
新建项目: 安装DotNetOpenAuth: 新增OAuthController: 代码如下: public class OAuthController : Controller { private ...
- Kubernetes集群
Kubernetes已经成为当下最火热的一门技术,未来一定也会有更好的发展,围绕着云原生的周边产物也越来越多,使得上云更加便利更加有意义,本文主要讲解一些蔚来汽车从传统应用落地到Kubernetes集 ...
- SpringCloud学习之大纲总略(大纲篇)
微服务架构的概念,现在对于大家应该都不陌生,无论使用 Apache Dubbo.还是 Spring Cloud,都可以去尝试微服务,把复杂而庞大的业务系统拆分成一些更小粒度且独立部署的 Rest 服务 ...
- 分布式改造剧集之Redis缓存采坑记
Redis缓存采坑记 前言 这个其实应该属于分布式改造剧集中的一集(第一集见前面博客:http://www.cnblogs.com/Kidezyq/p/8748961.html),本来按照顺序 ...
- 海豚调度5月Meetup:6个月重构大数据平台,帮你避开调度升级改造/集群迁移踩过的坑
当今许多企业都有着技术架构的DataOps程度不够.二次开发成本高.迁移成本高.集群部署混乱等情况,团队在技术选型之后发现并不适合自己的需求,但是迁移成本和难度又比较大,甚至前团队还留下了不少坑,企业 ...
- H5嵌入原生开发小结----兼容安卓与ios的填坑之路
一开始听说开发H5,以为就是做适配现代浏览器的移动网页,心想不用管IE了,欧也.到今天,发现当初too young too simple,兼容IE和兼容安卓与IOS,后者让你更抓狂.接下来数一下踩过的 ...
- ReactJS webpack实现JS模块化使用的坑
从一个原生HTML/CSS/JS模式的网页改造到ReactJS模块化的结构,需要以下步骤: (1)引用ReactJS框架 ->(2)使用webpack 工具 -> (3)配置webpack ...
随机推荐
- HDU4035 Maze 【树形DP】【期望DP】
题目分析: 以前一直不会这个方法, 我好菜啊. 转移分为三个部分,一个是直接成功,一个是转移到E1,还有一个是转移到自己周围的一圈儿点. 如果是叶子那么只能转移到父亲,如果不是叶子可以把非叶子的转移代 ...
- BZOJ 1912 巡逻(算竞进阶习题)
树的直径 这题如果k=1很简单,就是在树的最长链上加个环,这样就最大化的减少重复的路程 但是k=2的时候需要考虑两个环的重叠部分,如果没有重叠部分,则和k=1的情况是一样的,但是假如有重叠部分,我们可 ...
- HBase电子书
HBase 不睡觉书 https://pan.baidu.com/s/1d4u7pPAu_B3sW5w9x1ARdA HBase2018年年度总结 https://pan.baidu.com/s/1 ...
- 【XSY2727】Remove Dilworth定理 堆 树状数组 DP
题目描述 一个二维平面上有\(n\)个梯形,满足: 所有梯形的下底边在直线\(y=0\)上. 所有梯形的上底边在直线\(y=1\)上. 没有两个点的坐标相同. 你一次可以选择任意多个梯形,必须满足这些 ...
- Django media 配置
Django media 配置 settings.py 配置 配置 media 的路径, 以及连接到主路径 还要添加一个 上下文管理 TEMPLATES = [ { 'BACKEND': 'dja ...
- Min_25
可以用来筛出一个积性函数的前缀和.这个积性函数要满足当\(x\)是质数时,\(f(x)\)可以快速求出,\(f(x^k)\)也可以快速算出. 首先我们要处理出一个\(g(x)=\sum_{x\in p ...
- LVM-COW写实备份
[root@localhost ~]# fdisk -l /dev/sdb /dev/sdc | grep "LVM"/dev/sdb1 1 9660 77593918+ 8e L ...
- cf1076E Vasya and a Tree (线段树)
我的做法: 给询问按$deep[v]+d$排序,每次做到某一深度的时候,先给这个深度所有点的值清0,然后直接改v的子树 官方做法比较妙妙: dfs,进入v的时候给$[deep[v],deep[v]+d ...
- DNA Evolution CodeForces - 828E(树状数组)
题中有两种操作,第一种把某个位置的字母修改,第二种操作查询与[L, R]内与给出字符串循环起来以后对应位置的字母相同的个数.给出的字符串最大长度是10. 用一个四维树状数组表示 cnt[ATCG的编号 ...
- CF1139D Steps to One(DP,莫比乌斯反演,质因数分解)
stm这是div2的D题……我要对不住我这个紫名了…… 题目链接:CF原网 洛谷 题目大意:有个一开始为空的序列.每次操作会往序列最后加一个 $1$ 到 $m$ 的随机整数.当整个序列的 $\gcd ...