鍍金池/ 問答/Java/ java controller層怎么接二維數(shù)組

java controller層怎么接二維數(shù)組

后端接口:

@PostMapping("/compose/{id}")
    public Message compose(@PathVariable String id, @RequestBody List<List<String>> data) {
    }

前端傳的數(shù)據(jù)如下:

[
    [null,"2016-12-31","2016-12-31","2016-12-31","2016-12-31","2016-12-31","2016-12-31"],
    ["","營業(yè)收入","營業(yè)成本","營業(yè)收入","營業(yè)成本","營業(yè)收入","營業(yè)成本"],
    ["華北","10,395.82","4.73","8,041.72","3.65","7,202.08","7,202.08"],
    ["華東","78,942.98","35.93","76,100.98","34.53","70,450.89","70,450.89"],
    ["華南","16,343.33","7.44","21,176.08","9.61","22,709.62","22,709.62"],
    ["華中","41,575.34","18.92","37,104.71","16.84","39,294.05","39,294.05"],
    ["西北","4,581.72","2.09","5,273.01","2.39","4,261.26","4,261.26"],
    ["西南","64,956.49","29.57","69,146.78","31.38","72,990.61","72,990.61"],
    ["境外","1,126.66","0.51","1,278.24","0.58","1,284.34","1,284.34"],
    ["合計","219,704.55","100.00","220,385.17","100","221,530.55","221,530.55"]
]

前端代碼如下,用的angular.js的$http:

// 其中data就是二維數(shù)組
$http.post(url, data).then(response => {});

報錯如下:

 [WARN] DefaultHandlerExceptionResolver Line:384 - Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

后端該怎么處理才能接到二維數(shù)組。

回答
編輯回答
莓森

圖片描述

我這邊正常的哇!可以直接用list得到啊

剛試了下,在html里面這么寫也是ok的.
$("#bbb").click(()=>{

let json = [
    [null,"2016-12-31","2016-12-31","2016-12-31","2016-12-31","2016-12-31","2016-12-31"],
    ["","營業(yè)收入","營業(yè)成本","營業(yè)收入","營業(yè)成本","營業(yè)收入","營業(yè)成本"],
    ["華北","10,395.82","4.73","8,041.72","3.65","7,202.08","7,202.08"],
    ["華東","78,942.98","35.93","76,100.98","34.53","70,450.89","70,450.89"],
    ["華南","16,343.33","7.44","21,176.08","9.61","22,709.62","22,709.62"],
    ["華中","41,575.34","18.92","37,104.71","16.84","39,294.05","39,294.05"],
    ["西北","4,581.72","2.09","5,273.01","2.39","4,261.26","4,261.26"],
    ["西南","64,956.49","29.57","69,146.78","31.38","72,990.61","72,990.61"],
    ["境外","1,126.66","0.51","1,278.24","0.58","1,284.34","1,284.34"],
    ["合計","219,704.55","100.00","220,385.17","100","221,530.55","221,530.55"]
]                  
$.ajax({  
    type : "POST",  
    url : 'http://localhost:10000/app/compose/bbbID',  
    data : JSON.stringify(json),  
    contentType : "application/json",   
    dataType : "json",  
    success:function(msg) {  
        console.log(msg)
    }  
});

})

2018年5月5日 15:04
編輯回答
挽歌

可以使用String類型的字符串,然后后臺導入arraryjson架包或者使用阿里的jsonfast架包,幫你切割字符串

2018年6月16日 03:23
編輯回答
呆萌傻

直接String data接收不到嗎?

2017年2月14日 15:43