我有发送和接收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