码迷,mamicode.com
首页 > Web开发 > 详细

ajax json提交到控制层

时间:2015-09-23 18:34:51      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

js:

var useData = [];
$.ajax({
url: "/dealer/dealerShoper/synShopers",
method: "post",
data: JSON.stringify(useData),
contentType: ‘application/json‘,
dataType: "json",
success: function(data){
console.log(data);
callback && callback();
__d.hide();
}
})

controller:
 @ResponseBody
@RequestMapping("/synShopers")
public JsonMessage synShopersForClear(@RequestBody List<JSONObject> jsonList) throws BusinessException {
UserPrincipal userPrincipal = OnLineUserUtils.getPrincipal();

if(null != jsonList && null != userPrincipal && userPrincipal.getUserType().equals(DealerConstant.userType.DEALER_TYPE))
{
List<Map<String,Object>> dealerShoperList = Lists.newArrayList();
for (JSONObject jsonObject : jsonList) {
ProductSku productSku = productSkuService.findProductSku((String)jsonObject.get("skuId"));
Map<String,Object> map = Maps.newHashMap();
map.put("skuId", (String) jsonObject.get("skuId"));
if(null != productSku)
{
Boolean isChange = false ;
short productType = (short)jsonObject.get("productType");
BigDecimal productSkuPrice = (BigDecimal)jsonObject.get("productSkuPrice");
Integer quantity = jsonObject.getInteger("quantity");
map.put("productSkuPrice",productSkuPrice);
map.put("quantity", productSku.getQuantity());
map.put("isValid", true);
if(productType == DealerConstant.DealerShoper.PRODUCTTYPE_CASH)
{
if(productSku.getProductSkuPrice().getDirectPrice().compareTo(productSkuPrice) != 0)
{
map.put("productSkuPrice",productSku.getProductSkuPrice().getDirectPrice());
isChange= true;
}
}
else if(productType == DealerConstant.DealerShoper.PRODUCTTYPE_CREDIT)
{
if(productSku.getProductSkuPrice().getCreditPrice().compareTo(productSkuPrice) != 0)
{
map.put("productSkuPrice",productSku.getProductSkuPrice().getCreditPrice());
isChange= true;
}
}
else if(productType == DealerConstant.DealerShoper.PRODUCTTYPE_SAM)
{
if(productSku.getProductSkuPrice().getSamplePrice().compareTo(productSkuPrice) != 0)
{
map.put("productSkuPrice",productSku.getProductSkuPrice().getSamplePrice());
isChange= true;
}
}
if(productSku.getQuantity()-quantity < 0)
{
map.put("quantity", productSku.getQuantity());
isChange = true;
}
if(isChange)
{
dealerShoperList.add(map);
}
}else{
map.put("isValid",false);
dealerShoperList.add(map);
}
}
return this.getJsonMessage(CommonConst.SUCCESS,dealerShoperList);
}
return this.getJsonMessage(CommonConst.FAIL);
}
com.alibaba.fastjson



ajax json提交到控制层

标签:

原文地址:http://www.cnblogs.com/yiyongyao/p/4832625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!