Controller中的代码如下:
@RequestMapping(value="/delete",method=RequestMethod.POST,produces="application/json")
@ResponseStatus(HttpStatus.OK)}
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")+""));
}