如何使用ajax将json对象数组发送到spring控制器

时间:2018-01-05 05:56:57

标签: json ajax spring-mvc

我已使用以下代码将所有表格转换为json格式:

var table2 = $('#yTable').tableToJSON();          
alert(JSON.stringify(table2));

如何将这三个json数组发送到弹簧控制器?在spring控制器中,我想将这些json对象数组作为单独的参数:

    [
    {"Label":"A","Dimension":"0"},
    {"Label":"B","Dimension":"10"},
    {"Label":"C","Dimension":"20"},
    {"Label":"D","Dimension":"30"},
    {"Label":"E","Dimension":"40"}
    ]

    [
    {"Label":"1","Dimension":"0"},
    {"Label":"2","Dimension":"10"},
    {"Label":"3","Dimension":"20"},
    {"Label":"4","Dimension":"30"},
    {"Label":"5","Dimension":"40"}]



    [
    {"Label":"Floor1","Dimension":"0"},
    {"Label":"Floor2","Dimension":"10"},
    {"Label":"Floor3","Dimension":"20"},
    {"Label":"Floor4","Dimension":"30"},
    {"Label":"Floor5","Dimension":"40"}
    ]

ajax电话

 $.ajax({
             type: "POST",
              contentType : 'application/json; charset=utf-8',
              dataType : 'json',
              url: "/bimspring/gridData",
              data: JSON.stringify(postData),
            success : function(response) {
               // do something ... 
            },
            error : function(e) {
               alert('Error: ' + e);
            }
        });  

控制器

@RequestMapping(value = "/gridData", method = RequestMethod.POST)   
    public  @ResponseBody String  getSearchUserProfiles(@RequestBody Search[] list) {   
        return null;
       }

0 个答案:

没有答案