전단 js 패키지 집합 대상을springmvc로 전송

3446 단어

백엔드 컨트롤러에 방법이 있어요.

  public String addCampaign(@RequestBody CampaignVo campaignVo) {
        JSONObject result = new JSONObject();
        // 
        return result.toString();
    }
vo :
    private String campaignName;                               // 
    private UnionSkuRule unionSkuRule;                    // 
    private List 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;
}

좋은 웹페이지 즐겨찾기