美文网首页
通过SpingMVC绑定Ajax传递的JSON

通过SpingMVC绑定Ajax传递的JSON

作者: Cheava | 来源:发表于2018-04-18 17:32 被阅读13次

    表单和文件混合:
    字段name=adviseInfo.firstType

                var form = new FormData($("#importModel")[0]);
                var settings = {
                    "url": "/advise",
                    "method": "POST",
                    "headers": {
                        "accept": "application/json",
                        "cache-control": "no-cache",
                    },
                    "processData": false,
                    "contentType": false,
                    "mimeType":"multipart/form-data",
                    "data": form
                }
    
                $.ajax(settings).done(function (response){
                    alert("提交成功");
                    console.log(response);
                }).fail(function(){
                    alert("提交失败");
                })
            }
            
    
        public ServerResponse createAdvise(AdviseExcel adviseExcel, @RequestParam("file") MultipartFile attachment) {
    

    单纯表单
    字段name=distributor[company]

      var form = JSON.stringify($('#importModel').serializeJSON());
                console.log(form);
                var settings = {
                    "url": "/prjRecode",
                    "method": "POST",
                    "dataType":"json",
                    "headers": {
                        "content-type": "application/json",
                        "accept": "application/json",
                        "cache-control": "no-cache"
                    },
                    "processData": false,
                    "contentType": false,
                    "data": form
                };
    
        public ServerResponse createPrjRecode(@RequestBody PrjRecodeExcel prjRecodeExcel) {
        ```

    相关文章

      网友评论

          本文标题:通过SpingMVC绑定Ajax传递的JSON

          本文链接:https://www.haomeiwen.com/subject/qbcbkftx.html