我有發送和接收JSON對象(jQuery的阿賈克斯)郵政陣列到Spring MVC控制器
Java對象
public class UserSkill() {
private long user;
private long skill;
private long level;
//getter and setter methods
}
的列表從控制器我得到的對象和它的清單問題看起來是這樣的
$.getJSON("getList", function(data) {
console.log(data);
});
//console log -> [Object { user=4, skill=61, leve=10}, Object { user=3, skill=61, level=20}]
我改變了一些價值觀和我們下面的代碼
ioarray = [];
//update methods
console.log(ioarray);
//console log -> [Object { user=4, skill=61, level=9000 }, Object { user=3, skill=61, level=100 }]
阿賈克斯POST
$.ajax({
url : 'goUpdate',
type : 'POST',
contentType : 'application/json; charset=utf-8',
dataType : 'json',
data: ioarray,
succcess : function(e) {
alert('Yeah');
}
控制器
@RequestMapping(value = "goUpdate", method = RequestMethod.POST)
public Object goUpdatePOST(@RequestBody List<UserSkill> list) {
//list.get(0).getLevel();
return list;
}
日誌
type Status report
message Request method 'POST' not supported
description The specified HTTP method is not allowed for the requested resource.
了什麼在這裏...任何想法?
UPDATE;
的Controler
@RequestMapping(value = "goUpdate", method = RequestMethod.POST)
public @ResponseBody String goUpdatePOST(@RequestBody UserSkill[] list) {
for(UserSkill i : list) {
System.out.println(i.getSkill());
}
return "somepage";
}
jQuery的
var ioarray = [{ user:4, skill:61, level:10},
{ user:3, skill:61, level:20}];
$.ajax({
url : 'goUpdate',
type : 'POST',
data: JSON.stringify(ioarray),
});
控制檯輸出
JSON
0
Object { user=4, skill=61, level=10}
1
Object { user=3, skill=61, level=20}
Source
[{"user":4,"skill":61,"level":10},{"user":3,"skill":61,"level":20}]
到pom.xml中插入傑克遜映射器-ASL和Jackson核-ASL。
當然這個例子會產生同樣的錯誤......我做錯了什麼?我想我檢查了一切可能性。
嘗試刪除'數據類型:「json'' – 2014-08-28 11:10:01
沒有... POST來源:不確定=不確定= – user2363971 2014-08-28 11:23:21
嘗試刪除'@ RequestBody'然後,有一些問題與發佈的數據及其類型。 – 2014-08-28 11:25:51