Could not read JSON: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

Controller中的代码如下:

       @RequestMapping(value="/delete",method=RequestMethod.POST,produces="application/json")

@ResponseStatus(HttpStatus.OK)
public void delete(@RequestBody Integer id){
this.moduleService.deleteModule(id);

}

ajax请求:

//删除
$(".delete_line").live('click',function(){
//url:'/uc/module/delete/',
var del=$(this);
var id=$(this).attr('alt');
if(confirm('确定要删除吗?')){
var params = { id : id};
var str =Ab.encode(params);
alert(str);
$.ajax({
type: "post",
data: str,
dataType:"json",
//url:G_URL['module/create'],
url: G_ROOT+'/module/delete',
contentType:'application/json;charset=UTF-8',
success:function(data){
getTree('right');
}
});
}
return false;
});

Spring 会将{id:id}这个json转换成Map对象,只要将@requestBody中的参数改成Map就可以了,如下

@RequestMapping(value="/delete",method=RequestMethod.POST,produces="application/json")
@ResponseStatus(HttpStatus.OK)
public void delete(@RequestBody Map map){
this.moduleService.deleteModule(Integer.parseInt(map.get("id")+""));
}

你可能感兴趣的:(spring,json,function,object,Integer,delete)