java后台,在springMVC中有
@RequestMapping(value = "/requestbody", method = RequestMethod.POST)
@ResponeBody
public String saveGroup(@RequestBody Group group) throws DaoAccessException
{
system.out.print(group.toString());
return null;
}
public class Group {
private Integer id;
private String name;
//set..., get...
}
//参数很多,这里不多加说明,自行查看$.ajax相关API (需要的js-jquery, json2)
前端的js请求模式(jquery)
$.ajax(
{
type : 'post',
url : '/requestbody',
dataType : 'json',
data : JSON.stringify({id:1, name:'test'}), //需要将当前的对象转换为json字符串,
contentType : 'application/json',
success : function(result){console.debug(result);} // null
error : function(XMLHttpRequest, textStatus, errorThrown){}
}
);