后端controller中有一个方法
public String addCampaign(@RequestBody CampaignVo campaignVo) {
JSONObject result = new JSONObject();
//业务处理
return result.toString();
}
vo对象内容:
private String campaignName; //普通类型
private UnionSkuRule unionSkuRule; //普通对象
private List<UnionCampaignImg> campaignImg; //集合对象
前端js写法:
var aaa= getParams();
if (aaa != null) {
$.ajax({
url: 'path......',
type: 'post',
dataType: 'json',
data: JSON.stringify(campaign),
contentType: 'application/json;charset=utf-8',
success: function (data) {
//回来了...
});
}
function getParams() {
var campaignName = $.trim($('#campaignName').val());
var pageType = $.trim($('#pageType option:selected').val());
var campaignSummary = $.trim($("#campaignSummary").val());
var startTime = $.trim($('#startTime').val());
var endTime = $.trim($('#endTime').val());
var bizProduct = $.trim($('#skuBizType').val());
//基础梯度:只有单品才设置梯度
var basicDivides = [];
if (pageType == 0 && parseInt(bizProduct) != 2002) {
basicDivides = getBasicSkuDivideds();
if (basicDivides == null) {
return null;
}
}
//最终包装
var campaignImg = findAllImgUrl(); //查到多个上传图片的地址 数组
var campaign = {
campaignName: campaignName,
campaignImg: campaignImg,
unionSkuRule: settingCpsSku()
};
return campaign;
}
function findAllImgUrl() {
var images = [];
var tab = document.getElementById("cps_picture_list");
for (var i = 0; i < tab.rows.length; i++) {
var name = tab.rows[i].cells[0].innerText;
var url = tab.rows[i].cells[1].innerText;
var reg = /(https|http):/g;
url = url.replace(/(^\s*)|(\s*$)/g, "");
if (url != 'undefined' && url != "") {
url = url.replace(reg, '');
}
var sizeStr = tab.rows[i].cells[2].innerText;
var sizes = sizeStr.split('*');
var img = {
name: name,
img: url,
width: sizes[0],
height: sizes[1]
}
images.push(img);
}
return images;
}
//对象设置
function settingCpsSku() {
var sku = $.trim($('#sku').val());
var skuBizType = $.trim($("#skuBizType option:selected").val());
var skuBizProduct = $.trim($("#skuBizProduct option:selected").val());
var cmsType = $.trim($('#cmsType option:selected').val());
var projectType = $.trim($('#skuProjectType option:selected').val());
if("null" == projectType){
projectType = null;
}
var skuRule = {
sku: sku,
bizType: skuBizType,
bizProduct: skuBizProduct,
cmsType: cmsType,
projectType: projectType
};
return skuRule;
}
网友评论