通过SpingMVC绑定Ajax传递的JSON

表单和文件混合:
字段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)